--- a/ui/gtk/container.c Sat Feb 01 22:30:58 2025 +0100 +++ b/ui/gtk/container.c Wed Feb 05 23:03:30 2025 +0100 @@ -957,6 +957,70 @@ +static UIWIDGET splitpane_create(UiObject *obj, UiOrientation orientation, UiSplitPaneArgs args) { + UiObject* current = uic_current_obj(obj); + + GtkWidget *pane0 = create_paned(orientation); + printf("pane0: %p\n", pane0); + + UI_APPLY_LAYOUT1(current, args); + current->container->add(current->container, pane0, TRUE); + + int max = args.max_panes == 0 ? 2 : args.max_panes; + + UiObject *newobj = uic_object_new(obj, pane0); + newobj->container = ui_splitpane_container(obj, pane0, orientation, max); + uic_obj_add(obj, newobj); + + return pane0; +} + +UIWIDGET ui_hsplitpane_create(UiObject *obj, UiSplitPaneArgs args) { + return splitpane_create(obj, UI_HORIZONTAL, args); +} + +UIWIDGET ui_vsplitpane_create(UiObject *obj, UiSplitPaneArgs args) { + return splitpane_create(obj, UI_VERTICAL, args); +} + +UiContainer* ui_splitpane_container(UiObject *obj, GtkWidget *pane, UiOrientation orientation, int max) { + UiSplitPaneContainer *ct = ui_calloc(obj->ctx, 1, sizeof(UiSplitPaneContainer)); + ct->container.widget = pane; + ct->container.add = ui_splitpane_container_add; + ct->current_pane = pane; + ct->orientation = orientation; + ct->max = max; + return (UiContainer*)ct; +} + +void ui_splitpane_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill) { + UiSplitPaneContainer *s = (UiSplitPaneContainer*)ct; + + if(s->nchildren >= s->max) { + fprintf(stderr, "splitpane: maximum number of children reached\n"); + return; + } + + if(s->pos == 0) { + gtk_paned_set_start_child(GTK_PANED(s->current_pane), widget); + printf("pane add: %p\n", s->current_pane); + s->pos++; + s->nchildren++; + } else { + if(s->nchildren+1 == s->max) { + gtk_paned_set_end_child(GTK_PANED(s->current_pane), widget); + } else { + GtkWidget *pane = create_paned(s->orientation); + gtk_paned_set_start_child(GTK_PANED(pane), widget); + gtk_paned_set_end_child(GTK_PANED(s->current_pane), pane); + s->current_pane = pane; + } + + s->pos = 0; + s->nchildren++; + } +} + /* -------------------- ItemList Container -------------------- */ static void remove_item(void *data, void *item) {