Fri, 25 Oct 2024 15:37:02 +0200
fix ui_scrolledwindow (GTK)
application/main.c | file | annotate | diff | comparison | revisions | |
ui/common/context.c | file | annotate | diff | comparison | revisions | |
ui/gtk/button.c | file | annotate | diff | comparison | revisions | |
ui/gtk/button.h | file | annotate | diff | comparison | revisions | |
ui/gtk/container.c | file | annotate | diff | comparison | revisions | |
ui/gtk/headerbar.c | file | annotate | diff | comparison | revisions | |
ui/gtk/list.c | file | annotate | diff | comparison | revisions | |
ui/gtk/toolkit.c | file | annotate | diff | comparison | revisions | |
ui/gtk/window.c | file | annotate | diff | comparison | revisions |
--- a/application/main.c Wed Oct 23 17:16:51 2024 +0200 +++ b/application/main.c Fri Oct 25 15:37:02 2024 +0200 @@ -306,6 +306,18 @@ ui_button(obj, .label = "Test Button", .icon = "application-x-generic", .onclick = action_button); ui_imageviewer(obj, .varname = "image", .style_class = "imageviewer"); } + + ui_tab(obj, "Tab 6") { + ui_scrolledwindow(obj, .style_class = "ui_test", .fill = UI_ON) { + ui_vbox(obj, .spacing = 10) { + for(int i=0;i<100;i++) { + char labelstr[32]; + snprintf(labelstr, 32, "button %d", i); + ui_button(obj, .label = labelstr); + } + } + } + } } /*
--- a/ui/common/context.c Wed Oct 23 17:16:51 2024 +0200 +++ b/ui/common/context.c Fri Oct 25 15:37:02 2024 +0200 @@ -209,7 +209,7 @@ UiVar* uic_create_value_var(UiContext* ctx, void* value) { UiVar *var = (UiVar*)ui_malloc(ctx, sizeof(UiVar)); var->from = NULL; - var->from_ctx = NULL; + var->from_ctx = ctx; var->value = value; var->type = UI_VAR_SPECIAL; return var; @@ -563,7 +563,7 @@ } void ui_free(UiContext *ctx, void *ptr) { - if(ctx) { + if(ctx && ptr) { cxFree(ctx->allocator, ptr); } }
--- a/ui/gtk/button.c Wed Oct 23 17:16:51 2024 +0200 +++ b/ui/gtk/button.c Fri Oct 25 15:37:02 2024 +0200 @@ -60,7 +60,8 @@ const char *icon, ui_callback onclick, void *userdata, - int event_value) + int event_value, + bool activate_event) { GtkWidget *button = gtk_button_new_with_label(label); ui_button_set_icon_name(button, icon); @@ -83,6 +84,13 @@ "destroy", G_CALLBACK(ui_destroy_userdata), event); + if(activate_event) { + g_signal_connect( + button, + "activate", + G_CALLBACK(ui_button_clicked), + event); + } } return button; @@ -90,7 +98,7 @@ UIWIDGET ui_button_create(UiObject *obj, UiButtonArgs args) { UiObject* current = uic_current_obj(obj); - GtkWidget *button = ui_create_button(obj, args.label, args.icon, args.onclick, args.onclickdata, 0); + GtkWidget *button = ui_create_button(obj, args.label, args.icon, args.onclick, args.onclickdata, 0, FALSE); ui_set_name_and_style(button, args.name, args.style_class); ui_set_widget_groups(obj->ctx, button, args.groups); UI_APPLY_LAYOUT1(current, args);
--- a/ui/gtk/button.h Wed Oct 23 17:16:51 2024 +0200 +++ b/ui/gtk/button.h Fri Oct 25 15:37:02 2024 +0200 @@ -47,7 +47,8 @@ const char *icon, ui_callback onclick, void *userdata, - int event_value); + int event_value, + bool activate_event); void ui_setup_togglebutton( UiObject *obj,
--- a/ui/gtk/container.c Wed Oct 23 17:16:51 2024 +0200 +++ b/ui/gtk/container.c Fri Oct 25 15:37:02 2024 +0200 @@ -325,6 +325,9 @@ GtkWidget *sw = SCROLLEDWINDOW_NEW(); ui_set_name_and_style(sw, args.name, args.style_class); + GtkWidget *widget = ui_box_set_margin(sw, args.margin); + current->container->add(current->container, widget, TRUE); + UiObject *newobj = uic_object_new(obj, sw); newobj->container = ui_scrolledwindow_container(obj, sw); uic_obj_add(obj, newobj);
--- a/ui/gtk/headerbar.c Wed Oct 23 17:16:51 2024 +0200 +++ b/ui/gtk/headerbar.c Fri Oct 25 15:37:02 2024 +0200 @@ -114,7 +114,7 @@ UiObject *obj, enum UiToolbarPos pos) { - GtkWidget *button = ui_create_button(obj, item->args.label, item->args.icon, item->args.onclick, item->args.onclickdata, 0); + GtkWidget *button = ui_create_button(obj, item->args.label, item->args.icon, item->args.onclick, item->args.onclickdata, 0, FALSE); WIDGET_ADD_CSS_CLASS(button, "flat"); headerbar_add(headerbar, box, button, pos); }
--- a/ui/gtk/list.c Wed Oct 23 17:16:51 2024 +0200 +++ b/ui/gtk/list.c Fri Oct 25 15:37:02 2024 +0200 @@ -370,7 +370,9 @@ GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(view)); - gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE); + if(args.multiselection) { + gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE); + } // add widget to the current container GtkWidget *scroll_area = SCROLLEDWINDOW_NEW();
--- a/ui/gtk/toolkit.c Wed Oct 23 17:16:51 2024 +0200 +++ b/ui/gtk/toolkit.c Fri Oct 25 15:37:02 2024 +0200 @@ -296,7 +296,7 @@ uic_unbind_var(var); if(var->type == UI_VAR_SPECIAL) { - free(var); + ui_free(var->from_ctx, var); } else { ui_free(var->from_ctx, var); // TODO: free or unbound
--- a/ui/gtk/window.c Wed Oct 23 17:16:51 2024 +0200 +++ b/ui/gtk/window.c Fri Oct 25 15:37:02 2024 +0200 @@ -610,8 +610,10 @@ #if GTK_CHECK_VERSION(4, 0, 0) #define HEADERBAR_SHOW_CLOSEBUTTON(headerbar, set) gtk_header_bar_set_show_title_buttons(GTK_HEADER_BAR(headerbar), set) +#define DEFAULT_BUTTON(window, button) gtk_window_set_default_widget(GTK_WINDOW(window), button) #else #define HEADERBAR_SHOW_CLOSEBUTTON(headerbar, set) gtk_header_bar_set_show_close_button(GTK_HEADER_BAR(headerbar), set) +#define DEFAULT_BUTTON(window, button) gtk_window_set_default(GTK_WINDOW(window), button) #endif @@ -672,32 +674,36 @@ } if(args.lbutton1) { - GtkWidget *button = ui_create_button(obj, args.lbutton1, NULL, args.onclick, args.onclickdata, 1); + GtkWidget *button = ui_create_button(obj, args.lbutton1, NULL, args.onclick, args.onclickdata, 1, args.default_button == 1); gtk_header_bar_pack_start(GTK_HEADER_BAR(headerbar), button); if(args.default_button == 1) { WIDGET_ADD_CSS_CLASS(button, "suggested-action"); + DEFAULT_BUTTON(dialog, button); } } if(args.lbutton2) { - GtkWidget *button = ui_create_button(obj, args.lbutton2, NULL, args.onclick, args.onclickdata, 2); + GtkWidget *button = ui_create_button(obj, args.lbutton2, NULL, args.onclick, args.onclickdata, 2, args.default_button == 2); gtk_header_bar_pack_start(GTK_HEADER_BAR(headerbar), button); if(args.default_button == 2) { WIDGET_ADD_CSS_CLASS(button, "suggested-action"); + DEFAULT_BUTTON(dialog, button); } } if(args.rbutton4) { - GtkWidget *button = ui_create_button(obj, args.rbutton4, NULL, args.onclick, args.onclickdata, 4); + GtkWidget *button = ui_create_button(obj, args.rbutton4, NULL, args.onclick, args.onclickdata, 4, args.default_button == 4); gtk_header_bar_pack_end(GTK_HEADER_BAR(headerbar), button); if(args.default_button == 4) { WIDGET_ADD_CSS_CLASS(button, "suggested-action"); + DEFAULT_BUTTON(dialog, button); } } if(args.rbutton3) { - GtkWidget *button = ui_create_button(obj, args.rbutton3, NULL, args.onclick, args.onclickdata, 3); + GtkWidget *button = ui_create_button(obj, args.rbutton3, NULL, args.onclick, args.onclickdata, 3, args.default_button == 3); gtk_header_bar_pack_end(GTK_HEADER_BAR(headerbar), button); if(args.default_button == 3) { WIDGET_ADD_CSS_CLASS(button, "suggested-action"); + DEFAULT_BUTTON(dialog, button); } } WINDOW_SET_CONTENT(obj->widget, content_vbox); @@ -714,23 +720,39 @@ gtk_grid_set_column_homogeneous(GTK_GRID(grid), TRUE); if(args.lbutton1) { - GtkWidget *button = ui_create_button(obj, args.lbutton1, NULL, args.onclick, args.onclickdata, 1); + GtkWidget *button = ui_create_button(obj, args.lbutton1, NULL, args.onclick, args.onclickdata, 1, args.default_button == 1); gtk_grid_attach(GTK_GRID(grid), button, 0, 0, 1, 1); + if(args.default_button == 1) { + WIDGET_ADD_CSS_CLASS(button, "suggested-action"); + DEFAULT_BUTTON(dialog, button); + } } if(args.lbutton2) { - GtkWidget *button = ui_create_button(obj, args.lbutton2, NULL, args.onclick, args.onclickdata, 2); + GtkWidget *button = ui_create_button(obj, args.lbutton2, NULL, args.onclick, args.onclickdata, 2, args.default_button == 2); gtk_grid_attach(GTK_GRID(grid), button, 1, 0, 1, 1); + if(args.default_button == 2) { + WIDGET_ADD_CSS_CLASS(button, "suggested-action"); + DEFAULT_BUTTON(dialog, button); + } } GtkWidget *space = gtk_label_new(NULL); gtk_widget_set_hexpand(space, TRUE); gtk_grid_attach(GTK_GRID(grid), space, 2, 0, 1, 1); if(args.rbutton3) { - GtkWidget *button = ui_create_button(obj, args.rbutton3, NULL, args.onclick, args.onclickdata, 3); + GtkWidget *button = ui_create_button(obj, args.rbutton3, NULL, args.onclick, args.onclickdata, 3, args.default_button == 3); gtk_grid_attach(GTK_GRID(grid), button, 3, 0, 1, 1); + if(args.default_button == 3) { + WIDGET_ADD_CSS_CLASS(button, "suggested-action"); + DEFAULT_BUTTON(dialog, button); + } } - if(args.rbutton3) { - GtkWidget *button = ui_create_button(obj, args.rbutton4, NULL, args.onclick, args.onclickdata, 4); + if(args.rbutton4) { + GtkWidget *button = ui_create_button(obj, args.rbutton4, NULL, args.onclick, args.onclickdata, 4, args.default_button == 4); gtk_grid_attach(GTK_GRID(grid), button, 4, 0, 1, 1); + if(args.default_button == 4) { + WIDGET_ADD_CSS_CLASS(button, "suggested-action"); + DEFAULT_BUTTON(dialog, button); + } } BOX_ADD_EXPAND(vbox, content_vbox);