1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 #include "pch.h"
30
31 #include "label.h"
32 #include "text.h"
33 #include "util.h"
34
35 #include "toolkit.h"
36 #include "container.h"
37 #include "../common/object.h"
38 #include "../common/context.h"
39
40 using namespace winrt;
41 using namespace Microsoft::
UI::Xaml;
42 using namespace Microsoft::
UI::Xaml::Controls;
43 using namespace Windows::
UI::Xaml::Interop;
44 using namespace winrt::Windows::Foundation;
45 using namespace winrt::Microsoft::
UI::Xaml::Controls::Primitives;
46
47 UIWIDGET ui_label_create(UiObject* obj, UiLabelArgs args) {
48 UiObject* current = uic_current_obj(obj);
49
50
51 TextBlock label = TextBlock();
52 if (args.label) {
53 wchar_t* wlabel = str2wstr(args.label, nullptr);
54 label.Text(wlabel);
55 free(wlabel);
56 }
57
58 UIElement elm = label;
59 UiWidget* widget = new UiWidget(elm);
60 ui_context_add_widget_destructor(current->ctx, widget);
61
62 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname,
UI_VAR_STRING);
63 if (var) {
64 UiString* value = (UiString*)var->value;
65 value->obj = widget;
66 value->get = ui_label_get;
67 value->set = ui_label_set;
68
69
70
71 }
72
73
74 UI_APPLY_LAYOUT1(current, args);
75
76 current->container->Add(label, false);
77
78 return widget;
79 }
80
81 UIWIDGET ui_llabel_create(UiObject* obj, UiLabelArgs args) {
82 args.align =
UI_ALIGN_LEFT;
83 return ui_label_create(obj, args);
84 }
85
86 UIWIDGET ui_rlabel_create(UiObject* obj, UiLabelArgs args) {
87 args.align =
UI_ALIGN_RIGHT;
88 return ui_label_create(obj, args);
89 }
90
91
92
93 char* ui_label_get(UiString* str) {
94 UiWidget* widget = (UiWidget*)str->obj;
95 TextBlock box = widget->uielement.as<TextBlock>();
96 std::wstring wstr(box.Text());
97 return ui_wstring_get(str, wstr);
98 }
99
100 void ui_label_set(UiString* str,
const char* newvalue) {
101 UiWidget* widget = (UiWidget*)str->obj;
102 TextBlock box = widget->uielement.as<TextBlock>();
103 box.Text(ui_wstring_set(str, newvalue));
104 }
105
106
107
108
109 UIWIDGET ui_progressbar_create(UiObject* obj, UiProgressbarArgs args) {
110 UiObject* current = uic_current_obj(obj);
111
112
113 ProgressBar progressbar = ProgressBar();
114 progressbar.Minimum(args.min);
115 progressbar.Maximum(args.max ==
0 ?
100 : args.max);
116 if (args.width >
0) {
117 progressbar.Width(args.width);
118 }
119
120 UIElement elm = progressbar;
121 UiWidget* widget = new UiWidget(elm);
122 ui_context_add_widget_destructor(current->ctx, widget);
123
124 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname,
UI_VAR_DOUBLE);
125 if (var) {
126 UiDouble* value = (UiDouble*)var->value;
127 value->obj = widget;
128 value->get = ui_progressbar_get;
129 value->set = ui_progressbar_set;
130
131
132
133 }
134
135
136 UI_APPLY_LAYOUT1(current, args);
137
138 current->container->Add(progressbar, false);
139
140 return widget;
141 }
142
143 double ui_progressbar_get(UiDouble * d) {
144 UiWidget* widget = (UiWidget*)d->obj;
145 ProgressBar progressbar = widget->uielement.as<ProgressBar>();
146 d->value = progressbar.Value();
147 return d->value;
148 }
149
150 void ui_progressbar_set(UiDouble * d,
double newvalue) {
151 UiWidget* widget = (UiWidget*)d->obj;
152 ProgressBar progressbar = widget->uielement.as<ProgressBar>();
153 d->value = newvalue;
154 progressbar.Value(newvalue);
155 }
156
157 UIWIDGET ui_progressspinner_create(UiObject* obj, UiProgressbarSpinnerArgs args) {
158 UiObject* current = uic_current_obj(obj);
159
160
161 ProgressRing spinner = ProgressRing();
162 spinner.IsActive(false);
163
164 UIElement elm = spinner;
165 UiWidget* widget = new UiWidget(elm);
166 ui_context_add_widget_destructor(current->ctx, widget);
167
168 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname,
UI_VAR_DOUBLE);
169 if (var) {
170 UiInteger* value = (UiInteger*)var->value;
171 value->obj = widget;
172 value->get = ui_progressspinner_get;
173 value->set = ui_progressspinner_set;
174
175
176
177 }
178
179
180 UI_APPLY_LAYOUT1(current, args);
181
182 current->container->Add(spinner, false);
183
184 return widget;
185 }
186
187 int64_t ui_progressspinner_get(UiInteger * i) {
188 UiWidget* widget = (UiWidget*)i->obj;
189 ProgressRing spinner = widget->uielement.as<ProgressRing>();
190 i->value = spinner.IsActive();
191 return i->value;
192 }
193
194 void ui_progressspinner_set(UiInteger * i,
int64_t newvalue) {
195 UiWidget* widget = (UiWidget*)i->obj;
196 ProgressRing spinner = widget->uielement.as<ProgressRing>();
197 i->value = newvalue !=
0 ?
1 :
0;
198 spinner.IsActive(i->value);
199 }
200