# HG changeset patch # User Olaf Wintermann # Date 1707662673 -3600 # Node ID 7d176764756d3a401e8f86a2295fc3d3bcbf89cb # Parent 22dc0b739dd87a87e2c8cedf471430c036a716ed add input option to ui_dialog diff -r 22dc0b739dd8 -r 7d176764756d make/vs/testapp/main.c --- a/make/vs/testapp/main.c Sun Feb 11 13:59:40 2024 +0100 +++ b/make/vs/testapp/main.c Sun Feb 11 15:44:33 2024 +0100 @@ -185,11 +185,12 @@ } void dialog_result(UiEvent *evt, void *data) { + char *str = evt->eventdata; printf("dialog: %d\n", (int)evt->intval); } void btn_dialog(UiEvent *evt, void *data) { - ui_dialog(evt->obj, .title = "Title", .content = "Hello World", .button1_label = "Yes", .button2_label = "No", .closebutton_label = "Close", .result = dialog_result); + ui_dialog(evt->obj, .title = "Title", .input = TRUE, .content = "Hello World", .button1_label = "Yes", .button2_label = "No", .closebutton_label = "Close", .result = dialog_result); } diff -r 22dc0b739dd8 -r 7d176764756d ui/ui/window.h --- a/ui/ui/window.h Sun Feb 11 13:59:40 2024 +0100 +++ b/ui/ui/window.h Sun Feb 11 15:44:33 2024 +0100 @@ -45,6 +45,7 @@ const char *button1_label; const char *button2_label; const char *closebutton_label; + UiBool input; ui_callback result; void *resultdata; } UiDialogArgs; diff -r 22dc0b739dd8 -r 7d176764756d ui/winui/window.cpp --- a/ui/winui/window.cpp Sun Feb 11 13:59:40 2024 +0100 +++ b/ui/winui/window.cpp Sun Feb 11 15:44:33 2024 +0100 @@ -220,16 +220,41 @@ dialog.Title(winrt::box_value(str)); free(str); } - if (args.content) { - wchar_t *str = str2wstr(args.content, nullptr); - dialog.Content(winrt::box_value(str)); - free(str); + + TextBox textfield{ nullptr }; + if (args.input) { + StackPanel panel = StackPanel(); + panel.Orientation(Orientation::Vertical); + if (args.content) { + wchar_t *str = str2wstr(args.content, nullptr); + TextBlock label = TextBlock(); + label.Text(str); + panel.Children().Append(label); + free(str); + } + + textfield = TextBox(); + Thickness margin = { 0, 5, 0, 0 }; + textfield.Margin(margin); + panel.Margin(margin); + + panel.Children().Append(textfield); + + dialog.Content(panel); + + } else { + if (args.content) { + wchar_t *str = str2wstr(args.content, nullptr); + dialog.Content(winrt::box_value(str)); + free(str); + } } if (args.button1_label) { wchar_t *str = str2wstr(args.button1_label, nullptr); dialog.PrimaryButtonText(winrt::hstring(str)); free(str); + dialog.DefaultButton(ContentDialogButton::Primary); } if (args.button2_label) { wchar_t *str = str2wstr(args.button2_label, nullptr); @@ -257,7 +282,17 @@ evt.intval = 2; } + if (args.input) { + std::wstring wstr(textfield.Text()); + char *text = wchar2utf8(wstr.c_str(), wstr.length()); + evt.eventdata = text; + } + args.result(&evt, args.resultdata); + + if (evt.eventdata) { + free(evt.eventdata); + } } }