# HG changeset patch # User Olaf Wintermann # Date 1727614874 -7200 # Node ID b679cc6059abb95d40bce38a29263507f0fd4722 # Parent 3f2b3d15668bdcf1b4cfacb7d53b45368f18a4d8 add option to name widgets and add css classes (GTK) diff -r 3f2b3d15668b -r b679cc6059ab ui/gtk/button.c --- a/ui/gtk/button.c Sun Sep 29 13:33:34 2024 +0200 +++ b/ui/gtk/button.c Sun Sep 29 15:01:14 2024 +0200 @@ -90,6 +90,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); + ui_set_name_and_style(button, args.name, args.style_class); UI_APPLY_LAYOUT1(current, args); current->container->add(current->container, button, FALSE); return button; @@ -230,6 +231,7 @@ UiObject* current = uic_current_obj(obj); ui_setup_togglebutton(current, widget, args.label, args.icon, args.varname, args.value, args.onchange, args.onchangedata); + ui_set_name_and_style(widget, args.name, args.style_class); UI_APPLY_LAYOUT1(current, args); current->container->add(current->container, widget, FALSE); @@ -340,6 +342,7 @@ } GtkWidget *rbutton = RADIOBUTTON_NEW(rg, args.label); + ui_set_name_and_style(rbutton, args.name, args.style_class); if(rgroup) { #if GTK_MAJOR_VERSION >= 4 if(rg) { diff -r 3f2b3d15668b -r b679cc6059ab ui/gtk/container.c --- a/ui/gtk/container.c Sun Sep 29 13:33:34 2024 +0200 +++ b/ui/gtk/container.c Sun Sep 29 15:01:14 2024 +0200 @@ -266,6 +266,7 @@ UI_APPLY_LAYOUT1(current, args); GtkWidget *box = type == UI_CONTAINER_VBOX ? ui_gtk_vbox_new(args.spacing) : ui_gtk_hbox_new(args.spacing); + ui_set_name_and_style(box, args.name, args.style_class); GtkWidget *widget = args.margin > 0 ? box_set_margin(box, args.margin) : box; ct->add(ct, widget, TRUE); @@ -303,6 +304,7 @@ GtkWidget *widget; GtkWidget *grid = create_grid(args.columnspacing, args.rowspacing); + ui_set_name_and_style(grid, args.name, args.style_class); widget = box_set_margin(grid, args.margin); current->container->add(current->container, widget, TRUE); @@ -319,6 +321,7 @@ UI_APPLY_LAYOUT1(current, args); GtkWidget *sw = SCROLLEDWINDOW_NEW(); + ui_set_name_and_style(sw, args.name, args.style_class); UiObject *newobj = uic_object_new(obj, sw); newobj->container = ui_scrolledwindow_container(obj, sw); uic_obj_add(obj, newobj); diff -r 3f2b3d15668b -r b679cc6059ab ui/gtk/entry.c --- a/ui/gtk/entry.c Sun Sep 29 13:33:34 2024 +0200 +++ b/ui/gtk/entry.c Sun Sep 29 15:01:14 2024 +0200 @@ -70,6 +70,7 @@ } #endif GtkWidget *spin = gtk_spin_button_new_with_range(min, max, args.step); + ui_set_name_and_style(spin, args.name, args.style_class); gtk_spin_button_set_digits(GTK_SPIN_BUTTON(spin), args.digits); UiObserver **obs = NULL; if(var) { diff -r 3f2b3d15668b -r b679cc6059ab ui/gtk/text.c --- a/ui/gtk/text.c Sun Sep 29 13:33:34 2024 +0200 +++ b/ui/gtk/text.c Sun Sep 29 15:01:14 2024 +0200 @@ -542,6 +542,7 @@ static UIWIDGET create_textfield(UiObject *obj, UiBool frameless, UiBool password, UiTextFieldArgs args) { GtkWidget *textfield = gtk_entry_new(); + ui_set_name_and_style(textfield, args.name, args.style_class); UiObject* current = uic_current_obj(obj); UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_STRING); diff -r 3f2b3d15668b -r b679cc6059ab ui/gtk/toolkit.c --- a/ui/gtk/toolkit.c Sun Sep 29 13:33:34 2024 +0200 +++ b/ui/gtk/toolkit.c Sun Sep 29 15:01:14 2024 +0200 @@ -383,4 +383,21 @@ -#endif \ No newline at end of file +#endif + +void ui_set_name_and_style(GtkWidget *widget, const char *name, const char *style_classes) { + if(name) { + gtk_widget_set_name(widget, name); + } + if(style_classes) { + cxstring *cls = NULL; + size_t numClasses = cx_strsplit_a(cxDefaultAllocator, cx_str(style_classes), CX_STR(" "), 128, &cls); + for(int i=0;i