Sun, 17 Nov 2024 15:21:50 +0100
add public function for getting the UiContext UCX mempool
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 | |
205
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
196
diff
changeset
|
29 | #include "pch.h" |
184
8c9b4b28aaa9
implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | |
8c9b4b28aaa9
implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
31 | #include "button.h" |
8c9b4b28aaa9
implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
32 | |
8c9b4b28aaa9
implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
33 | #include "util.h" |
8c9b4b28aaa9
implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | #include "container.h" |
213
7e39db525fd9
add icons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
206
diff
changeset
|
35 | #include "icons.h" |
184
8c9b4b28aaa9
implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | |
8c9b4b28aaa9
implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | #include "../common/object.h" |
8c9b4b28aaa9
implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | #include "../common/context.h" |
8c9b4b28aaa9
implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | |
8c9b4b28aaa9
implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | using namespace winrt; |
8c9b4b28aaa9
implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | using namespace Microsoft::UI::Xaml; |
8c9b4b28aaa9
implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | using namespace Microsoft::UI::Xaml::Controls; |
8c9b4b28aaa9
implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | using namespace Windows::UI::Xaml::Interop; |
8c9b4b28aaa9
implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | using namespace winrt::Windows::Foundation; |
187
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
45 | using namespace winrt::Microsoft::UI::Xaml::Controls::Primitives; |
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 | |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
48 | |
379
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
49 | void ui_set_button_label(ButtonBase button, const char* label, const char* stockid, const char *icon, UiLabelType type) { |
230
4f5b32a2a60f
add icon parameter for buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
50 | // TODO: stockid |
4f5b32a2a60f
add icon parameter for buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
51 | |
4f5b32a2a60f
add icon parameter for buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
52 | if (type == UI_LABEL_ICON) { |
4f5b32a2a60f
add icon parameter for buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
53 | label = NULL; |
4f5b32a2a60f
add icon parameter for buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
54 | } |
4f5b32a2a60f
add icon parameter for buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
55 | else if (type == UI_LABEL_TEXT) { |
4f5b32a2a60f
add icon parameter for buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
56 | icon = NULL; |
4f5b32a2a60f
add icon parameter for buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
57 | } |
4f5b32a2a60f
add icon parameter for buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
58 | |
374
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
59 | IconElement icon_elm = { nullptr }; |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
60 | if (icon) { |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
61 | icon_elm = ui_get_icon(icon); |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
62 | } |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
63 | |
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
64 | if (label && icon_elm) { |
230
4f5b32a2a60f
add icon parameter for buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
65 | StackPanel panel = StackPanel(); |
4f5b32a2a60f
add icon parameter for buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
66 | panel.Orientation(Orientation::Horizontal); |
4f5b32a2a60f
add icon parameter for buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
67 | panel.Spacing(5); |
4f5b32a2a60f
add icon parameter for buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
68 | |
374
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
69 | panel.Children().Append(icon_elm); |
230
4f5b32a2a60f
add icon parameter for buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
70 | |
4f5b32a2a60f
add icon parameter for buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
71 | wchar_t* wlabel = str2wstr(label, nullptr); |
4f5b32a2a60f
add icon parameter for buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
72 | TextBlock label = TextBlock(); |
4f5b32a2a60f
add icon parameter for buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
73 | label.Text(wlabel); |
4f5b32a2a60f
add icon parameter for buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
74 | panel.Children().Append(label); |
4f5b32a2a60f
add icon parameter for buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
75 | free(wlabel); |
4f5b32a2a60f
add icon parameter for buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
76 | |
4f5b32a2a60f
add icon parameter for buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
77 | button.Content(panel); |
4f5b32a2a60f
add icon parameter for buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
78 | } |
4f5b32a2a60f
add icon parameter for buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
79 | else if (label) { |
187
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
80 | wchar_t* wlabel = str2wstr(label, nullptr); |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
81 | button.Content(box_value(wlabel)); |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
82 | free(wlabel); |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
83 | } |
374
eae5d6623fd3
add textarea (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
373
diff
changeset
|
84 | else if (icon_elm) { |
230
4f5b32a2a60f
add icon parameter for buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
85 | button.Content(ui_get_icon(icon)); |
4f5b32a2a60f
add icon parameter for buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
213
diff
changeset
|
86 | } |
187
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
87 | } |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
88 | |
184
8c9b4b28aaa9
implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
89 | |
186
5db4979bf482
implement new api style for ui_button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
184
diff
changeset
|
90 | UIWIDGET ui_button_create(UiObject* obj, UiButtonArgs args) { |
184
8c9b4b28aaa9
implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
91 | UiObject* current = uic_current_obj(obj); |
8c9b4b28aaa9
implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
92 | |
8c9b4b28aaa9
implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
93 | // create button with label |
8c9b4b28aaa9
implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
94 | Button button = Button(); |
379
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
95 | ui_set_button_label(button, args.label, args.stockid, args.icon, args.labeltype); |
184
8c9b4b28aaa9
implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
96 | |
8c9b4b28aaa9
implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
97 | // create toolkit wrapper object and register destructor |
8c9b4b28aaa9
implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
98 | UIElement elm = button; |
8c9b4b28aaa9
implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
99 | UiWidget* widget = new UiWidget(elm); |
8c9b4b28aaa9
implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
100 | ui_context_add_widget_destructor(current->ctx, widget); |
382
de653b07050b
implement ui groups/states (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
101 | ui_set_widget_groups(current->ctx, widget, args.groups); |
184
8c9b4b28aaa9
implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
102 | |
8c9b4b28aaa9
implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
103 | // register callback |
186
5db4979bf482
implement new api style for ui_button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
184
diff
changeset
|
104 | if (args.onclick) { |
196
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
192
diff
changeset
|
105 | ui_callback cbfunc = args.onclick; |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
192
diff
changeset
|
106 | void* cbdata = args.onclickdata; |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
192
diff
changeset
|
107 | button.Click([cbfunc, cbdata, obj](IInspectable const& sender, RoutedEventArgs) { |
184
8c9b4b28aaa9
implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
108 | UiEvent evt; |
196
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
192
diff
changeset
|
109 | evt.obj = obj; |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
192
diff
changeset
|
110 | evt.window = obj->window; |
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
192
diff
changeset
|
111 | evt.document = obj->ctx->document; |
184
8c9b4b28aaa9
implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
112 | evt.eventdata = nullptr; |
8c9b4b28aaa9
implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
113 | evt.intval = 0; |
196
320d85f3cd14
add listview (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
192
diff
changeset
|
114 | cbfunc(&evt, cbdata); |
186
5db4979bf482
implement new api style for ui_button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
184
diff
changeset
|
115 | }); |
184
8c9b4b28aaa9
implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
116 | } |
186
5db4979bf482
implement new api style for ui_button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
184
diff
changeset
|
117 | |
184
8c9b4b28aaa9
implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
118 | // 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
|
119 | UI_APPLY_LAYOUT1(current, args); |
187
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
120 | |
184
8c9b4b28aaa9
implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
121 | current->container->Add(button, false); |
8c9b4b28aaa9
implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
122 | |
8c9b4b28aaa9
implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
123 | return widget; |
8c9b4b28aaa9
implement ui_button (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
124 | } |
186
5db4979bf482
implement new api style for ui_button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
184
diff
changeset
|
125 | |
189
4daddc326877
add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
188
diff
changeset
|
126 | |
206
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
127 | void togglebutton_register_checked_observers(ToggleButton button, UiObject* obj, UiVar* var) { |
189
4daddc326877
add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
188
diff
changeset
|
128 | 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
|
129 | UiInteger* i = (UiInteger*)var->value; |
4daddc326877
add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
188
diff
changeset
|
130 | 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
|
131 | ui_notify_evt(i->observers, &evt); |
4daddc326877
add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
188
diff
changeset
|
132 | }); |
4daddc326877
add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
188
diff
changeset
|
133 | } |
4daddc326877
add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
188
diff
changeset
|
134 | |
206
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
135 | void togglebutton_register_unchecked_observers(ToggleButton button, UiObject* obj, UiVar* var) { |
189
4daddc326877
add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
188
diff
changeset
|
136 | 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
|
137 | UiInteger* i = (UiInteger*)var->value; |
4daddc326877
add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
188
diff
changeset
|
138 | 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
|
139 | ui_notify_evt(i->observers, &evt); |
4daddc326877
add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
188
diff
changeset
|
140 | }); |
4daddc326877
add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
188
diff
changeset
|
141 | } |
4daddc326877
add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
188
diff
changeset
|
142 | |
206
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
143 | void togglebutton_register_callback(ToggleButton button, UiObject *obj, UiToggleArgs& args) { |
189
4daddc326877
add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
188
diff
changeset
|
144 | ui_callback callback = args.onchange; |
4daddc326877
add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
188
diff
changeset
|
145 | void* cbdata = args.onchangedata; |
4daddc326877
add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
188
diff
changeset
|
146 | if (callback) { |
4daddc326877
add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
188
diff
changeset
|
147 | 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
|
148 | 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
|
149 | callback(&evt, cbdata); |
4daddc326877
add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
188
diff
changeset
|
150 | }); |
4daddc326877
add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
188
diff
changeset
|
151 | 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
|
152 | 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
|
153 | callback(&evt, cbdata); |
4daddc326877
add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
188
diff
changeset
|
154 | }); |
4daddc326877
add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
188
diff
changeset
|
155 | } |
4daddc326877
add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
188
diff
changeset
|
156 | } |
4daddc326877
add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
188
diff
changeset
|
157 | |
191
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
158 | // for some stupid reason the ToggleSwitch is not a ToggleButton and we need to write the same |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
159 | // code again, because although everything is basically the same, it is named differently |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
160 | static void switch_register_observers(ToggleSwitch button, UiObject* obj, UiVar* var) { |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
161 | button.Toggled([button, obj, var](IInspectable const& sender, RoutedEventArgs) { |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
162 | UiInteger* i = (UiInteger*)var->value; |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
163 | UiEvent evt = ui_create_int_event(obj, i->get(i)); |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
164 | ui_notify_evt(i->observers, &evt); |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
165 | }); |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
166 | } |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
167 | |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
168 | static void switch_register_callback(ToggleSwitch button, UiObject* obj, UiToggleArgs& args) { |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
169 | ui_callback callback = args.onchange; |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
170 | void* cbdata = args.onchangedata; |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
171 | if (callback) { |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
172 | button.Toggled([button, obj, callback, cbdata](IInspectable const& sender, RoutedEventArgs) { |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
173 | UiEvent evt = ui_create_int_event(obj, button.IsOn()); |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
174 | callback(&evt, cbdata); |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
175 | }); |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
176 | } |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
177 | } |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
178 | |
382
de653b07050b
implement ui groups/states (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
179 | static void togglebutton_changed(UiObject *obj, bool checked, ui_callback onchange, void *onchangedata, int enable_state) { |
de653b07050b
implement ui groups/states (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
180 | if (onchange) { |
de653b07050b
implement ui groups/states (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
181 | UiEvent evt; |
de653b07050b
implement ui groups/states (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
182 | evt.obj = obj; |
de653b07050b
implement ui groups/states (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
183 | evt.window = obj->window; |
de653b07050b
implement ui groups/states (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
184 | evt.document = obj->ctx->document; |
de653b07050b
implement ui groups/states (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
185 | evt.eventdata = nullptr; |
de653b07050b
implement ui groups/states (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
186 | evt.intval = checked; |
de653b07050b
implement ui groups/states (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
187 | onchange(&evt, onchangedata); |
de653b07050b
implement ui groups/states (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
188 | } |
de653b07050b
implement ui groups/states (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
189 | if (enable_state > 0) { |
de653b07050b
implement ui groups/states (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
190 | if (checked) { |
de653b07050b
implement ui groups/states (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
191 | ui_set_group(obj->ctx, enable_state); |
de653b07050b
implement ui groups/states (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
192 | } else { |
de653b07050b
implement ui groups/states (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
193 | ui_unset_group(obj->ctx, enable_state); |
de653b07050b
implement ui groups/states (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
194 | } |
de653b07050b
implement ui groups/states (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
195 | } |
de653b07050b
implement ui groups/states (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
196 | } |
191
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
197 | |
187
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
198 | 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
|
199 | UiObject* current = uic_current_obj(obj); |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
200 | |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
201 | // set label |
379
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
202 | ui_set_button_label(button, args.label, args.stockid, args.icon, args.labeltype); |
189
4daddc326877
add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
188
diff
changeset
|
203 | togglebutton_register_callback(button, obj, args); |
187
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
204 | |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
205 | // create toolkit wrapper object and register destructor |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
206 | UIElement elm = button; |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
207 | UiWidget* widget = new UiWidget(elm); |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
208 | ui_context_add_widget_destructor(current->ctx, widget); |
382
de653b07050b
implement ui groups/states (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
209 | ui_set_widget_groups(current->ctx, widget, args.groups); |
187
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
210 | |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
211 | // bind variable |
192
bcacd00ea955
implement textfield (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
191
diff
changeset
|
212 | UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_INTEGER); |
187
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
213 | if (var) { |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
214 | UiInteger* value = (UiInteger*)var->value; |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
215 | value->obj = widget; |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
216 | value->get = ui_toggle_button_get; |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
217 | 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
|
218 | |
4daddc326877
add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
188
diff
changeset
|
219 | // listener for notifying observers |
4daddc326877
add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
188
diff
changeset
|
220 | 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
|
221 | togglebutton_register_unchecked_observers(button, obj, var); |
187
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
222 | } |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
223 | |
382
de653b07050b
implement ui groups/states (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
224 | if (args.enable_group > 0 || args.onchange) { |
de653b07050b
implement ui groups/states (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
225 | button.Checked([obj, args](IInspectable const& sender, RoutedEventArgs) { |
de653b07050b
implement ui groups/states (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
226 | togglebutton_changed(obj, true, args.onchange, args.onchangedata, args.enable_group); |
de653b07050b
implement ui groups/states (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
227 | }); |
de653b07050b
implement ui groups/states (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
228 | button.Unchecked([obj, args](IInspectable const& sender, RoutedEventArgs) { |
de653b07050b
implement ui groups/states (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
229 | togglebutton_changed(obj, false, args.onchange, args.onchangedata, args.enable_group); |
de653b07050b
implement ui groups/states (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
230 | }); |
de653b07050b
implement ui groups/states (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
231 | } |
de653b07050b
implement ui groups/states (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
232 | |
187
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
233 | // add button to current container |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
234 | UI_APPLY_LAYOUT1(current, args); |
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 | current->container->Add(button, false); |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
237 | |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
238 | return widget; |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
239 | } |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
240 | |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
241 | UIWIDGET ui_togglebutton_create(UiObject* obj, UiToggleArgs args) { |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
242 | ToggleButton button = ToggleButton(); |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
243 | return create_togglebutton(obj, button, args); |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
244 | } |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
245 | |
186
5db4979bf482
implement new api style for ui_button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
184
diff
changeset
|
246 | UIWIDGET ui_checkbox_create(UiObject* obj, UiToggleArgs args) { |
187
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
247 | CheckBox button = CheckBox(); |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
248 | 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
|
249 | } |
5db4979bf482
implement new api style for ui_button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
184
diff
changeset
|
250 | |
191
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
251 | UIWIDGET ui_switch_create(UiObject* obj, UiToggleArgs args) { |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
252 | ToggleSwitch button = ToggleSwitch(); |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
253 | if (args.label) { |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
254 | wchar_t* wlabel = str2wstr(args.label, nullptr); |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
255 | button.Header(box_value(wlabel)); |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
256 | free(wlabel); |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
257 | } |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
258 | switch_register_callback(button, obj, args); |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
259 | |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
260 | UiObject* current = uic_current_obj(obj); |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
261 | |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
262 | // create toolkit wrapper object and register destructor |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
263 | UIElement elm = button; |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
264 | UiWidget* widget = new UiWidget(elm); |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
265 | ui_context_add_widget_destructor(current->ctx, widget); |
382
de653b07050b
implement ui groups/states (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
266 | ui_set_widget_groups(current->ctx, widget, args.groups); |
191
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
267 | |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
268 | // bind variable |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
269 | UiVar* var = nullptr; |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
270 | if (args.value) { |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
271 | var = uic_create_value_var(current->ctx, args.value); |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
272 | } |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
273 | else if (args.varname) { |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
274 | var = uic_create_var(obj->ctx, args.varname, UI_VAR_INTEGER); |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
275 | } |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
276 | if (var) { |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
277 | UiInteger* value = (UiInteger*)var->value; |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
278 | value->obj = widget; |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
279 | value->get = ui_toggle_button_get; |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
280 | value->set = ui_toggle_button_set; |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
281 | |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
282 | // listener for notifying observers |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
283 | switch_register_observers(button, obj, var); |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
284 | } |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
285 | |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
286 | // add button to current container |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
287 | UI_APPLY_LAYOUT1(current, args); |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
288 | |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
289 | current->container->Add(button, false); |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
290 | |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
291 | return widget; |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
292 | } |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
293 | |
188
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
294 | UIWIDGET ui_radiobutton_create(UiObject* obj, UiToggleArgs args) { |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
295 | RadioButton button = RadioButton(); |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
296 | |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
297 | UiObject* current = uic_current_obj(obj); |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
298 | |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
299 | // set label |
379
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
374
diff
changeset
|
300 | ui_set_button_label(button, args.label, args.stockid, args.icon, args.labeltype); |
189
4daddc326877
add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
188
diff
changeset
|
301 | togglebutton_register_callback(button, obj, args); |
188
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
302 | |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
303 | // create toolkit wrapper object and register destructor |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
304 | UIElement elm = button; |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
305 | UiWidget* widget = new UiWidget(elm); |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
306 | ui_context_add_widget_destructor(current->ctx, widget); |
382
de653b07050b
implement ui groups/states (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
307 | ui_set_widget_groups(current->ctx, widget, args.groups); |
188
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
308 | |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
309 | UiVar* var = nullptr; |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
310 | if (args.value) { |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
311 | var = uic_create_value_var(current->ctx, args.value); |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
312 | } |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
313 | else if (args.varname) { |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
314 | 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
|
315 | } |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
316 | |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
317 | // bind radio button to the value |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
318 | if (var) { |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
319 | UiInteger* value = (UiInteger*)var->value; |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
320 | |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
321 | // store a list of radio buttons in the value |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
322 | 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
|
323 | // get or create the group name |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
324 | static int groupCount = 0; |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
325 | winrt::hstring groupName; |
373
2eede3d98aba
implement windows condvar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
230
diff
changeset
|
326 | if (cxListSize(radioButtons) == 0) { |
188
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
327 | groupName = winrt::to_hstring(groupCount++); |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
328 | } else { |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
329 | UiWidget* firstButtonWidget = (UiWidget*)cxListAt(radioButtons, 0); |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
330 | RadioButton firstRadioButton = firstButtonWidget->uielement.as<RadioButton>(); |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
331 | groupName = firstRadioButton.GroupName(); |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
332 | } |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
333 | |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
334 | // set the group name for the new radiobutton |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
335 | cxListAdd(radioButtons, widget); |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
336 | button.GroupName(groupName); |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
337 | |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
338 | value->obj = radioButtons; |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
339 | value->get = ui_radio_button_get; |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
340 | 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
|
341 | |
4daddc326877
add onchange event for toggle buttons (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
188
diff
changeset
|
342 | // 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
|
343 | togglebutton_register_checked_observers(button, obj, var); |
188
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
344 | } |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
345 | |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
346 | // add button to current container |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
347 | UI_APPLY_LAYOUT1(current, args); |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
348 | |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
349 | current->container->Add(button, false); |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
350 | |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
351 | return widget; |
186
5db4979bf482
implement new api style for ui_button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
184
diff
changeset
|
352 | } |
187
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
353 | |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
354 | |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
355 | int64_t ui_toggle_button_get(UiInteger* integer) { |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
356 | UiWidget* widget = (UiWidget*)integer->obj; |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
357 | ToggleButton toggleButton = widget->uielement.as<ToggleButton>(); |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
358 | int val = toggleButton.IsChecked().GetBoolean(); |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
359 | integer->value = val; |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
360 | return val; |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
361 | } |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
362 | |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
363 | 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
|
364 | UiWidget* widget = (UiWidget*)integer->obj; |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
365 | ToggleButton toggleButton = widget->uielement.as<ToggleButton>(); |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
366 | toggleButton.IsChecked((bool)value); |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
367 | integer->value = value; |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
368 | } |
188
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
369 | |
206
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
370 | int64_t ui_switch_get(UiInteger * integer) { |
191
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
371 | UiWidget* widget = (UiWidget*)integer->obj; |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
372 | ToggleSwitch toggleButton = widget->uielement.as<ToggleSwitch>(); |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
373 | int val = toggleButton.IsOn(); |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
374 | integer->value = val; |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
375 | return val; |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
376 | } |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
377 | |
206
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
378 | void ui_switch_set(UiInteger * integer, int64_t value) { |
191
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
379 | UiWidget* widget = (UiWidget*)integer->obj; |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
380 | ToggleSwitch toggleButton = widget->uielement.as<ToggleSwitch>(); |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
381 | toggleButton.IsOn((bool)value); |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
382 | integer->value = value; |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
383 | } |
6113ed66d258
add toggle switch (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
189
diff
changeset
|
384 | |
206
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
385 | int64_t ui_radio_button_get(UiInteger * integer) { |
188
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
386 | CxList* list = (CxList*)integer->obj; |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
387 | CxIterator i = cxListIterator(list); |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
388 | int selection = -1; |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
389 | cx_foreach(UiWidget*, widget, i) { |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
390 | ToggleButton button = widget->uielement.as<ToggleButton>(); |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
391 | if (button.IsChecked().GetBoolean()) { |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
392 | selection = i.index; |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
393 | break; |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
394 | } |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
395 | } |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
396 | integer->value = selection; |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
397 | return selection; |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
398 | } |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
399 | |
206
7ebc5a747c6f
implement toolbar togglebutton
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
400 | void ui_radio_button_set(UiInteger * integer, int64_t value) { |
188
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
401 | CxList* list = (CxList*)integer->obj; |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
402 | UiWidget* widget = (UiWidget*)cxListAt(list, value); |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
403 | if (widget) { |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
404 | ToggleButton button = widget->uielement.as<ToggleButton>(); |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
405 | button.IsChecked(true); |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
406 | integer->value = value; |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
407 | } |
fbbae6738252
implement radio button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
187
diff
changeset
|
408 | } |