ui/winui/button.cpp

Sun, 01 Oct 2023 16:53:02 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 01 Oct 2023 16:53:02 +0200
branch
newapi
changeset 190
70fd1b24e395
parent 189
4daddc326877
child 191
6113ed66d258
permissions
-rw-r--r--

implement new api style for box and grid containers (WinUI3)

184
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2023 Olaf Wintermann. All rights reserved.
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include "button.h"
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 #include "util.h"
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include "container.h"
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #include "../common/object.h"
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 #include "../common/context.h"
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 using namespace winrt;
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 using namespace Microsoft::UI::Xaml;
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 using namespace Microsoft::UI::Xaml::Controls;
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 using namespace Windows::UI::Xaml::Interop;
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 using namespace winrt::Windows::Foundation;
187
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
43 using namespace winrt::Microsoft::UI::Xaml::Controls::Primitives;
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
44
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
45
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
46
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
47 static void set_button_label(ButtonBase button, const char* label, const char* stockid) {
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
48 if (label) {
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
49 wchar_t* wlabel = str2wstr(label, nullptr);
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
50 button.Content(box_value(wlabel));
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
51 free(wlabel);
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
52 }
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
53 // TODO: stockid
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
54 }
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
55
184
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56
186
5db4979bf482 implement new api style for ui_button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 184
diff changeset
57 UIWIDGET ui_button_create(UiObject* obj, UiButtonArgs args) {
184
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 UiObject* current = uic_current_obj(obj);
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 // create button with label
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 Button button = Button();
187
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
62 set_button_label(button, args.label, args.stockid);
184
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 // create toolkit wrapper object and register destructor
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 UIElement elm = button;
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 UiWidget* widget = new UiWidget(elm);
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 ui_context_add_widget_destructor(current->ctx, widget);
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 // register callback
186
5db4979bf482 implement new api style for ui_button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 184
diff changeset
70 if (args.onclick) {
184
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 widget->obj = obj;
186
5db4979bf482 implement new api style for ui_button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 184
diff changeset
72 widget->event_func = (ui_eventfunc)args.onclick;
5db4979bf482 implement new api style for ui_button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 184
diff changeset
73 widget->event_data = args.onclickdata;
184
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 button.Click([widget](IInspectable const& sender, RoutedEventArgs) {
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 ui_callback cb = (ui_callback)widget->event_func;
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 UiEvent evt;
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 evt.obj = (UiObject*)widget->obj;
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 evt.window = evt.obj->window;
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 evt.document = evt.obj->ctx->document;
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 evt.eventdata = nullptr;
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 evt.intval = 0;
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 cb(&evt, widget->event_data);
186
5db4979bf482 implement new api style for ui_button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 184
diff changeset
84 });
184
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 }
186
5db4979bf482 implement new api style for ui_button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 184
diff changeset
86
184
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 // add button to current container
186
5db4979bf482 implement new api style for ui_button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 184
diff changeset
88 UI_APPLY_LAYOUT1(current, args);
187
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
89
184
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 current->container->Add(button, false);
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 return widget;
8c9b4b28aaa9 implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 }
186
5db4979bf482 implement new api style for ui_button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 184
diff changeset
94
189
4daddc326877 add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
95
4daddc326877 add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
96 static void togglebutton_register_checked_observers(ToggleButton button, UiObject* obj, UiVar* var) {
4daddc326877 add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
97 button.Checked([button, obj, var](IInspectable const& sender, RoutedEventArgs) {
4daddc326877 add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
98 UiInteger* i = (UiInteger*)var->value;
4daddc326877 add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
99 UiEvent evt = ui_create_int_event(obj, i->get(i));
4daddc326877 add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
100 ui_notify_evt(i->observers, &evt);
4daddc326877 add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
101 });
4daddc326877 add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
102 }
4daddc326877 add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
103
4daddc326877 add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
104 static void togglebutton_register_unchecked_observers(ToggleButton button, UiObject* obj, UiVar* var) {
4daddc326877 add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
105 button.Unchecked([button, obj, var](IInspectable const& sender, RoutedEventArgs) {
4daddc326877 add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
106 UiInteger* i = (UiInteger*)var->value;
4daddc326877 add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
107 UiEvent evt = ui_create_int_event(obj, i->get(i));
4daddc326877 add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
108 ui_notify_evt(i->observers, &evt);
4daddc326877 add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
109 });
4daddc326877 add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
110 }
4daddc326877 add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
111
4daddc326877 add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
112 static void togglebutton_register_callback(ToggleButton button, UiObject *obj, UiToggleArgs& args) {
4daddc326877 add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
113 ui_callback callback = args.onchange;
4daddc326877 add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
114 void* cbdata = args.onchangedata;
4daddc326877 add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
115 if (callback) {
4daddc326877 add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
116 button.Checked([button, obj, callback, cbdata](IInspectable const& sender, RoutedEventArgs) {
4daddc326877 add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
117 UiEvent evt = ui_create_int_event(obj, true);
4daddc326877 add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
118 callback(&evt, cbdata);
4daddc326877 add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
119 });
4daddc326877 add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
120 button.Unchecked([button, obj, callback, cbdata](IInspectable const& sender, RoutedEventArgs) {
4daddc326877 add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
121 UiEvent evt = ui_create_int_event(obj, false);
4daddc326877 add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
122 callback(&evt, cbdata);
4daddc326877 add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
123 });
4daddc326877 add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
124 }
4daddc326877 add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
125 }
4daddc326877 add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
126
187
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
127 static UIWIDGET create_togglebutton(UiObject *obj, ToggleButton button, UiToggleArgs args) {
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
128 UiObject* current = uic_current_obj(obj);
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
129
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
130 // set label
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
131 set_button_label(button, args.label, args.stockid);
189
4daddc326877 add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
132 togglebutton_register_callback(button, obj, args);
187
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
133
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
134 // create toolkit wrapper object and register destructor
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
135 UIElement elm = button;
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
136 UiWidget* widget = new UiWidget(elm);
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
137 ui_context_add_widget_destructor(current->ctx, widget);
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
138
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
139 // bind variable
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
140 UiVar* var = nullptr;
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
141 if (args.value) {
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
142 var = uic_create_value_var(current->ctx, args.value);
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
143 }
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
144 else if (args.varname) {
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
145 var = uic_create_var(obj->ctx, args.varname, UI_VAR_INTEGER);
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
146 }
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
147 if (var) {
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
148 UiInteger* value = (UiInteger*)var->value;
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
149 value->obj = widget;
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
150 value->get = ui_toggle_button_get;
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
151 value->set = ui_toggle_button_set;
189
4daddc326877 add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
152
4daddc326877 add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
153 // listener for notifying observers
4daddc326877 add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
154 togglebutton_register_checked_observers(button, obj, var);
4daddc326877 add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
155 togglebutton_register_unchecked_observers(button, obj, var);
187
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
156 }
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
157
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
158 // add button to current container
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
159 UI_APPLY_LAYOUT1(current, args);
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
160
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
161 current->container->Add(button, false);
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
162
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
163 return widget;
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
164 }
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
165
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
166 UIWIDGET ui_togglebutton_create(UiObject* obj, UiToggleArgs args) {
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
167 ToggleButton button = ToggleButton();
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
168 return create_togglebutton(obj, button, args);
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
169 }
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
170
186
5db4979bf482 implement new api style for ui_button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 184
diff changeset
171 UIWIDGET ui_checkbox_create(UiObject* obj, UiToggleArgs args) {
187
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
172 CheckBox button = CheckBox();
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
173 return create_togglebutton(obj, button, args);
186
5db4979bf482 implement new api style for ui_button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 184
diff changeset
174 }
5db4979bf482 implement new api style for ui_button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 184
diff changeset
175
188
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
176 UIWIDGET ui_radiobutton_create(UiObject* obj, UiToggleArgs args) {
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
177 RadioButton button = RadioButton();
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
178
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
179 UiObject* current = uic_current_obj(obj);
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
180
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
181 // set label
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
182 set_button_label(button, args.label, args.stockid);
189
4daddc326877 add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
183 togglebutton_register_callback(button, obj, args);
188
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
184
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
185 // create toolkit wrapper object and register destructor
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
186 UIElement elm = button;
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
187 UiWidget* widget = new UiWidget(elm);
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
188 ui_context_add_widget_destructor(current->ctx, widget);
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
189
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
190 UiVar* var = nullptr;
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
191 if (args.value) {
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
192 var = uic_create_value_var(current->ctx, args.value);
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
193 }
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
194 else if (args.varname) {
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
195 var = uic_create_var(obj->ctx, args.varname, UI_VAR_INTEGER);
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
196 }
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
197
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
198 // bind radio button to the value
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
199 if (var) {
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
200 UiInteger* value = (UiInteger*)var->value;
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
201
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
202 // store a list of radio buttons in the value
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
203 CxList* radioButtons = (CxList*) (value->obj ? value->obj : cxLinkedListCreate(current->ctx->allocator, NULL, CX_STORE_POINTERS));
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
204 // get or create the group name
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
205 static int groupCount = 0;
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
206 winrt::hstring groupName;
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
207 if (radioButtons->size == 0) {
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
208 groupName = winrt::to_hstring(groupCount++);
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
209 } else {
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
210 UiWidget* firstButtonWidget = (UiWidget*)cxListAt(radioButtons, 0);
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
211 RadioButton firstRadioButton = firstButtonWidget->uielement.as<RadioButton>();
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
212 groupName = firstRadioButton.GroupName();
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
213 }
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
214
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
215 // set the group name for the new radiobutton
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
216 cxListAdd(radioButtons, widget);
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
217 button.GroupName(groupName);
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
218
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
219 value->obj = radioButtons;
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
220 value->get = ui_radio_button_get;
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
221 value->set = ui_radio_button_set;
189
4daddc326877 add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
222
4daddc326877 add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
223 // listener for notifying observers (only checked, not unchecked)
4daddc326877 add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 188
diff changeset
224 togglebutton_register_checked_observers(button, obj, var);
188
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
225 }
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
226
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
227 // add button to current container
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
228 UI_APPLY_LAYOUT1(current, args);
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
229
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
230 current->container->Add(button, false);
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
231
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
232 return widget;
186
5db4979bf482 implement new api style for ui_button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 184
diff changeset
233 }
187
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
234
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
235
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
236 int64_t ui_toggle_button_get(UiInteger* integer) {
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
237 UiWidget* widget = (UiWidget*)integer->obj;
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
238 ToggleButton toggleButton = widget->uielement.as<ToggleButton>();
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
239 int val = toggleButton.IsChecked().GetBoolean();
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
240 integer->value = val;
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
241 return val;
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
242 }
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
243
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
244 void ui_toggle_button_set(UiInteger* integer, int64_t value) {
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
245 UiWidget* widget = (UiWidget*)integer->obj;
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
246 ToggleButton toggleButton = widget->uielement.as<ToggleButton>();
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
247 toggleButton.IsChecked((bool)value);
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
248 integer->value = value;
24ce2c326d85 implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 186
diff changeset
249 }
188
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
250
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
251 extern "C" int64_t ui_radio_button_get(UiInteger * integer) {
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
252 CxList* list = (CxList*)integer->obj;
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
253 CxIterator i = cxListIterator(list);
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
254 int selection = -1;
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
255 cx_foreach(UiWidget*, widget, i) {
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
256 ToggleButton button = widget->uielement.as<ToggleButton>();
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
257 if (button.IsChecked().GetBoolean()) {
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
258 selection = i.index;
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
259 break;
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
260 }
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
261 }
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
262 integer->value = selection;
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
263 return selection;
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
264 }
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
265
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
266 extern "C" void ui_radio_button_set(UiInteger * integer, int64_t value) {
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
267 CxList* list = (CxList*)integer->obj;
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
268 UiWidget* widget = (UiWidget*)cxListAt(list, value);
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
269 if (widget) {
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
270 ToggleButton button = widget->uielement.as<ToggleButton>();
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
271 button.IsChecked(true);
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
272 integer->value = value;
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
273 }
fbbae6738252 implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 187
diff changeset
274 }

mercurial