39 using namespace Microsoft::UI::Xaml; |
39 using namespace Microsoft::UI::Xaml; |
40 using namespace Microsoft::UI::Xaml::Controls; |
40 using namespace Microsoft::UI::Xaml::Controls; |
41 using namespace Windows::UI::Xaml::Interop; |
41 using namespace Windows::UI::Xaml::Interop; |
42 using namespace winrt::Windows::Foundation; |
42 using namespace winrt::Windows::Foundation; |
43 |
43 |
44 UIWIDGET ui_button(UiObject* obj, char* label, ui_callback f, void* data) { |
44 UIWIDGET ui_button_create(UiObject* obj, UiButtonArgs args) { |
45 UiObject* current = uic_current_obj(obj); |
45 UiObject* current = uic_current_obj(obj); |
46 |
46 |
47 // create button with label |
47 // create button with label |
48 Button button = Button(); |
48 Button button = Button(); |
49 if (label) { |
49 if (args.label) { |
50 wchar_t *wlabel = str2wstr(label, nullptr); |
50 wchar_t* wlabel = str2wstr(args.label, nullptr); |
51 button.Content(box_value(wlabel)); |
51 button.Content(box_value(wlabel)); |
52 free(wlabel); |
52 free(wlabel); |
53 } |
53 } |
54 |
54 |
55 // create toolkit wrapper object and register destructor |
55 // create toolkit wrapper object and register destructor |
56 UIElement elm = button; |
56 UIElement elm = button; |
57 UiWidget* widget = new UiWidget(elm); |
57 UiWidget* widget = new UiWidget(elm); |
58 ui_context_add_widget_destructor(current->ctx, widget); |
58 ui_context_add_widget_destructor(current->ctx, widget); |
59 |
59 |
60 // register callback |
60 // register callback |
61 if (f) { |
61 if (args.onclick) { |
62 widget->obj = obj; |
62 widget->obj = obj; |
63 widget->event_func = (ui_eventfunc)f; |
63 widget->event_func = (ui_eventfunc)args.onclick; |
64 widget->event_data = data; |
64 widget->event_data = args.onclickdata; |
65 button.Click([widget](IInspectable const& sender, RoutedEventArgs) { |
65 button.Click([widget](IInspectable const& sender, RoutedEventArgs) { |
66 ui_callback cb = (ui_callback)widget->event_func; |
66 ui_callback cb = (ui_callback)widget->event_func; |
67 |
67 |
68 UiEvent evt; |
68 UiEvent evt; |
69 evt.obj = (UiObject*)widget->obj; |
69 evt.obj = (UiObject*)widget->obj; |
70 evt.window = evt.obj->window; |
70 evt.window = evt.obj->window; |
71 evt.document = evt.obj->ctx->document; |
71 evt.document = evt.obj->ctx->document; |
72 evt.eventdata = nullptr; |
72 evt.eventdata = nullptr; |
73 evt.intval = 0; |
73 evt.intval = 0; |
74 cb(&evt, widget->event_data); |
74 cb(&evt, widget->event_data); |
75 } ); |
75 }); |
76 } |
76 } |
77 |
77 |
78 // add button to current container |
78 // add button to current container |
|
79 UI_APPLY_LAYOUT1(current, args); |
79 current->container->Add(button, false); |
80 current->container->Add(button, false); |
80 |
81 |
81 return widget; |
82 return widget; |
82 } |
83 } |
|
84 |
|
85 UIWIDGET ui_checkbox_create(UiObject* obj, UiToggleArgs args) { |
|
86 return nullptr; |
|
87 } |
|
88 |
|
89 UIWIDGET ui_radiobutton_create(UiObject* obj, UiToggleArgs) { |
|
90 return nullptr; |
|
91 } |