add style for dialog window default button (GTK) newapi

Wed, 23 Oct 2024 15:01:18 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 23 Oct 2024 15:01:18 +0200
branch
newapi
changeset 345
d2ccc543f432
parent 344
870dd3d41d83
child 346
a20213cb3d2f

add style for dialog window default button (GTK)

application/main.c file | annotate | diff | comparison | revisions
ui/gtk/window.c file | annotate | diff | comparison | revisions
--- a/application/main.c	Wed Oct 23 14:52:18 2024 +0200
+++ b/application/main.c	Wed Oct 23 15:01:18 2024 +0200
@@ -85,7 +85,7 @@
 
 void action_toolbar_dialog(UiEvent *event, void *userdata) {
     
-    UiObject *dialog = ui_dialog_window(event->obj, .title  = "Dialog Window", .lbutton1 = "Cancel 1", .lbutton2 = "Btn2", .rbutton3 = "Btn3", .rbutton4 = "Login 4", .onclick = action_dialog_button, .show_closebutton = UI_OFF);
+    UiObject *dialog = ui_dialog_window(event->obj, .title  = "Dialog Window", .lbutton1 = "Cancel 1", .lbutton2 = "Btn2", .rbutton3 = "Btn3", .rbutton4 = "Login 4", .onclick = action_dialog_button, .default_button = 4, .show_closebutton = UI_OFF);
     
     ui_vbox(dialog, .margin = 10, .spacing = 10) {
         ui_label(dialog, .label = "Enter password:");
--- a/ui/gtk/window.c	Wed Oct 23 14:52:18 2024 +0200
+++ b/ui/gtk/window.c	Wed Oct 23 15:01:18 2024 +0200
@@ -674,19 +674,31 @@
             if(args.lbutton1) {
                 GtkWidget *button = ui_create_button(obj, args.lbutton1, NULL, args.onclick, args.onclickdata, 1);
                 gtk_header_bar_pack_start(GTK_HEADER_BAR(headerbar), button);
+                if(args.default_button == 1) {
+                    WIDGET_ADD_CSS_CLASS(button, "suggested-action");
+                }
             }
             if(args.lbutton2) {
                 GtkWidget *button = ui_create_button(obj, args.lbutton2, NULL, args.onclick, args.onclickdata, 2);
                 gtk_header_bar_pack_start(GTK_HEADER_BAR(headerbar), button);
+                if(args.default_button == 2) {
+                    WIDGET_ADD_CSS_CLASS(button, "suggested-action");
+                }
             }
             
             if(args.rbutton4) {
                 GtkWidget *button = ui_create_button(obj, args.rbutton4, NULL, args.onclick, args.onclickdata, 4);
                 gtk_header_bar_pack_end(GTK_HEADER_BAR(headerbar), button);
+                if(args.default_button == 4) {
+                    WIDGET_ADD_CSS_CLASS(button, "suggested-action");
+                }
             }
             if(args.rbutton3) {
                 GtkWidget *button = ui_create_button(obj, args.rbutton3, NULL, args.onclick, args.onclickdata, 3);
                 gtk_header_bar_pack_end(GTK_HEADER_BAR(headerbar), button);
+                if(args.default_button == 3) {
+                    WIDGET_ADD_CSS_CLASS(button, "suggested-action");
+                }
             }
             return obj;
         }

mercurial