8 |
8 |
9 namespace UI |
9 namespace UI |
10 { |
10 { |
11 public interface Container |
11 public interface Container |
12 { |
12 { |
|
13 Layout Layout { get; set; } |
|
14 |
13 void Add(UIElement control, bool fill); |
15 void Add(UIElement control, bool fill); |
|
16 } |
|
17 |
|
18 public class Layout |
|
19 { |
|
20 public bool? Fill { get; set; } |
|
21 |
|
22 public Layout() |
|
23 { |
|
24 Fill = null; |
|
25 } |
|
26 |
|
27 public bool IsFill(bool fill) |
|
28 { |
|
29 if (Fill != null) |
|
30 { |
|
31 |
|
32 return (bool)Fill; |
|
33 } |
|
34 return fill; |
|
35 } |
|
36 |
|
37 public void Reset() |
|
38 { |
|
39 Fill = null; |
|
40 } |
14 } |
41 } |
15 |
42 |
16 public enum BoxOrientation |
43 public enum BoxOrientation |
17 { |
44 { |
18 VERTICAL, |
45 VERTICAL, |
19 HORIZONTAL |
46 HORIZONTAL |
20 } |
47 } |
21 |
48 |
22 public class BoxContainer : Grid, Container |
49 public class BoxContainer : Grid, Container |
23 { |
50 { |
24 public BoxOrientation Orientation; |
51 public Layout Layout { get; set; } |
|
52 |
|
53 private BoxOrientation Orientation; |
25 |
54 |
26 private int x = 0; |
55 private int x = 0; |
27 private int y = 0; |
56 private int y = 0; |
28 |
57 |
29 private bool filled = false; |
58 private bool filled = false; |
30 |
59 |
31 public BoxContainer(BoxOrientation orientation) : base() |
60 public BoxContainer(BoxOrientation orientation) : base() |
32 { |
61 { |
|
62 Layout = new Layout(); |
|
63 |
33 Orientation = orientation; |
64 Orientation = orientation; |
34 if(Orientation == BoxOrientation.HORIZONTAL) |
65 if(Orientation == BoxOrientation.HORIZONTAL) |
35 { |
66 { |
36 RowDefinition row = new RowDefinition(); |
67 RowDefinition row = new RowDefinition(); |
37 row.Height = new GridLength(1, GridUnitType.Star); |
68 row.Height = new GridLength(1, GridUnitType.Star); |
50 parent.Add(this, true); |
81 parent.Add(this, true); |
51 } |
82 } |
52 |
83 |
53 public void Add(UIElement control, bool fill) |
84 public void Add(UIElement control, bool fill) |
54 { |
85 { |
|
86 fill = Layout.IsFill(fill); |
|
87 |
55 if(Orientation == BoxOrientation.HORIZONTAL) |
88 if(Orientation == BoxOrientation.HORIZONTAL) |
56 { |
89 { |
57 ColumnDefinition col = new ColumnDefinition(); |
90 ColumnDefinition col = new ColumnDefinition(); |
58 if(filled && fill) |
91 if(filled && fill) |
59 { |
92 { |
101 } |
134 } |
102 else |
135 else |
103 { |
136 { |
104 y++; |
137 y++; |
105 } |
138 } |
|
139 |
|
140 Layout.Reset(); |
106 } |
141 } |
107 |
142 |
108 public static BoxContainer CreateBoxContainer(Container parent, BoxOrientation orientation) |
143 public static BoxContainer CreateBoxContainer(Container parent, BoxOrientation orientation) |
109 { |
144 { |
110 return Application.GetInstance().Exec<BoxContainer>(() => new BoxContainer(parent, orientation)); |
145 return Application.GetInstance().Exec<BoxContainer>(() => new BoxContainer(parent, orientation)); |
111 } |
146 } |
112 } |
147 } |
113 |
148 |
114 public class GridContainer : Container |
149 public class GridContainer : Container |
115 { |
150 { |
|
151 public Layout Layout { get; set; } |
|
152 |
116 public Grid Grid; |
153 public Grid Grid; |
117 |
154 |
118 public GridContainer(System.Windows.Controls.Grid grid) |
155 public GridContainer(System.Windows.Controls.Grid grid) |
119 { |
156 { |
120 Grid = grid; |
157 Grid = grid; |