44 using namespace winrt::Windows::Foundation; |
44 using namespace winrt::Windows::Foundation; |
45 using namespace winrt::Microsoft::UI::Xaml::Controls::Primitives; |
45 using namespace winrt::Microsoft::UI::Xaml::Controls::Primitives; |
46 |
46 |
47 |
47 |
48 |
48 |
49 static void set_button_label(ButtonBase button, const char* label, const char* stockid) { |
49 static void set_button_label(ButtonBase button, const char* label, const char* stockid, const char *icon, UiLabelType type) { |
50 if (label) { |
50 // TODO: stockid |
|
51 |
|
52 if (type == UI_LABEL_ICON) { |
|
53 label = NULL; |
|
54 } |
|
55 else if (type == UI_LABEL_TEXT) { |
|
56 icon = NULL; |
|
57 } |
|
58 |
|
59 if (label && icon) { |
|
60 StackPanel panel = StackPanel(); |
|
61 panel.Orientation(Orientation::Horizontal); |
|
62 panel.Spacing(5); |
|
63 |
|
64 panel.Children().Append(ui_get_icon(icon)); |
|
65 |
|
66 wchar_t* wlabel = str2wstr(label, nullptr); |
|
67 TextBlock label = TextBlock(); |
|
68 label.Text(wlabel); |
|
69 panel.Children().Append(label); |
|
70 free(wlabel); |
|
71 |
|
72 button.Content(panel); |
|
73 } |
|
74 else if (label) { |
51 wchar_t* wlabel = str2wstr(label, nullptr); |
75 wchar_t* wlabel = str2wstr(label, nullptr); |
52 button.Content(box_value(wlabel)); |
76 button.Content(box_value(wlabel)); |
53 free(wlabel); |
77 free(wlabel); |
54 } |
78 } |
55 // TODO: stockid |
79 else if (icon) { |
|
80 button.Content(ui_get_icon(icon)); |
|
81 } |
56 } |
82 } |
57 |
83 |
58 |
84 |
59 UIWIDGET ui_button_create(UiObject* obj, UiButtonArgs args) { |
85 UIWIDGET ui_button_create(UiObject* obj, UiButtonArgs args) { |
60 UiObject* current = uic_current_obj(obj); |
86 UiObject* current = uic_current_obj(obj); |
61 |
87 |
62 // create button with label |
88 // create button with label |
63 Button button = Button(); |
89 Button button = Button(); |
64 set_button_label(button, args.label, args.stockid); |
90 set_button_label(button, args.label, args.stockid, args.icon, args.labeltype); |
65 |
91 |
66 // create toolkit wrapper object and register destructor |
92 // create toolkit wrapper object and register destructor |
67 UIElement elm = button; |
93 UIElement elm = button; |
68 UiWidget* widget = new UiWidget(elm); |
94 UiWidget* widget = new UiWidget(elm); |
69 ui_context_add_widget_destructor(current->ctx, widget); |
95 ui_context_add_widget_destructor(current->ctx, widget); |
147 |
173 |
148 static UIWIDGET create_togglebutton(UiObject *obj, ToggleButton button, UiToggleArgs args) { |
174 static UIWIDGET create_togglebutton(UiObject *obj, ToggleButton button, UiToggleArgs args) { |
149 UiObject* current = uic_current_obj(obj); |
175 UiObject* current = uic_current_obj(obj); |
150 |
176 |
151 // set label |
177 // set label |
152 set_button_label(button, args.label, args.stockid); |
178 set_button_label(button, args.label, args.stockid, args.icon, args.labeltype); |
153 togglebutton_register_callback(button, obj, args); |
179 togglebutton_register_callback(button, obj, args); |
154 |
180 |
155 // create toolkit wrapper object and register destructor |
181 // create toolkit wrapper object and register destructor |
156 UIElement elm = button; |
182 UIElement elm = button; |
157 UiWidget* widget = new UiWidget(elm); |
183 UiWidget* widget = new UiWidget(elm); |
234 RadioButton button = RadioButton(); |
260 RadioButton button = RadioButton(); |
235 |
261 |
236 UiObject* current = uic_current_obj(obj); |
262 UiObject* current = uic_current_obj(obj); |
237 |
263 |
238 // set label |
264 // set label |
239 set_button_label(button, args.label, args.stockid); |
265 set_button_label(button, args.label, args.stockid, args.icon, args.labeltype); |
240 togglebutton_register_callback(button, obj, args); |
266 togglebutton_register_callback(button, obj, args); |
241 |
267 |
242 // create toolkit wrapper object and register destructor |
268 // create toolkit wrapper object and register destructor |
243 UIElement elm = button; |
269 UIElement elm = button; |
244 UiWidget* widget = new UiWidget(elm); |
270 UiWidget* widget = new UiWidget(elm); |