144 { |
150 { |
145 return Application.GetInstance().Exec<BoxContainer>(() => new BoxContainer(parent, orientation)); |
151 return Application.GetInstance().Exec<BoxContainer>(() => new BoxContainer(parent, orientation)); |
146 } |
152 } |
147 } |
153 } |
148 |
154 |
149 public class GridContainer : Container |
155 public class GridContainer : Grid, Container |
150 { |
156 { |
151 public Layout Layout { get; set; } |
157 public Layout Layout { get; set; } |
152 |
158 |
153 public Grid Grid; |
159 private int X = 0; |
154 |
160 private int Y = 0; |
155 public GridContainer(System.Windows.Controls.Grid grid) |
161 private int CurrentWidth = 0; |
156 { |
162 private int CurrentHeight = 0; |
157 Grid = grid; |
163 |
|
164 public GridContainer(Container parent, int margin, int colspacing, int rowspacing) : base() |
|
165 { |
|
166 Layout = new Layout(); |
|
167 |
|
168 parent.Add(this, true); |
158 } |
169 } |
159 |
170 |
160 public void Add(UIElement control, bool fill) |
171 public void Add(UIElement control, bool fill) |
161 { |
172 { |
162 |
173 if(Layout.NewLine) |
|
174 { |
|
175 X = 0; |
|
176 Y++; |
|
177 } |
|
178 |
|
179 ColumnDefinition col; |
|
180 RowDefinition row; |
|
181 if(X >= CurrentWidth) |
|
182 { |
|
183 col = new ColumnDefinition(); |
|
184 col.Width = GridLength.Auto; |
|
185 ColumnDefinitions.Add(col); |
|
186 CurrentWidth = X + 1; |
|
187 } |
|
188 else |
|
189 { |
|
190 col = ColumnDefinitions.ElementAt(X); |
|
191 } |
|
192 |
|
193 if (Y >= CurrentHeight) |
|
194 { |
|
195 row = new RowDefinition(); |
|
196 row.Height = GridLength.Auto; |
|
197 RowDefinitions.Add(row); |
|
198 CurrentHeight = Y + 1; |
|
199 } |
|
200 else |
|
201 { |
|
202 row = RowDefinitions.ElementAt(Y); |
|
203 } |
|
204 |
|
205 if(Layout.Hexpand) |
|
206 { |
|
207 col.Width = new GridLength(1, GridUnitType.Star); |
|
208 } |
|
209 if(Layout.Vexpand) |
|
210 { |
|
211 row.Height = new GridLength(1, GridUnitType.Star); |
|
212 } |
|
213 |
|
214 Grid.SetColumn(control, X); |
|
215 Grid.SetRow(control, Y); |
|
216 Children.Add(control); |
|
217 |
|
218 Layout.Reset(); |
|
219 X++; |
|
220 } |
|
221 |
|
222 public static GridContainer CreateGridContainer(Container parent, int margin, int colspacing, int rowspacing) |
|
223 { |
|
224 return Application.GetInstance().Exec<GridContainer>(() => new GridContainer(parent, margin, colspacing, rowspacing)); |
163 } |
225 } |
164 } |
226 } |
165 } |
227 } |