diff -r 1b4aae4e8432 -r ae999e3346a9 ui/gtk/container.c --- a/ui/gtk/container.c Sun Oct 27 08:25:15 2024 +0100 +++ b/ui/gtk/container.c Sun Oct 27 08:53:32 2024 +0100 @@ -68,6 +68,44 @@ #endif } +GtkWidget* ui_subcontainer_create( + UiSubContainerType type, + UiObject *newobj, + int spacing, + int columnspacing, + int rowspacing, + int margin) +{ + GtkWidget *sub = NULL; + GtkWidget *add = NULL; + switch(type) { + default: { + sub = ui_gtk_vbox_new(spacing); + add = ui_box_set_margin(sub, margin); + newobj->container = ui_box_container(newobj, sub, type); + newobj->widget = sub; + break; + } + case UI_CONTAINER_HBOX: { + sub = ui_gtk_hbox_new(spacing); + add = ui_box_set_margin(sub, margin); + newobj->container = ui_box_container(newobj, sub, type); + newobj->widget = sub; + break; + } + case UI_CONTAINER_GRID: { + sub = ui_create_grid_widget(columnspacing, rowspacing); + add = ui_box_set_margin(sub, margin); + newobj->container = ui_grid_container(newobj, sub); + newobj->widget = sub; + break; + } + case UI_CONTAINER_NO_SUB: { + break; + } + } + return add; +} /* -------------------- Box Container -------------------- */ @@ -201,6 +239,20 @@ } #endif +UiContainer* ui_frame_container(UiObject *obj, GtkWidget *frame) { + UiContainer *ct = cxCalloc( + obj->ctx->allocator, + 1, + sizeof(UiContainer)); + ct->widget = frame; + ct->add = ui_frame_container_add; + return ct; +} + +void ui_frame_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill) { + FRAME_SET_CHILD(ct->widget, widget); +} + UiContainer* ui_scrolledwindow_container(UiObject *obj, GtkWidget *scrolledwindow) { UiContainer *ct = cxCalloc( obj->ctx->allocator, @@ -318,6 +370,23 @@ return widget; } +UIWIDGET ui_frame_create(UiObject *obj, UiFrameArgs args) { + UiObject* current = uic_current_obj(obj); + UI_APPLY_LAYOUT1(current, args); + + GtkWidget *frame = gtk_frame_new(args.label); + UiObject *newobj = uic_object_new(obj, frame); + GtkWidget *sub = ui_subcontainer_create(args.subcontainer, newobj, args.spacing, args.columnspacing, args.rowspacing, args.margin); + if(sub) { + FRAME_SET_CHILD(frame, sub); + } else { + newobj->widget = frame; + newobj->container = ui_frame_container(obj, frame); + } + + return frame; +} + UIWIDGET ui_scrolledwindow_create(UiObject* obj, UiFrameArgs args) { UiObject* current = uic_current_obj(obj); @@ -329,39 +398,13 @@ current->container->add(current->container, widget, TRUE); UiObject *newobj = uic_object_new(obj, sw); - GtkWidget *sub; - switch(args.subcontainer) { - default: { - sub = ui_gtk_vbox_new(args.spacing); - GtkWidget *widget = ui_box_set_margin(sub, args.margin); - SCROLLEDWINDOW_SET_CHILD(sw, widget); - - newobj->container = ui_box_container(newobj, sub, args.subcontainer); - break; - } - case UI_CONTAINER_HBOX: { - sub = ui_gtk_hbox_new(args.spacing); - GtkWidget *widget = ui_box_set_margin(sub, args.margin); - SCROLLEDWINDOW_SET_CHILD(sw, widget); - - newobj->container = ui_box_container(newobj, sub, args.subcontainer); - break; - } - case UI_CONTAINER_GRID: { - sub = ui_create_grid_widget(args.columnspacing, args.rowspacing); - GtkWidget *widget = ui_box_set_margin(sub, args.margin); - SCROLLEDWINDOW_SET_CHILD(sw, widget); - - newobj->container = ui_grid_container(newobj, sub); - break; - } - case UI_CONTAINER_NO_SUB: { - sub = sw; - newobj->container = ui_scrolledwindow_container(obj, sw); - } + GtkWidget *sub = ui_subcontainer_create(args.subcontainer, newobj, args.spacing, args.columnspacing, args.rowspacing, args.margin); + if(sub) { + SCROLLEDWINDOW_SET_CHILD(sw, sub); + } else { + newobj->widget = sw; + newobj->container = ui_scrolledwindow_container(obj, sw); } - newobj->widget = sub; - uic_obj_add(obj, newobj);