Mon, 15 Sep 2025 16:08:07 +0200
add position_property splitpane arg (GTK)
| ui/gtk/container.c | file | annotate | diff | comparison | revisions | |
| ui/ui/container.h | file | annotate | diff | comparison | revisions |
--- a/ui/gtk/container.c Mon Sep 15 15:58:18 2025 +0200 +++ b/ui/gtk/container.c Mon Sep 15 16:08:07 2025 +0200 @@ -28,6 +28,7 @@ #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <limits.h> #include "container.h" @@ -37,6 +38,8 @@ #include "../common/context.h" #include "../common/object.h" +#include "../ui/properties.h" + void ui_container_begin_close(UiObject *obj) { UiContainer *ct = uic_get_current_container(obj); @@ -1067,7 +1070,13 @@ return NULL; } - +static void save_pane_pos(GtkWidget *widget, char *property_name) { + int pos = gtk_paned_get_position(GTK_PANED(widget)); + char buf[32]; + snprintf(buf, 32, "%d", pos); + ui_set_property(property_name, buf); + free(property_name); +} static UIWIDGET splitpane_create(UiObject *obj, UiOrientation orientation, UiSplitPaneArgs *args) { UiObject* current = uic_current_obj(obj); @@ -1079,6 +1088,23 @@ int max = args->max_panes == 0 ? 2 : args->max_panes; + if(args->position_property) { + const char *pos_str = ui_get_property(args->position_property); + if(pos_str) { + char *end; + long pos = strtol(pos_str, &end, 10); + if(*end = '\0') { + args->initial_position = (int)pos; + } + } + + g_signal_connect( + pane0, + "destroy", + G_CALLBACK(save_pane_pos), + strdup(args->position_property)); + } + UiObject *newobj = uic_object_new(obj, pane0); newobj->container = ui_splitpane_container(obj, pane0, orientation, max, args->initial_position); uic_obj_add(obj, newobj);