105 break; |
105 break; |
106 } |
106 } |
107 case UI_CONTAINER_GRID: { |
107 case UI_CONTAINER_GRID: { |
108 sub = ui_create_grid_widget(columnspacing, rowspacing); |
108 sub = ui_create_grid_widget(columnspacing, rowspacing); |
109 add = ui_box_set_margin(sub, margin); |
109 add = ui_box_set_margin(sub, margin); |
110 newobj->container = ui_grid_container(newobj, sub); |
110 newobj->container = ui_grid_container(newobj, sub, FALSE, FALSE, FALSE, FALSE); |
111 newobj->widget = sub; |
111 newobj->widget = sub; |
112 break; |
112 break; |
113 } |
113 } |
114 case UI_CONTAINER_NO_SUB: { |
114 case UI_CONTAINER_NO_SUB: { |
115 break; |
115 break; |
165 |
165 |
166 ui_reset_layout(ct->layout); |
166 ui_reset_layout(ct->layout); |
167 ct->current = widget; |
167 ct->current = widget; |
168 } |
168 } |
169 |
169 |
170 UiContainer* ui_grid_container(UiObject *obj, GtkWidget *grid) { |
170 UiContainer* ui_grid_container( |
|
171 UiObject *obj, |
|
172 GtkWidget *grid, |
|
173 UiBool def_hexpand, |
|
174 UiBool def_vexpand, |
|
175 UiBool def_hfill, |
|
176 UiBool def_vfill) |
|
177 { |
171 UiGridContainer *ct = cxCalloc( |
178 UiGridContainer *ct = cxCalloc( |
172 obj->ctx->allocator, |
179 obj->ctx->allocator, |
173 1, |
180 1, |
174 sizeof(UiGridContainer)); |
181 sizeof(UiGridContainer)); |
|
182 ct->def_hexpand = def_hexpand; |
|
183 ct->def_vexpand = def_vexpand; |
|
184 ct->def_hfill = def_hfill; |
|
185 ct->def_vfill = def_vfill; |
175 ct->container.widget = grid; |
186 ct->container.widget = grid; |
176 ct->container.add = ui_grid_container_add; |
187 ct->container.add = ui_grid_container_add; |
177 UI_GTK_V2(ct->width = 0); |
188 UI_GTK_V2(ct->width = 0); |
178 UI_GTK_V2(ct->height = 1); |
189 UI_GTK_V2(ct->height = 1); |
179 return (UiContainer*)ct; |
190 return (UiContainer*)ct; |
191 |
202 |
192 int hexpand = FALSE; |
203 int hexpand = FALSE; |
193 int vexpand = FALSE; |
204 int vexpand = FALSE; |
194 int hfill = FALSE; |
205 int hfill = FALSE; |
195 int vfill = FALSE; |
206 int vfill = FALSE; |
|
207 if(!ct->layout.override_defaults) { |
|
208 if(grid->def_hexpand) { |
|
209 hexpand = TRUE; |
|
210 hfill = TRUE; |
|
211 } else if(grid->def_hfill) { |
|
212 hfill = TRUE; |
|
213 } |
|
214 if(grid->def_vexpand) { |
|
215 vexpand = TRUE; |
|
216 vfill = TRUE; |
|
217 } else if(grid->def_vfill) { |
|
218 vfill = TRUE; |
|
219 } |
|
220 } |
|
221 |
196 if(ct->layout.fill != UI_LAYOUT_UNDEFINED) { |
222 if(ct->layout.fill != UI_LAYOUT_UNDEFINED) { |
197 fill = ui_lb2bool(ct->layout.fill); |
223 fill = ui_lb2bool(ct->layout.fill); |
198 } |
224 } |
199 if(ct->layout.hexpand != UI_LAYOUT_UNDEFINED) { |
225 if(ct->layout.hexpand) { |
200 hexpand = ct->layout.hexpand; |
226 hexpand = TRUE; |
201 hfill = TRUE; |
227 hfill = TRUE; |
202 } |
228 } else if(ct->layout.hfill) { |
203 if(ct->layout.vexpand != UI_LAYOUT_UNDEFINED) { |
229 hfill = TRUE; |
204 vexpand = ct->layout.vexpand; |
230 } |
|
231 if(ct->layout.vexpand) { |
|
232 vexpand = TRUE; |
|
233 vfill = TRUE; |
|
234 } else if(ct->layout.vfill) { |
205 vfill = TRUE; |
235 vfill = TRUE; |
206 } |
236 } |
207 if(fill) { |
237 if(fill) { |
208 hfill = TRUE; |
238 hfill = TRUE; |
209 vfill = TRUE; |
239 vfill = TRUE; |
239 ct->layout.newline = FALSE; |
269 ct->layout.newline = FALSE; |
240 } |
270 } |
241 |
271 |
242 int hexpand = FALSE; |
272 int hexpand = FALSE; |
243 int vexpand = FALSE; |
273 int vexpand = FALSE; |
244 if(ct->layout.hexpand != UI_LAYOUT_UNDEFINED) { |
274 int hfill = FALSE; |
245 hexpand = ct->layout.hexpand; |
275 int vfill = FALSE; |
246 } |
276 if(!ct->layout.override_defaults) { |
247 if(ct->layout.vexpand != UI_LAYOUT_UNDEFINED) { |
277 if(grid->def_hexpand) { |
248 vexpand = ct->layout.vexpand; |
278 hexpand = TRUE; |
249 } |
279 hfill = TRUE; |
250 GtkAttachOptions xoptions = hexpand ? GTK_FILL | GTK_EXPAND : GTK_FILL; |
280 } else if(grid->def_hfill) { |
251 GtkAttachOptions yoptions = vexpand ? GTK_FILL | GTK_EXPAND : GTK_FILL; |
281 hfill = TRUE; |
|
282 } |
|
283 if(grid->def_vexpand) { |
|
284 vexpand = TRUE; |
|
285 vfill = TRUE; |
|
286 } else if(grid->def_vfill) { |
|
287 vfill = TRUE; |
|
288 } |
|
289 } |
|
290 |
|
291 if(ct->layout.fill != UI_LAYOUT_UNDEFINED) { |
|
292 fill = ui_lb2bool(ct->layout.fill); |
|
293 } |
|
294 if(ct->layout.hexpand) { |
|
295 hexpand = TRUE; |
|
296 hfill = TRUE; |
|
297 } else if(ct->layout.hfill) { |
|
298 hfill = TRUE; |
|
299 } |
|
300 if(ct->layout.vexpand) { |
|
301 vexpand = TRUE; |
|
302 vfill = TRUE; |
|
303 } else if(ct->layout.vfill) { |
|
304 vfill = TRUE; |
|
305 } |
|
306 if(fill) { |
|
307 hfill = TRUE; |
|
308 vfill = TRUE; |
|
309 } |
|
310 |
|
311 GtkAttachOptions xoptions = 0; |
|
312 GtkAttachOptions yoptions = 0; |
|
313 if(hexpand) { |
|
314 xoptions = GTK_EXPAND; |
|
315 } |
|
316 if(hfill) { |
|
317 xoptions |= GTK_FILL; |
|
318 } |
|
319 if(vexpand) { |
|
320 yoptions = GTK_EXPAND; |
|
321 } |
|
322 if(vfill) { |
|
323 yoptions |= GTK_FILL; |
|
324 } |
252 |
325 |
253 int colspan = ct->layout.colspan > 0 ? ct->layout.colspan : 1; |
326 int colspan = ct->layout.colspan > 0 ? ct->layout.colspan : 1; |
254 int rowspan = ct->layout.rowspan > 0 ? ct->layout.rowspan : 1; |
327 int rowspan = ct->layout.rowspan > 0 ? ct->layout.rowspan : 1; |
255 // TODO: use colspan/rowspan |
328 // TODO: use colspan/rowspan |
256 |
329 |
405 ui_set_name_and_style(grid, args.name, args.style_class); |
478 ui_set_name_and_style(grid, args.name, args.style_class); |
406 widget = ui_box_set_margin(grid, args.margin); |
479 widget = ui_box_set_margin(grid, args.margin); |
407 current->container->add(current->container, widget, TRUE); |
480 current->container->add(current->container, widget, TRUE); |
408 |
481 |
409 UiObject *newobj = uic_object_new(obj, grid); |
482 UiObject *newobj = uic_object_new(obj, grid); |
410 newobj->container = ui_grid_container(obj, grid); |
483 newobj->container = ui_grid_container(obj, grid, args.def_hexpand, args.def_vexpand, args.def_hfill, args.def_vfill); |
411 uic_obj_add(obj, newobj); |
484 uic_obj_add(obj, newobj); |
412 |
485 |
413 return widget; |
486 return widget; |
414 } |
487 } |
415 |
488 |
764 newobj->container = ui_box_container(newobj, sub, data->subcontainer); |
837 newobj->container = ui_box_container(newobj, sub, data->subcontainer); |
765 break; |
838 break; |
766 } |
839 } |
767 case UI_CONTAINER_GRID: { |
840 case UI_CONTAINER_GRID: { |
768 sub = ui_create_grid_widget(data->columnspacing, data->rowspacing); |
841 sub = ui_create_grid_widget(data->columnspacing, data->rowspacing); |
769 newobj->container = ui_grid_container(newobj, sub); |
842 newobj->container = ui_grid_container(newobj, sub, FALSE, FALSE, FALSE, FALSE); |
770 break; |
843 break; |
771 } |
844 } |
772 } |
845 } |
773 newobj->widget = sub; |
846 newobj->widget = sub; |
774 GtkWidget *widget = ui_box_set_margin(sub, data->margin); |
847 GtkWidget *widget = ui_box_set_margin(sub, data->margin); |
1173 void ui_layout_vfill(UiObject *obj, UiBool fill) { |
1246 void ui_layout_vfill(UiObject *obj, UiBool fill) { |
1174 UiContainer *ct = uic_get_current_container(obj); |
1247 UiContainer *ct = uic_get_current_container(obj); |
1175 ct->layout.vfill = fill; |
1248 ct->layout.vfill = fill; |
1176 } |
1249 } |
1177 |
1250 |
|
1251 UIEXPORT void ui_layout_override_defaults(UiObject *obj, UiBool d) { |
|
1252 UiContainer *ct = uic_get_current_container(obj); |
|
1253 ct->layout.override_defaults = d; |
|
1254 } |
|
1255 |
1178 void ui_layout_colspan(UiObject* obj, int cols) { |
1256 void ui_layout_colspan(UiObject* obj, int cols) { |
1179 UiContainer* ct = uic_get_current_container(obj); |
1257 UiContainer* ct = uic_get_current_container(obj); |
1180 ct->layout.colspan = cols; |
1258 ct->layout.colspan = cols; |
1181 } |
1259 } |
1182 |
1260 |