diff -r b47bda6666ce -r de653b07050b ui/winui/button.cpp --- a/ui/winui/button.cpp Wed Nov 13 22:02:50 2024 +0100 +++ b/ui/winui/button.cpp Thu Nov 14 17:26:16 2024 +0100 @@ -98,6 +98,7 @@ UIElement elm = button; UiWidget* widget = new UiWidget(elm); ui_context_add_widget_destructor(current->ctx, widget); + ui_set_widget_groups(current->ctx, widget, args.groups); // register callback if (args.onclick) { @@ -175,6 +176,24 @@ } } +static void togglebutton_changed(UiObject *obj, bool checked, ui_callback onchange, void *onchangedata, int enable_state) { + if (onchange) { + UiEvent evt; + evt.obj = obj; + evt.window = obj->window; + evt.document = obj->ctx->document; + evt.eventdata = nullptr; + evt.intval = checked; + onchange(&evt, onchangedata); + } + if (enable_state > 0) { + if (checked) { + ui_set_group(obj->ctx, enable_state); + } else { + ui_unset_group(obj->ctx, enable_state); + } + } +} static UIWIDGET create_togglebutton(UiObject *obj, ToggleButton button, UiToggleArgs args) { UiObject* current = uic_current_obj(obj); @@ -187,6 +206,7 @@ UIElement elm = button; UiWidget* widget = new UiWidget(elm); ui_context_add_widget_destructor(current->ctx, widget); + ui_set_widget_groups(current->ctx, widget, args.groups); // bind variable UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_INTEGER); @@ -201,6 +221,15 @@ togglebutton_register_unchecked_observers(button, obj, var); } + if (args.enable_group > 0 || args.onchange) { + button.Checked([obj, args](IInspectable const& sender, RoutedEventArgs) { + togglebutton_changed(obj, true, args.onchange, args.onchangedata, args.enable_group); + }); + button.Unchecked([obj, args](IInspectable const& sender, RoutedEventArgs) { + togglebutton_changed(obj, false, args.onchange, args.onchangedata, args.enable_group); + }); + } + // add button to current container UI_APPLY_LAYOUT1(current, args); @@ -234,6 +263,7 @@ UIElement elm = button; UiWidget* widget = new UiWidget(elm); ui_context_add_widget_destructor(current->ctx, widget); + ui_set_widget_groups(current->ctx, widget, args.groups); // bind variable UiVar* var = nullptr; @@ -274,6 +304,7 @@ UIElement elm = button; UiWidget* widget = new UiWidget(elm); ui_context_add_widget_destructor(current->ctx, widget); + ui_set_widget_groups(current->ctx, widget, args.groups); UiVar* var = nullptr; if (args.value) {