# HG changeset patch # User Olaf Wintermann # Date 1696145027 -7200 # Node ID 5db4979bf4827766773635276c4610b66065b4f8 # Parent 4a8b1a748f091b1987be597e31746bbff7a5f4c0 implement new api style for ui_button (WinUI3) diff -r 4a8b1a748f09 -r 5db4979bf482 make/vs/testapp/main.c --- a/make/vs/testapp/main.c Sun Sep 24 12:03:57 2023 +0200 +++ b/make/vs/testapp/main.c Sun Oct 01 09:23:47 2023 +0200 @@ -30,38 +30,30 @@ #include #include +#include #include void action1(UiEvent* event, void* data) { char* action = data; - printf("hello world!\n"); + printf("data: %s!\n", data); } void application_startup(UiEvent* event, void* data) { UiObject* obj = ui_window("Test", NULL); - /* - ui_button(obj, "Button1", action1, "action1"); - ui_button(obj, "Button2", action1, "action2"); - ui_layout_fill(obj, TRUE); - ui_button(obj, "Button3", action1, "action3"); - */ - UI_GRID_SP(obj, 10, 5, 20) { - ui_button(obj, "Button1", action1, "action1"); - ui_button(obj, "Button2", action1, "action2"); - ui_layout_hexpand(obj, 1); - ui_button(obj, "Button3", action1, "action3"); + ui_button(obj, .label="Button1", .onclick=action1, .onclickdata="action1"); + ui_button(obj, .label="Button2", .onclick=action1, .onclickdata="action2"); + ui_button(obj, .label="Button3", .onclick=action1, .onclickdata="action3", .hexpand=true); ui_newline(obj); - ui_button(obj, "Button4", action1, "action4"); - ui_layout_gridwidth(obj, 2); - ui_button(obj, "Button5_", action1, "action5"); + ui_button(obj, .label="Button4", .onclick=action1, .onclickdata="action4"); + ui_button(obj, .label="Button5", .onclick=action1, .onclickdata="action5", .colspan=2); ui_newline(obj); - ui_button(obj, "Very Long Button Label Text ____________ Test", action1, "test"); + ui_button(obj, .label="Very Long Button Label Text ____________ Test", .onclick=action1, .onclickdata="test"); } ui_show(obj); diff -r 4a8b1a748f09 -r 5db4979bf482 ui/ui/button.h --- a/ui/ui/button.h Sun Sep 24 12:03:57 2023 +0200 +++ b/ui/ui/button.h Sun Oct 01 09:23:47 2023 +0200 @@ -34,14 +34,42 @@ #ifdef __cplusplus extern "C" { #endif - -UIWIDGET ui_button(UiObject *obj, char *label, ui_callback f, void *data); + +typedef struct UiButtonArgs { + UiTri fill; + UiBool hexpand; + UiBool vexpand; + int colspan; + int rowspan; + + char* label; + char* stockid; + ui_callback onclick; + void* onclickdata; +} UiButtonArgs; -UIWIDGET ui_checkbox(UiObject *obj, char *label, UiInteger *value); -UIWIDGET ui_checkbox_nv(UiObject *obj, char *label, char *varname); +typedef struct UiToggleArgs { + char* label; + char* stockid; + UiInteger* value; + char* varname; +} UiToggleArgs; + +#define ui_button(obj, ...) ui_button_create(obj, (UiButtonArgs){ __VA_ARGS__ } ) +#define ui_checkbox(obj, ...) ui_checkbox_create(obj, (UiToggleArgs){ __VA_ARGS__ } ) +#define ui_radiobutton(obj, ...) ui_checkbox_create(obj, (UiToggleArgs){ __VA_ARGS__ } ) -UIWIDGET ui_radiobutton(UiObject *obj, char *label, UiInteger *rgroup); -UIWIDGET ui_radiobutton_nv(UiObject *obj, char *label, char *varname); +UIWIDGET ui_button_create(UiObject* obj, UiButtonArgs args); +UIWIDGET ui_checkbox_create(UiObject* obj, UiToggleArgs args); +UIWIDGET ui_radiobutton_create(UiObject* obj, UiToggleArgs); + +UIWIDGET deprecated_ui_button(UiObject *obj, char *label, ui_callback f, void *data); + +UIWIDGET deprecated_ui_checkbox(UiObject *obj, char *label, UiInteger *value); +UIWIDGET deprecated_ui_checkbox_nv(UiObject *obj, char *label, char *varname); + +UIWIDGET deprecated_ui_radiobutton(UiObject *obj, char *label, UiInteger *rgroup); +UIWIDGET deprecated_ui_radiobutton_nv(UiObject *obj, char *label, char *varname); #ifdef __cplusplus diff -r 4a8b1a748f09 -r 5db4979bf482 ui/ui/container.h --- a/ui/ui/container.h Sun Sep 24 12:03:57 2023 +0200 +++ b/ui/ui/container.h Sun Oct 01 09:23:47 2023 +0200 @@ -34,7 +34,8 @@ #ifdef __cplusplus extern "C" { #endif - + + #define UI_CTN(obj, ctn) for(ctn;ui_container_finish(obj);ui_container_begin_close(obj)) #define UI_VBOX(obj) for(ui_vbox(obj);ui_container_finish(obj);ui_container_begin_close(obj)) #define UI_HBOX(obj) for(ui_hbox(obj);ui_container_finish(obj);ui_container_begin_close(obj)) @@ -43,6 +44,7 @@ #define UI_GRID(obj) for(ui_grid(obj);ui_container_finish(obj);ui_container_begin_close(obj)) #define UI_GRID_SP(obj, margin, columnspacing, rowspacing) for(ui_grid_sp(obj,margin,columnspacing,rowspacing);ui_container_finish(obj);ui_container_begin_close(obj)) + void ui_end(UiObject *obj); UIWIDGET ui_vbox(UiObject *obj); @@ -70,7 +72,9 @@ void ui_layout_hexpand(UiObject *obj, UiBool expand); void ui_layout_vexpand(UiObject *obj, UiBool expand); void ui_layout_width(UiObject *obj, int width); -void ui_layout_gridwidth(UiObject *obj, int width); +void ui_layout_height(UiObject* obj, int width); +void ui_layout_colspan(UiObject *obj, int cols); +void ui_layout_rowspan(UiObject* obj, int rows); void ui_newline(UiObject *obj); @@ -83,6 +87,13 @@ void ui_container_begin_close(UiObject *obj); int ui_container_finish(UiObject *obj); +#define UI_APPLY_LAYOUT1(obj, args) \ + if(args.fill != UI_DEFAULT) ui_layout_fill(obj, args.fill == UI_ON ? 1 : 0 ); \ + if(args.hexpand) ui_layout_hexpand(obj, 1); \ + if(args.vexpand) ui_layout_vexpand(obj, 1); \ + if(args.colspan > 0) ui_layout_colspan(obj, args.colspan); \ + if(args.rowspan > 0) ui_layout_rowspan(obj, args.rowspan); + #ifdef __cplusplus } diff -r 4a8b1a748f09 -r 5db4979bf482 ui/ui/toolkit.h --- a/ui/ui/toolkit.h Sun Sep 24 12:03:57 2023 +0200 +++ b/ui/ui/toolkit.h Sun Oct 01 09:23:47 2023 +0200 @@ -163,6 +163,8 @@ typedef struct UiTabbedPane UiTabbedPane; +typedef enum UiTri UiTri; + enum UiMouseEventType { UI_PRESS = 0, UI_PRESS2 }; @@ -339,6 +341,12 @@ UiObserver *observers; }; +enum UiTri { + UI_DEFAULT = 0, + UI_ON, + UI_OFF +}; + void ui_init(const char *appname, int argc, char **argv); const char* ui_appname(); diff -r 4a8b1a748f09 -r 5db4979bf482 ui/winui/button.cpp --- a/ui/winui/button.cpp Sun Sep 24 12:03:57 2023 +0200 +++ b/ui/winui/button.cpp Sun Oct 01 09:23:47 2023 +0200 @@ -41,13 +41,13 @@ using namespace Windows::UI::Xaml::Interop; using namespace winrt::Windows::Foundation; -UIWIDGET ui_button(UiObject* obj, char* label, ui_callback f, void* data) { +UIWIDGET ui_button_create(UiObject* obj, UiButtonArgs args) { UiObject* current = uic_current_obj(obj); // create button with label Button button = Button(); - if (label) { - wchar_t *wlabel = str2wstr(label, nullptr); + if (args.label) { + wchar_t* wlabel = str2wstr(args.label, nullptr); button.Content(box_value(wlabel)); free(wlabel); } @@ -58,10 +58,10 @@ ui_context_add_widget_destructor(current->ctx, widget); // register callback - if (f) { + if (args.onclick) { widget->obj = obj; - widget->event_func = (ui_eventfunc)f; - widget->event_data = data; + widget->event_func = (ui_eventfunc)args.onclick; + widget->event_data = args.onclickdata; button.Click([widget](IInspectable const& sender, RoutedEventArgs) { ui_callback cb = (ui_callback)widget->event_func; @@ -72,11 +72,20 @@ evt.eventdata = nullptr; evt.intval = 0; cb(&evt, widget->event_data); - } ); + }); } - + // add button to current container + UI_APPLY_LAYOUT1(current, args); current->container->Add(button, false); return widget; } + +UIWIDGET ui_checkbox_create(UiObject* obj, UiToggleArgs args) { + return nullptr; +} + +UIWIDGET ui_radiobutton_create(UiObject* obj, UiToggleArgs) { + return nullptr; +} diff -r 4a8b1a748f09 -r 5db4979bf482 ui/winui/container.cpp --- a/ui/winui/container.cpp Sun Sep 24 12:03:57 2023 +0200 +++ b/ui/winui/container.cpp Sun Oct 01 09:23:47 2023 +0200 @@ -189,8 +189,11 @@ control.HorizontalAlignment(HorizontalAlignment::Stretch); control.VerticalAlignment(VerticalAlignment::Stretch); - if (layout.gridwidth > 0) { - grid.SetColumnSpan(control, layout.gridwidth); + if (layout.colspan > 0) { + grid.SetColumnSpan(control, layout.colspan); + } + if (layout.rowspan > 0) { + grid.SetRowSpan(control, layout.rowspan); } grid.SetRow(control, y); @@ -229,9 +232,19 @@ ct->layout.width = width; } -void ui_layout_gridwidth(UiObject* obj, int width) { +void ui_layout_height(UiObject* obj, int height) { + UiContainer* ct = uic_get_current_container(obj); + ct->layout.height = height; +} + +void ui_layout_colspan(UiObject* obj, int cols) { UiContainer* ct = uic_get_current_container(obj); - ct->layout.gridwidth = width; + ct->layout.colspan = cols; +} + +void ui_layout_rowspan(UiObject* obj, int rows) { + UiContainer* ct = uic_get_current_container(obj); + ct->layout.rowspan = rows; } void ui_newline(UiObject* obj) { diff -r 4a8b1a748f09 -r 5db4979bf482 ui/winui/container.h --- a/ui/winui/container.h Sun Sep 24 12:03:57 2023 +0200 +++ b/ui/winui/container.h Sun Oct 01 09:23:47 2023 +0200 @@ -68,7 +68,9 @@ UiBool hexpand; UiBool vexpand; int width; - int gridwidth; + int height; + int colspan; + int rowspan; }; struct UiContainer { diff -r 4a8b1a748f09 -r 5db4979bf482 ui/winui/winui.vcxproj --- a/ui/winui/winui.vcxproj Sun Sep 24 12:03:57 2023 +0200 +++ b/ui/winui/winui.vcxproj Sun Oct 01 09:23:47 2023 +0200 @@ -168,6 +168,23 @@ + + + + + + + + + + + + + + + + + diff -r 4a8b1a748f09 -r 5db4979bf482 ui/winui/winui.vcxproj.filters --- a/ui/winui/winui.vcxproj.filters Sun Sep 24 12:03:57 2023 +0200 +++ b/ui/winui/winui.vcxproj.filters Sun Oct 01 09:23:47 2023 +0200 @@ -19,6 +19,9 @@ {e701397e-2637-4a23-a260-1d3259292fa8} + + {135ba0dc-0817-4d23-b816-1ac0fa785bb9} + @@ -104,5 +107,56 @@ Headerdateien + + public + + + public + + + public + + + public + + + public + + + public + + + public + + + public + + + public + + + public + + + public + + + public + + + public + + + public + + + public + + + public + + + public + \ No newline at end of file