Sun, 01 Oct 2023 12:08:09 +0200
implement toggle button (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 | |
187
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
95 | 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
|
96 | UiObject* current = uic_current_obj(obj); |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
97 | |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
98 | // set label |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
99 | set_button_label(button, args.label, args.stockid); |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
100 | |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
101 | // create toolkit wrapper object and register destructor |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
102 | UIElement elm = button; |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
103 | UiWidget* widget = new UiWidget(elm); |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
104 | ui_context_add_widget_destructor(current->ctx, widget); |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
105 | |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
106 | // bind variable |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
107 | UiVar* var = nullptr; |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
108 | if (args.value) { |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
109 | var = uic_create_value_var(current->ctx, args.value); |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
110 | } |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
111 | else if (args.varname) { |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
112 | 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
|
113 | } |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
114 | if (var) { |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
115 | UiInteger* value = (UiInteger*)var->value; |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
116 | value->obj = widget; |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
117 | value->get = ui_toggle_button_get; |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
118 | value->set = ui_toggle_button_set; |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
119 | } |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
120 | |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
121 | // add button to current container |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
122 | UI_APPLY_LAYOUT1(current, args); |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
123 | |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
124 | current->container->Add(button, false); |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
125 | |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
126 | return widget; |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
127 | } |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
128 | |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
129 | UIWIDGET ui_togglebutton_create(UiObject* obj, UiToggleArgs args) { |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
130 | ToggleButton button = ToggleButton(); |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
131 | return create_togglebutton(obj, button, args); |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
132 | } |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
133 | |
186
5db4979bf482
implement new api style for ui_button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
184
diff
changeset
|
134 | UIWIDGET ui_checkbox_create(UiObject* obj, UiToggleArgs args) { |
187
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
135 | CheckBox button = CheckBox(); |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
136 | 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
|
137 | } |
5db4979bf482
implement new api style for ui_button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
184
diff
changeset
|
138 | |
5db4979bf482
implement new api style for ui_button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
184
diff
changeset
|
139 | UIWIDGET ui_radiobutton_create(UiObject* obj, UiToggleArgs) { |
5db4979bf482
implement new api style for ui_button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
184
diff
changeset
|
140 | return nullptr; |
5db4979bf482
implement new api style for ui_button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
184
diff
changeset
|
141 | } |
187
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
142 | |
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 | int64_t ui_toggle_button_get(UiInteger* integer) { |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
145 | UiWidget* widget = (UiWidget*)integer->obj; |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
146 | ToggleButton toggleButton = widget->uielement.as<ToggleButton>(); |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
147 | int val = toggleButton.IsChecked().GetBoolean(); |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
148 | integer->value = val; |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
149 | return val; |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
150 | } |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
151 | |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
152 | 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
|
153 | UiWidget* widget = (UiWidget*)integer->obj; |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
154 | ToggleButton toggleButton = widget->uielement.as<ToggleButton>(); |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
155 | toggleButton.IsChecked((bool)value); |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
156 | integer->value = value; |
24ce2c326d85
implement toggle button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
186
diff
changeset
|
157 | } |