fix button action binding

Wed, 22 Apr 2026 10:07:54 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 22 Apr 2026 10:07:54 +0200
changeset 1101
789b476ff7e3
parent 1100
7773850dc77f
child 1102
c4883a63929b

fix button action binding

make/xcode/toolkit/toolkit/main.m file | annotate | diff | comparison | revisions
ui/cocoa/button.m file | annotate | diff | comparison | revisions
--- a/make/xcode/toolkit/toolkit/main.m	Tue Apr 21 21:09:39 2026 +0200
+++ b/make/xcode/toolkit/toolkit/main.m	Wed Apr 22 10:07:54 2026 +0200
@@ -137,7 +137,9 @@
     return elm;
 }
 
-
+void action_test(UiEvent *event, void *userdata) {
+    printf("action test\n");
+}
 
 void application_startup(UiEvent *event, void *data) {
     UiObject *obj = ui_splitview_window("My Window", TRUE);
@@ -147,6 +149,8 @@
     MyDocument *doc = create_doc();
     ui_attach_document(obj->ctx, doc);
     
+    ui_add_action(obj->ctx, "test", action_test, NULL);
+    
     UiSubList sublist[2];
     sublist[0].header = "iCloud";
     sublist[0].value = doc->sidebar_list;
@@ -171,11 +175,11 @@
             ui_newline(obj);
             
             ui_frame(obj, .label = "Test", .margin_bottom = 10, .hfill = TRUE, .vfill = TRUE, .hexpand = TRUE, .vexpand = TRUE, .subcontainer = UI_CONTAINER_VBOX, .spacing = 10) {
-                ui_button(obj, .label = "Test Button");
-                ui_button(obj, .label = "Test Button");
-                ui_button(obj, .label = "Test Button");
-                ui_button(obj, .label = "Test Button");
-                ui_button(obj, .label = "Test Button");
+                ui_button(obj, .label = "Test Button", .action = "test");
+                ui_button(obj, .label = "Test Button", .action = "test");
+                ui_button(obj, .label = "Test Button", .action = "test");
+                ui_button(obj, .label = "Test Button", .action = "test");
+                ui_button(obj, .label = "Test Button", .action = "test");
             }
         }
     }
--- a/ui/cocoa/button.m	Tue Apr 21 21:09:39 2026 +0200
+++ b/ui/cocoa/button.m	Wed Apr 22 10:07:54 2026 +0200
@@ -47,12 +47,14 @@
         button.image = ui_cocoa_named_icon(args->icon);;
     }
     
-    if(args->onclick) {
+    if(args->onclick || args->action) {
         EventData *event = [[EventData alloc] init:args->onclick userdata:args->onclickdata action:args->action];
         event.obj = obj;
         button.target = event;
         button.action = @selector(handleEvent:);
         objc_setAssociatedObject(button, "eventdata", event, OBJC_ASSOCIATION_RETAIN);
+        
+        ui_cocoa_view_bind_action(obj->ctx, button, args->action);
     }
     
     UiLayout layout = UI_INIT_LAYOUT(args);

mercurial