ui/winui/label.cpp

Fri, 15 Nov 2024 21:25:35 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Fri, 15 Nov 2024 21:25:35 +0100
branch
newapi
changeset 385
e3a01a99236d
parent 245
06e655d15b17
permissions
-rw-r--r--

add ui_dialog_window reference counting (GTK)

219
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2023 Olaf Wintermann. All rights reserved.
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
527a66c0afb2 add label (WinUI3)
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
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include "pch.h"
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include "label.h"
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 #include "text.h"
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include "util.h"
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #include "toolkit.h"
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 #include "container.h"
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 #include "../common/object.h"
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 #include "../common/context.h"
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 using namespace winrt;
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 using namespace Microsoft::UI::Xaml;
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 using namespace Microsoft::UI::Xaml::Controls;
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 using namespace Windows::UI::Xaml::Interop;
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 using namespace winrt::Windows::Foundation;
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 using namespace winrt::Microsoft::UI::Xaml::Controls::Primitives;
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 UIWIDGET ui_label_create(UiObject* obj, UiLabelArgs args) {
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 UiObject* current = uic_current_obj(obj);
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 // create textbox and toolkit wrapper
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 TextBlock label = TextBlock();
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 if (args.label) {
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 wchar_t* wlabel = str2wstr(args.label, nullptr);
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 label.Text(wlabel);
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 free(wlabel);
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 }
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 UIElement elm = label;
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 UiWidget* widget = new UiWidget(elm);
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 ui_context_add_widget_destructor(current->ctx, widget);
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_STRING);
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 if (var) {
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 UiString* value = (UiString*)var->value;
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 value->obj = widget;
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 value->get = ui_label_get;
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 value->set = ui_label_set;
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 // listener for notifying observers
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 // TODO:
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 }
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72
220
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
73 // add label to current container
219
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 UI_APPLY_LAYOUT1(current, args);
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 current->container->Add(label, false);
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 return widget;
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 }
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 UIWIDGET ui_llabel_create(UiObject* obj, UiLabelArgs args) {
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 args.align = UI_ALIGN_LEFT;
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 return ui_label_create(obj, args);
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 }
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 UIWIDGET ui_rlabel_create(UiObject* obj, UiLabelArgs args) {
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 args.align = UI_ALIGN_RIGHT;
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 return ui_label_create(obj, args);
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 }
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 char* ui_label_get(UiString* str) {
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 UiWidget* widget = (UiWidget*)str->obj;
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 TextBlock box = widget->uielement.as<TextBlock>();
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 std::wstring wstr(box.Text());
231
e160bb392148 add getter/setter for ui number/string types
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
97 return ui_wstring_get(str, wstr);
219
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98 }
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 void ui_label_set(UiString* str, const char* newvalue) {
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 UiWidget* widget = (UiWidget*)str->obj;
245
06e655d15b17 fix usage of wrong type in ui_label_set (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 231
diff changeset
102 TextBlock box = widget->uielement.as<TextBlock>();
231
e160bb392148 add getter/setter for ui number/string types
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 221
diff changeset
103 box.Text(ui_wstring_set(str, newvalue));
219
527a66c0afb2 add label (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 }
220
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
105
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
106
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
107 // -------------------- progressbar -------------------------
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
108
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
109 UIWIDGET ui_progressbar_create(UiObject* obj, UiProgressbarArgs args) {
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
110 UiObject* current = uic_current_obj(obj);
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
111
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
112 // create textbox and toolkit wrapper
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
113 ProgressBar progressbar = ProgressBar();
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
114 progressbar.Minimum(args.min);
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
115 progressbar.Maximum(args.max == 0 ? 100 : args.max);
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
116 if (args.width > 0) {
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
117 progressbar.Width(args.width);
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
118 }
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
119
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
120 UIElement elm = progressbar;
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
121 UiWidget* widget = new UiWidget(elm);
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
122 ui_context_add_widget_destructor(current->ctx, widget);
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
123
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
124 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_DOUBLE);
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
125 if (var) {
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
126 UiDouble* value = (UiDouble*)var->value;
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
127 value->obj = widget;
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
128 value->get = ui_progressbar_get;
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
129 value->set = ui_progressbar_set;
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
130
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
131 // listener for notifying observers
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
132 // TODO:
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
133 }
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
134
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
135 // add button to current container
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
136 UI_APPLY_LAYOUT1(current, args);
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
137
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
138 current->container->Add(progressbar, false);
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
139
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
140 return widget;
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
141 }
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
142
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
143 double ui_progressbar_get(UiDouble * d) {
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
144 UiWidget* widget = (UiWidget*)d->obj;
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
145 ProgressBar progressbar = widget->uielement.as<ProgressBar>();
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
146 d->value = progressbar.Value();
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
147 return d->value;
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
148 }
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
149
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
150 void ui_progressbar_set(UiDouble * d, double newvalue) {
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
151 UiWidget* widget = (UiWidget*)d->obj;
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
152 ProgressBar progressbar = widget->uielement.as<ProgressBar>();
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
153 d->value = newvalue;
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
154 progressbar.Value(newvalue);
e377456302df add progressbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 219
diff changeset
155 }
221
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
156
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
157 UIWIDGET ui_progressspinner_create(UiObject* obj, UiProgressbarSpinnerArgs args) {
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
158 UiObject* current = uic_current_obj(obj);
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
159
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
160 // create textbox and toolkit wrapper
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
161 ProgressRing spinner = ProgressRing();
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
162 spinner.IsActive(false);
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
163
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
164 UIElement elm = spinner;
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
165 UiWidget* widget = new UiWidget(elm);
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
166 ui_context_add_widget_destructor(current->ctx, widget);
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
167
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
168 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_DOUBLE);
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
169 if (var) {
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
170 UiInteger* value = (UiInteger*)var->value;
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
171 value->obj = widget;
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
172 value->get = ui_progressspinner_get;
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
173 value->set = ui_progressspinner_set;
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
174
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
175 // listener for notifying observers
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
176 // TODO:
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
177 }
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
178
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
179 // add button to current container
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
180 UI_APPLY_LAYOUT1(current, args);
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
181
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
182 current->container->Add(spinner, false);
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
183
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
184 return widget;
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
185 }
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
186
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
187 int64_t ui_progressspinner_get(UiInteger * i) {
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
188 UiWidget* widget = (UiWidget*)i->obj;
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
189 ProgressRing spinner = widget->uielement.as<ProgressRing>();
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
190 i->value = spinner.IsActive();
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
191 return i->value;
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
192 }
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
193
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
194 void ui_progressspinner_set(UiInteger * i, int64_t newvalue) {
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
195 UiWidget* widget = (UiWidget*)i->obj;
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
196 ProgressRing spinner = widget->uielement.as<ProgressRing>();
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
197 i->value = newvalue != 0 ? 1 : 0;
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
198 spinner.IsActive(i->value);
a82d9beaa94a add semi-functional pathbar (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 220
diff changeset
199 }

mercurial