26 * POSSIBILITY OF SUCH DAMAGE. |
26 * POSSIBILITY OF SUCH DAMAGE. |
27 */ |
27 */ |
28 |
28 |
29 #include "container.h" |
29 #include "container.h" |
30 |
30 |
|
31 #include "../common/context.h" |
|
32 #include "../common/object.h" |
|
33 |
|
34 |
|
35 void ui_container_begin_close(UiObject* obj) { |
|
36 UiContainer* ct = uic_get_current_container(obj); |
|
37 ct->close = 1; |
|
38 } |
|
39 |
|
40 int ui_container_finish(UiObject* obj) { |
|
41 UiContainer* ct = uic_get_current_container(obj); |
|
42 if (ct->close) { |
|
43 ui_end(obj); |
|
44 return 0; |
|
45 } |
|
46 return 1; |
|
47 } |
|
48 |
|
49 |
|
50 // --------------------- UiBoxContainer --------------------- |
31 |
51 |
32 UiBoxContainer::UiBoxContainer(Grid grid, enum UiBoxContainerType type) { |
52 UiBoxContainer::UiBoxContainer(Grid grid, enum UiBoxContainerType type) { |
33 this->grid = grid; |
53 this->grid = grid; |
34 this->type = type; |
54 this->type = type; |
35 |
55 |
|
56 GridLength gl; |
|
57 gl.Value = 1; |
|
58 gl.GridUnitType = GridUnitType::Star; |
|
59 |
36 // hbox needs one row def, vbox needs one col def |
60 // hbox needs one row def, vbox needs one col def |
37 // all other col/row defs are created when elements are added |
61 // all other col/row defs are created when elements are added |
38 if (type == UI_CONTAINER_HBOX) { |
62 if (type == UI_CONTAINER_HBOX) { |
39 RowDefinition rowdef = RowDefinition(); |
63 boxRowDef = RowDefinition(); |
40 grid.RowDefinitions().Append(rowdef); |
64 boxRowDef.Height(gl); |
|
65 grid.RowDefinitions().Append(boxRowDef); |
41 } else { |
66 } else { |
42 ColumnDefinition coldef = ColumnDefinition(); |
67 boxColDef = ColumnDefinition(); |
43 grid.ColumnDefinitions().Append(coldef); |
68 boxColDef.Width(gl); |
44 } |
69 grid.ColumnDefinitions().Append(boxColDef); |
45 } |
70 } |
46 |
71 |
47 void UiBoxContainer::Add(Control control, UiBool fill) { |
72 ui_reset_layout(layout); |
|
73 } |
|
74 |
|
75 void UiBoxContainer::Add(FrameworkElement control, UiBool fill) { |
|
76 if (this->layout.fill != UI_LAYOUT_UNDEFINED) { |
|
77 fill = ui_lb2bool(this->layout.fill); |
|
78 } |
|
79 |
48 GridLength gl; |
80 GridLength gl; |
49 if (fill) { |
81 if (fill) { |
50 gl.Value = 1; |
82 gl.Value = 1; |
51 gl.GridUnitType = GridUnitType::Star; |
83 gl.GridUnitType = GridUnitType::Star; |
52 } |
84 } |
53 else { |
85 else { |
54 gl.Value = 0; |
86 gl.Value = 0; |
55 gl.GridUnitType = GridUnitType::Auto; |
87 gl.GridUnitType = GridUnitType::Auto; |
56 } |
88 } |
57 |
89 |
|
90 control.HorizontalAlignment(HorizontalAlignment::Stretch); |
|
91 control.VerticalAlignment(VerticalAlignment::Stretch); |
|
92 |
58 if (type == UI_CONTAINER_HBOX) { |
93 if (type == UI_CONTAINER_HBOX) { |
59 ColumnDefinition coldef = ColumnDefinition(); |
94 ColumnDefinition coldef = ColumnDefinition(); |
60 coldef.Width(gl); |
95 coldef.Width(gl); |
61 grid.ColumnDefinitions().Append(coldef); |
96 grid.ColumnDefinitions().Append(coldef); |
62 grid.SetColumn(control, grid.Children().Size()); |
97 grid.SetColumn(control, grid.Children().Size()); |
|
98 grid.SetRow(control, 0); |
63 } else { |
99 } else { |
64 RowDefinition rowdef = RowDefinition(); |
100 RowDefinition rowdef = RowDefinition(); |
65 rowdef.Height(gl); |
101 rowdef.Height(gl); |
66 grid.RowDefinitions().Append(rowdef); |
102 grid.RowDefinitions().Append(rowdef); |
67 grid.SetRow(control, grid.Children().Size()); |
103 grid.SetRow(control, grid.Children().Size()); |
|
104 grid.SetColumn(control, 0); |
68 } |
105 } |
69 |
106 |
70 grid.Children().Append(control); |
107 grid.Children().Append(control); |
71 } |
108 |
72 |
109 ui_reset_layout(layout); |
|
110 } |
|
111 |
|
112 // --------------------- UiBoxContainer --------------------- |
|
113 |
|
114 UIWIDGET ui_grid(UiObject* obj) { |
|
115 return ui_grid_sp(obj, 0, 0, 0); |
|
116 } |
|
117 |
|
118 UIWIDGET ui_grid_sp(UiObject* obj, int margin, int columnspacing, int rowspacing) { |
|
119 UiContainer* ct = uic_get_current_container(obj); |
|
120 |
|
121 Grid grid = Grid(); |
|
122 ct->Add(grid, true); |
|
123 |
|
124 UIElement elm = grid; |
|
125 UiWidget* widget = new UiWidget(elm); |
|
126 |
|
127 UiObject* newobj = uic_object_new(obj, widget); |
|
128 newobj->container = new UiGridContainer(grid, margin, columnspacing, rowspacing); |
|
129 uic_obj_add(obj, newobj); |
|
130 |
|
131 return widget; |
|
132 } |
|
133 |
|
134 UiGridContainer::UiGridContainer(Grid grid, int margin, int columnspacing, int rowspacing) { |
|
135 this->grid = grid; |
|
136 Thickness t = { (double)margin, (double)margin, (double)margin, (double)margin }; |
|
137 grid.Margin(t); |
|
138 grid.ColumnSpacing((double)columnspacing); |
|
139 grid.RowSpacing((double)rowspacing); |
|
140 ui_reset_layout(layout); |
|
141 } |
|
142 |
|
143 void UiGridContainer::Add(FrameworkElement control, UiBool fill) { |
|
144 GridLength gl; |
|
145 |
|
146 int hexpand = FALSE; |
|
147 int vexpand = FALSE; |
|
148 if (layout.hexpand != UI_LAYOUT_UNDEFINED) { |
|
149 hexpand = layout.hexpand; |
|
150 } |
|
151 if (layout.vexpand != UI_LAYOUT_UNDEFINED) { |
|
152 vexpand = layout.vexpand; |
|
153 } |
|
154 |
|
155 // create new RowDefinition for the new line |
|
156 if (layout.newline || y == -1) { |
|
157 x = 0; |
|
158 y++; |
|
159 RowDefinition rowdef = RowDefinition(); |
|
160 if (vexpand) { |
|
161 gl.GridUnitType = GridUnitType::Star; |
|
162 gl.Value = 1; |
|
163 } |
|
164 else { |
|
165 gl.GridUnitType = GridUnitType::Auto; |
|
166 gl.Value = 0; |
|
167 } |
|
168 rowdef.Height(gl); |
|
169 grid.RowDefinitions().Append(rowdef); |
|
170 } |
|
171 |
|
172 // create new columndefinition, if a new column is added |
|
173 if (x == cols) { |
|
174 if (hexpand) { |
|
175 gl.GridUnitType = GridUnitType::Star; |
|
176 gl.Value = 1; |
|
177 } |
|
178 else { |
|
179 gl.GridUnitType = GridUnitType::Auto; |
|
180 gl.Value = 0; |
|
181 } |
|
182 ColumnDefinition coldef = ColumnDefinition(); |
|
183 coldef.Width(gl); |
|
184 grid.ColumnDefinitions().Append(coldef); |
|
185 cols++; |
|
186 } |
|
187 |
|
188 // add control |
|
189 control.HorizontalAlignment(HorizontalAlignment::Stretch); |
|
190 control.VerticalAlignment(VerticalAlignment::Stretch); |
|
191 |
|
192 if (layout.gridwidth > 0) { |
|
193 grid.SetColumnSpan(control, layout.gridwidth); |
|
194 } |
|
195 |
|
196 grid.SetRow(control, y); |
|
197 grid.SetColumn(control, x); |
|
198 grid.Children().Append(control); |
|
199 |
|
200 x++; |
|
201 |
|
202 ui_reset_layout(layout); |
|
203 } |
|
204 |
|
205 /* |
|
206 * -------------------- Layout Functions -------------------- |
|
207 * |
|
208 * functions for setting layout attributes for the current container |
|
209 * |
|
210 */ |
|
211 |
|
212 void ui_layout_fill(UiObject* obj, UiBool fill) { |
|
213 UiContainer* ct = uic_get_current_container(obj); |
|
214 ct->layout.fill = ui_bool2lb(fill); |
|
215 } |
|
216 |
|
217 void ui_layout_hexpand(UiObject* obj, UiBool expand) { |
|
218 UiContainer* ct = uic_get_current_container(obj); |
|
219 ct->layout.hexpand = expand; |
|
220 } |
|
221 |
|
222 void ui_layout_vexpand(UiObject* obj, UiBool expand) { |
|
223 UiContainer* ct = uic_get_current_container(obj); |
|
224 ct->layout.vexpand = expand; |
|
225 } |
|
226 |
|
227 void ui_layout_width(UiObject* obj, int width) { |
|
228 UiContainer* ct = uic_get_current_container(obj); |
|
229 ct->layout.width = width; |
|
230 } |
|
231 |
|
232 void ui_layout_gridwidth(UiObject* obj, int width) { |
|
233 UiContainer* ct = uic_get_current_container(obj); |
|
234 ct->layout.gridwidth = width; |
|
235 } |
|
236 |
|
237 void ui_newline(UiObject* obj) { |
|
238 UiContainer* ct = uic_get_current_container(obj); |
|
239 ct->layout.newline = TRUE; |
|
240 } |
|
241 |