implement toggled_by_state arg for the content toggle button (GTK)

Wed, 17 Jun 2026 21:06:50 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 17 Jun 2026 21:06:50 +0200
changeset 1207
833c37fc5475
parent 1206
4637da12bc6c
child 1208
6a1a43a1b526

implement toggled_by_state arg for the content toggle button (GTK)

application/main.c file | annotate | diff | comparison | revisions
ui/gtk/button.c file | annotate | diff | comparison | revisions
--- a/application/main.c	Wed Jun 17 20:54:22 2026 +0200
+++ b/application/main.c	Wed Jun 17 21:06:50 2026 +0200
@@ -731,7 +731,8 @@
                 ui_button(obj, .label = "Disable Group 2", .onclick = action_group2, .onclickdata = "disable");
                 ui_newline(obj);
                 
-                ui_content_togglebutton(obj, .label0 = "Off", .label1 = "On", .tooltip0 = "enable", .tooltip1 = "disable", .istogglebutton = TRUE, .onchange = content_toggled, .varname = "ctntoggle");
+                ui_content_togglebutton(obj, .label0 = "Off", .label1 = "On", .tooltip0 = "enable", .tooltip1 = "disable", .istogglebutton = TRUE, .onchange = content_toggled, .varname = "ctntoggle", .toggled_by_state = 2501);
+                ui_togglebutton(obj, .label = "Toggle", .enable_state = 2501);
                 ui_newline(obj);
                 
                 ui_button(obj, .label = "Groups 1,2", .colspan = 2, .states = UI_STATES(1, 2));
--- a/ui/gtk/button.c	Wed Jun 17 20:54:22 2026 +0200
+++ b/ui/gtk/button.c	Wed Jun 17 21:06:50 2026 +0200
@@ -629,6 +629,14 @@
     free(button);
 }
 
+static void ui_content_togglebutton_enabled_by_state(void *data, int enabled) {
+    UiContentToggleButton *button = data;
+    if(button->toggled != enabled) {
+        button->toggled = enabled;
+        content_toggle_button_changed(button);
+    }
+}
+
 UIWIDGET ui_create_content_togglebutton(UiObject *obj, UiContentToggleArgs *args) {
     UiContentToggleButton *button = malloc(sizeof(UiContentToggleButton));
     memset(button, 0, sizeof(UiContentToggleButton));
@@ -684,6 +692,13 @@
     gtk_widget_set_tooltip_text(widget, tooltip);
     button->widget = widget;
     
+    if(args->toggled_by_state != 0) {
+        CxList *ls = cxArrayListCreate(NULL, sizeof(int), 1);
+        cxListAdd(ls, &args->toggled_by_state);
+        uic_add_state_widget(obj->ctx, button, ui_content_togglebutton_enabled_by_state, ls);
+        cxListFree(ls);
+    }
+    
     g_signal_connect(
             widget,
             "destroy",

mercurial