| 84 GtkWidget *add = NULL; |
84 GtkWidget *add = NULL; |
| 85 UiContainerX *container = NULL; |
85 UiContainerX *container = NULL; |
| 86 switch(type) { |
86 switch(type) { |
| 87 default: { |
87 default: { |
| 88 sub = ui_gtk_vbox_new(spacing); |
88 sub = ui_gtk_vbox_new(spacing); |
| 89 add = ui_box_set_margin(sub, margin); |
89 add = ui_gtk_set_margin(sub, margin, 0, 0, 0, 0); |
| 90 container = ui_box_container(obj, sub, type); |
90 container = ui_box_container(obj, sub, type); |
| 91 break; |
91 break; |
| 92 } |
92 } |
| 93 case UI_CONTAINER_HBOX: { |
93 case UI_CONTAINER_HBOX: { |
| 94 sub = ui_gtk_hbox_new(spacing); |
94 sub = ui_gtk_hbox_new(spacing); |
| 95 add = ui_box_set_margin(sub, margin); |
95 add = ui_gtk_set_margin(sub, margin, 0, 0, 0, 0); |
| 96 container = ui_box_container(obj, sub, type); |
96 container = ui_box_container(obj, sub, type); |
| 97 break; |
97 break; |
| 98 } |
98 } |
| 99 case UI_CONTAINER_GRID: { |
99 case UI_CONTAINER_GRID: { |
| 100 sub = ui_create_grid_widget(columnspacing, rowspacing); |
100 sub = ui_create_grid_widget(columnspacing, rowspacing); |
| 101 add = ui_box_set_margin(sub, margin); |
101 add = ui_gtk_set_margin(sub, margin, 0, 0, 0, 0); |
| 102 container = ui_grid_container(obj, sub, FALSE, FALSE, FALSE, FALSE); |
102 container = ui_grid_container(obj, sub, FALSE, FALSE, FALSE, FALSE); |
| 103 break; |
103 break; |
| 104 } |
104 } |
| 105 case UI_CONTAINER_NO_SUB: { |
105 case UI_CONTAINER_NO_SUB: { |
| 106 break; |
106 break; |
| 125 return (UiContainerX*)ct; |
125 return (UiContainerX*)ct; |
| 126 } |
126 } |
| 127 |
127 |
| 128 void ui_box_container_add(UiContainerPrivate *ct, GtkWidget *widget, UiLayout *layout) { |
128 void ui_box_container_add(UiContainerPrivate *ct, GtkWidget *widget, UiLayout *layout) { |
| 129 UiBoxContainer *bc = (UiBoxContainer*)ct; |
129 UiBoxContainer *bc = (UiBoxContainer*)ct; |
| |
130 widget = ui_gtk_set_margin(widget, layout->margin, layout->margin_left, layout->margin_right, layout->margin_top, layout->margin_bottom); |
| |
131 |
| 130 UiBool fill = layout->fill; |
132 UiBool fill = layout->fill; |
| 131 if(bc->has_fill && fill) { |
133 if(bc->has_fill && fill) { |
| 132 fprintf(stderr, "UiError: container has 2 filled widgets"); |
134 fprintf(stderr, "UiError: container has 2 filled widgets"); |
| 133 fill = FALSE; |
135 fill = FALSE; |
| 134 } |
136 } |
| 182 |
184 |
| 183 |
185 |
| 184 #if GTK_MAJOR_VERSION >= 3 |
186 #if GTK_MAJOR_VERSION >= 3 |
| 185 void ui_grid_container_add(UiContainerPrivate *ct, GtkWidget *widget, UiLayout *layout) { |
187 void ui_grid_container_add(UiContainerPrivate *ct, GtkWidget *widget, UiLayout *layout) { |
| 186 UiGridContainer *grid = (UiGridContainer*)ct; |
188 UiGridContainer *grid = (UiGridContainer*)ct; |
| |
189 widget = ui_gtk_set_margin(widget, layout->margin, layout->margin_left, layout->margin_right, layout->margin_top, layout->margin_bottom); |
| 187 |
190 |
| 188 if(ct->container.newline) { |
191 if(ct->container.newline) { |
| 189 grid->x = 0; |
192 grid->x = 0; |
| 190 grid->y++; |
193 grid->y++; |
| 191 ct->container.newline = FALSE; |
194 ct->container.newline = FALSE; |
| 265 ct->add = ui_frame_container_add; |
269 ct->add = ui_frame_container_add; |
| 266 return (UiContainerX*)ct; |
270 return (UiContainerX*)ct; |
| 267 } |
271 } |
| 268 |
272 |
| 269 void ui_frame_container_add(UiContainerPrivate *ct, GtkWidget *widget, UiLayout *layout) { |
273 void ui_frame_container_add(UiContainerPrivate *ct, GtkWidget *widget, UiLayout *layout) { |
| |
274 widget = ui_gtk_set_margin(widget, layout->margin, layout->margin_left, layout->margin_right, layout->margin_top, layout->margin_bottom); |
| 270 FRAME_SET_CHILD(ct->widget, widget); |
275 FRAME_SET_CHILD(ct->widget, widget); |
| 271 ct->current = widget; |
276 ct->current = widget; |
| 272 } |
277 } |
| 273 |
278 |
| 274 UiContainerX* ui_expander_container(UiObject *obj, GtkWidget *expander) { |
279 UiContainerX* ui_expander_container(UiObject *obj, GtkWidget *expander) { |
| 280 ct->add = ui_expander_container_add; |
285 ct->add = ui_expander_container_add; |
| 281 return (UiContainerX*)ct; |
286 return (UiContainerX*)ct; |
| 282 } |
287 } |
| 283 |
288 |
| 284 void ui_expander_container_add(UiContainerPrivate *ct, GtkWidget *widget, UiLayout *layout) { |
289 void ui_expander_container_add(UiContainerPrivate *ct, GtkWidget *widget, UiLayout *layout) { |
| |
290 widget = ui_gtk_set_margin(widget, layout->margin, layout->margin_left, layout->margin_right, layout->margin_top, layout->margin_bottom); |
| 285 EXPANDER_SET_CHILD(ct->widget, widget); |
291 EXPANDER_SET_CHILD(ct->widget, widget); |
| 286 ct->current = widget; |
292 ct->current = widget; |
| 287 } |
293 } |
| 288 |
294 |
| 289 void ui_scrolledwindow_container_add(UiContainerPrivate *ct, GtkWidget *widget, UiLayout *layout) { |
295 void ui_scrolledwindow_container_add(UiContainerPrivate *ct, GtkWidget *widget, UiLayout *layout) { |
| |
296 widget = ui_gtk_set_margin(widget, layout->margin, layout->margin_left, layout->margin_right, layout->margin_top, layout->margin_bottom); |
| 290 // TODO: check if the widget implements GtkScrollable |
297 // TODO: check if the widget implements GtkScrollable |
| 291 SCROLLEDWINDOW_SET_CHILD(ct->widget, widget); |
298 SCROLLEDWINDOW_SET_CHILD(ct->widget, widget); |
| 292 ct->current = widget; |
299 ct->current = widget; |
| 293 } |
300 } |
| 294 |
301 |
| 316 UiGtkTabView *data = ui_widget_get_tabview_data(ct->widget); |
323 UiGtkTabView *data = ui_widget_get_tabview_data(ct->widget); |
| 317 if(!data) { |
324 if(!data) { |
| 318 fprintf(stderr, "UI Error: widget is not a tabview"); |
325 fprintf(stderr, "UI Error: widget is not a tabview"); |
| 319 return; |
326 return; |
| 320 } |
327 } |
| |
328 widget = ui_gtk_set_margin(widget, layout->margin, layout->margin_left, layout->margin_right, layout->margin_top, layout->margin_bottom); |
| 321 data->add_tab(ct->widget, -1, layout->label, widget); |
329 data->add_tab(ct->widget, -1, layout->label, widget); |
| 322 |
330 |
| 323 ct->current = widget; |
331 ct->current = widget; |
| 324 } |
332 } |
| 325 |
333 |
| 326 |
334 #ifdef UI_GTK2 |
| 327 |
335 |
| 328 GtkWidget* ui_box_set_margin(GtkWidget *box, int margin) { |
336 static void alignment_child_visibility_changed(GtkWidget *widget, gpointer user_data) { |
| 329 GtkWidget *ret = box; |
337 gtk_widget_set_visible(gtk_widget_get_parent(widget), gtk_widget_get_visible(widget)); |
| |
338 } |
| |
339 |
| |
340 #endif |
| |
341 |
| |
342 GtkWidget* ui_gtk_set_margin(GtkWidget *widget, int margin, int margin_left, int margin_right, int margin_top, int margin_bottom) { |
| |
343 if(margin > 0) { |
| |
344 margin_left = margin; |
| |
345 margin_right = margin; |
| |
346 margin_top = margin; |
| |
347 margin_bottom = margin; |
| |
348 } |
| |
349 GtkWidget *ret = widget; |
| 330 #if GTK_MAJOR_VERSION >= 3 |
350 #if GTK_MAJOR_VERSION >= 3 |
| 331 #if GTK_MAJOR_VERSION * 1000 + GTK_MINOR_VERSION >= 3012 |
351 #if GTK_CHECK_VERSION(3, 12, 0) |
| 332 gtk_widget_set_margin_start(box, margin); |
352 gtk_widget_set_margin_start(widget, margin_left); |
| 333 gtk_widget_set_margin_end(box, margin); |
353 gtk_widget_set_margin_end(widget, margin_right); |
| 334 #else |
354 #else |
| 335 gtk_widget_set_margin_left(box, margin); |
355 gtk_widget_set_margin_left(widget, margin_left); |
| 336 gtk_widget_set_margin_right(box, margin); |
356 gtk_widget_set_margin_right(widget, margin_right); |
| 337 #endif |
357 #endif |
| 338 gtk_widget_set_margin_top(box, margin); |
358 gtk_widget_set_margin_top(widget, margin_top); |
| 339 gtk_widget_set_margin_bottom(box, margin); |
359 gtk_widget_set_margin_bottom(widget, margin_bottom); |
| 340 #elif defined(UI_GTK2) |
360 #elif defined(UI_GTK2) |
| 341 GtkWidget *a = gtk_alignment_new(0.5, 0.5, 1, 1); |
361 GtkWidget *a = gtk_alignment_new(0.5, 0.5, 1, 1); |
| 342 gtk_alignment_set_padding(GTK_ALIGNMENT(a), margin, margin, margin, margin); |
362 gtk_alignment_set_padding(GTK_ALIGNMENT(a), margin_top, margin_bottom, margin_left, margin_right); |
| 343 gtk_container_add(GTK_CONTAINER(a), box); |
363 gtk_container_add(GTK_CONTAINER(a), widget); |
| |
364 g_signal_connect( |
| |
365 widget, |
| |
366 "show", |
| |
367 G_CALLBACK(alignment_child_visibility_changed), |
| |
368 NULL); |
| |
369 g_signal_connect( |
| |
370 widget, |
| |
371 "hide", |
| |
372 G_CALLBACK(alignment_child_visibility_changed), |
| |
373 NULL); |
| 344 ret = a; |
374 ret = a; |
| 345 #endif |
375 #endif |
| 346 return ret; |
376 return ret; |
| 347 } |
377 } |
| 348 |
378 |
| 350 UiContainerPrivate *ct = (UiContainerPrivate*)obj->container_end; |
380 UiContainerPrivate *ct = (UiContainerPrivate*)obj->container_end; |
| 351 UiLayout layout = UI_ARGS2LAYOUT(args); |
381 UiLayout layout = UI_ARGS2LAYOUT(args); |
| 352 |
382 |
| 353 GtkWidget *box = type == UI_CONTAINER_VBOX ? ui_gtk_vbox_new(args->spacing) : ui_gtk_hbox_new(args->spacing); |
383 GtkWidget *box = type == UI_CONTAINER_VBOX ? ui_gtk_vbox_new(args->spacing) : ui_gtk_hbox_new(args->spacing); |
| 354 ui_set_name_and_style(box, args->name, args->style_class); |
384 ui_set_name_and_style(box, args->name, args->style_class); |
| 355 GtkWidget *widget = args->margin > 0 ? ui_box_set_margin(box, args->margin) : box; // TODO: remove, margin will be handled by container add-functions |
385 ct->add(ct, box, &layout); |
| 356 ct->add(ct, widget, &layout); |
|
| 357 |
386 |
| 358 UiContainerX *container = ui_box_container(obj, box, type); |
387 UiContainerX *container = ui_box_container(obj, box, type); |
| 359 uic_object_push_container(obj, container); |
388 uic_object_push_container(obj, container); |
| 360 |
389 |
| 361 return widget; |
390 return box; |
| 362 } |
391 } |
| 363 |
392 |
| 364 UIEXPORT UIWIDGET ui_vbox_create(UiObject *obj, UiContainerArgs *args) { |
393 UIEXPORT UIWIDGET ui_vbox_create(UiObject *obj, UiContainerArgs *args) { |
| 365 return ui_box_create(obj, args, UI_CONTAINER_VBOX); |
394 return ui_box_create(obj, args, UI_CONTAINER_VBOX); |
| 366 } |
395 } |
| 387 UiLayout layout = UI_ARGS2LAYOUT(args); |
416 UiLayout layout = UI_ARGS2LAYOUT(args); |
| 388 GtkWidget *widget; |
417 GtkWidget *widget; |
| 389 |
418 |
| 390 GtkWidget *grid = ui_create_grid_widget(args->columnspacing, args->rowspacing); |
419 GtkWidget *grid = ui_create_grid_widget(args->columnspacing, args->rowspacing); |
| 391 ui_set_name_and_style(grid, args->name, args->style_class); |
420 ui_set_name_and_style(grid, args->name, args->style_class); |
| 392 widget = ui_box_set_margin(grid, args->margin); |
421 ct->add(ct, grid, &layout); |
| 393 ct->add(ct, widget, &layout); |
|
| 394 |
422 |
| 395 UiContainerX *container = ui_grid_container(obj, grid, args->def_hexpand, args->def_vexpand, args->def_hfill, args->def_vfill); |
423 UiContainerX *container = ui_grid_container(obj, grid, args->def_hexpand, args->def_vexpand, args->def_hfill, args->def_vfill); |
| 396 uic_object_push_container(obj, container); |
424 uic_object_push_container(obj, container); |
| 397 |
425 |
| 398 return widget; |
426 return grid; |
| 399 } |
427 } |
| 400 |
428 |
| 401 static void frame_create_subcontainer(UiObject *obj, UiFrameArgs *args) { |
429 static void frame_create_subcontainer(UiObject *obj, UiFrameArgs *args) { |
| 402 switch(args->subcontainer) { |
430 switch(args->subcontainer) { |
| 403 default: |
431 default: |
| 979 fprintf(stderr, "Error: window is not configured for sidebar\n"); |
1007 fprintf(stderr, "Error: window is not configured for sidebar\n"); |
| 980 return NULL; |
1008 return NULL; |
| 981 } |
1009 } |
| 982 |
1010 |
| 983 GtkWidget *box = ui_gtk_vbox_new(args->spacing); |
1011 GtkWidget *box = ui_gtk_vbox_new(args->spacing); |
| 984 ui_box_set_margin(box, args->margin); |
1012 ui_gtk_set_margin(box, args->margin, args->margin_left, args->margin_right, args->margin_top, args->margin_bottom); |
| 985 adw_toolbar_view_set_content(ADW_TOOLBAR_VIEW(sidebar_toolbar_view), box); |
1013 adw_toolbar_view_set_content(ADW_TOOLBAR_VIEW(sidebar_toolbar_view), box); |
| 986 |
1014 |
| 987 UiContainerX *container = ui_box_container(obj, box, UI_CONTAINER_VBOX); |
1015 UiContainerX *container = ui_box_container(obj, box, UI_CONTAINER_VBOX); |
| 988 uic_object_push_container(obj, container); |
1016 uic_object_push_container(obj, container); |
| 989 |
1017 |
| 992 #else |
1020 #else |
| 993 UIWIDGET ui_sidebar_create(UiObject *obj, UiSidebarArgs *args) { |
1021 UIWIDGET ui_sidebar_create(UiObject *obj, UiSidebarArgs *args) { |
| 994 GtkWidget *sidebar_vbox = g_object_get_data(G_OBJECT(obj->widget), "ui_sidebar"); |
1022 GtkWidget *sidebar_vbox = g_object_get_data(G_OBJECT(obj->widget), "ui_sidebar"); |
| 995 |
1023 |
| 996 GtkWidget *box = ui_gtk_vbox_new(args->spacing); |
1024 GtkWidget *box = ui_gtk_vbox_new(args->spacing); |
| 997 ui_box_set_margin(box, args->margin); |
1025 ui_gtk_set_margin(box, args->margin, args->margin-left, args->margin_right, args->margin_top, args->margin_bottom); |
| 998 BOX_ADD_EXPAND(sidebar_vbox, box); |
1026 BOX_ADD_EXPAND(sidebar_vbox, box); |
| 999 |
1027 |
| 1000 UiContainerX *container = ui_box_container(obj, box, UI_CONTAINER_VBOX); |
1028 UiContainerX *container = ui_box_container(obj, box, UI_CONTAINER_VBOX); |
| 1001 uic_object_push_container(obj, container); |
1029 uic_object_push_container(obj, container); |
| 1002 |
1030 |
| 1012 return NULL; |
1040 return NULL; |
| 1013 } |
1041 } |
| 1014 |
1042 |
| 1015 GtkWidget *box = ui_gtk_vbox_new(args->spacing); |
1043 GtkWidget *box = ui_gtk_vbox_new(args->spacing); |
| 1016 ui_set_name_and_style(box, args->name, args->style_class); |
1044 ui_set_name_and_style(box, args->name, args->style_class); |
| 1017 ui_box_set_margin(box, args->margin); |
1045 ui_gtk_set_margin(box, args->margin, args->margin_left, args->margin_right, args->margin_top, args->margin_bottom); |
| 1018 BOX_ADD_EXPAND(pbox, box); |
1046 BOX_ADD_EXPAND(pbox, box); |
| 1019 |
1047 |
| 1020 UiContainerX *container = ui_box_container(obj, box, UI_CONTAINER_VBOX); |
1048 UiContainerX *container = ui_box_container(obj, box, UI_CONTAINER_VBOX); |
| 1021 uic_object_push_container(obj, container); |
1049 uic_object_push_container(obj, container); |
| 1022 |
1050 |
| 1267 UiContainerPrivate *ct = (UiContainerPrivate*)obj->container_end; |
1295 UiContainerPrivate *ct = (UiContainerPrivate*)obj->container_end; |
| 1268 UiLayout layout = UI_ARGS2LAYOUT(args); |
1296 UiLayout layout = UI_ARGS2LAYOUT(args); |
| 1269 |
1297 |
| 1270 GtkWidget *box = args->container == UI_CONTAINER_VBOX ? ui_gtk_vbox_new(args->spacing) : ui_gtk_hbox_new(args->spacing); |
1298 GtkWidget *box = args->container == UI_CONTAINER_VBOX ? ui_gtk_vbox_new(args->spacing) : ui_gtk_hbox_new(args->spacing); |
| 1271 ui_set_name_and_style(box, args->name, args->style_class); |
1299 ui_set_name_and_style(box, args->name, args->style_class); |
| 1272 GtkWidget *widget = args->margin > 0 ? ui_box_set_margin(box, args->margin) : box; |
1300 ct->add(ct, box, &layout); |
| 1273 ct->add(ct, widget, &layout); |
|
| 1274 |
1301 |
| 1275 UiGtkItemListContainer *container = malloc(sizeof(UiGtkItemListContainer)); |
1302 UiGtkItemListContainer *container = malloc(sizeof(UiGtkItemListContainer)); |
| 1276 container->parent = obj; |
1303 container->parent = obj; |
| 1277 container->widget = box; |
1304 container->widget = box; |
| 1278 container->container = (UiContainerPrivate*)ui_box_container(obj, box, args->container); |
1305 container->container = (UiContainerPrivate*)ui_box_container(obj, box, args->container); |