ui/wpf/UIcore/Container.cs

changeset 101
1c943d43fa81
parent 85
91f45354d1e2
child 104
3efe0210e27e
equal deleted inserted replaced
100:d276306d801f 101:1c943d43fa81
16 } 16 }
17 17
18 public class Layout 18 public class Layout
19 { 19 {
20 public bool? Fill { get; set; } 20 public bool? Fill { get; set; }
21 public bool Hexpand { get; set; }
22 public bool Vexpand { get; set; }
23 public bool NewLine { get; set; }
21 24
22 public Layout() 25 public Layout()
23 { 26 {
24 Fill = null; 27 Reset();
25 } 28 }
26 29
27 public bool IsFill(bool fill) 30 public bool IsFill(bool fill)
28 { 31 {
29 if (Fill != null) 32 if (Fill != null)
35 } 38 }
36 39
37 public void Reset() 40 public void Reset()
38 { 41 {
39 Fill = null; 42 Fill = null;
43 Hexpand = false;
44 Vexpand = false;
45 NewLine = false;
40 } 46 }
41 } 47 }
42 48
43 public enum BoxOrientation 49 public enum BoxOrientation
44 { 50 {
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 }

mercurial