Sun, 10 Nov 2024 15:27:44 +0100
implement some missing WinUI functions
--- a/ui/common/properties.c Sun Nov 10 10:16:47 2024 +0100 +++ b/ui/common/properties.c Sun Nov 10 15:27:44 2024 +0100 @@ -32,6 +32,9 @@ #include <sys/stat.h> #include <errno.h> +#include "../ui/toolkit.h" + + #include "properties.h" #include <cx/string.h> #include <cx/buffer.h> @@ -48,11 +51,12 @@ #endif -char* ui_getappdir() { + +char* ui_getappdir(void) { if(ui_appname() == NULL) { return NULL; } - + return ui_configfile(NULL); } @@ -296,4 +300,3 @@ } return cxMapGet(language, name); } -
--- a/ui/common/toolbar.c Sun Nov 10 10:16:47 2024 +0100 +++ b/ui/common/toolbar.c Sun Nov 10 15:27:44 2024 +0100 @@ -37,6 +37,7 @@ static UiToolbarMenuItem* ui_appmenu; + void uic_toolbar_init(void) { toolbar_items = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 16); toolbar_defaults[0] = cxLinkedListCreateSimple(CX_STORE_POINTERS);
--- a/ui/common/types.c Sun Nov 10 10:16:47 2024 +0100 +++ b/ui/common/types.c Sun Nov 10 15:27:44 2024 +0100 @@ -37,6 +37,8 @@ #include "types.h" #include "context.h" + + UiObserver* ui_observer_new(ui_callback f, void *data) { UiObserver *observer = malloc(sizeof(UiObserver)); observer->callback = f;
--- a/ui/gtk/container.c Sun Nov 10 10:16:47 2024 +0100 +++ b/ui/gtk/container.c Sun Nov 10 15:27:44 2024 +0100 @@ -180,11 +180,29 @@ int hexpand = FALSE; int vexpand = FALSE; + int hfill = FALSE; + int vfill = FALSE; + if(ct->layout.fill != UI_LAYOUT_UNDEFINED) { + fill = ui_lb2bool(ct->layout.fill); + } if(ct->layout.hexpand != UI_LAYOUT_UNDEFINED) { hexpand = ct->layout.hexpand; + hfill = TRUE; } if(ct->layout.vexpand != UI_LAYOUT_UNDEFINED) { vexpand = ct->layout.vexpand; + vfill = TRUE; + } + if(fill) { + hfill = TRUE; + vfill = TRUE; + } + + if(!hfill) { + gtk_widget_set_halign(widget, GTK_ALIGN_START); + } + if(!vfill) { + gtk_widget_set_valign(widget, GTK_ALIGN_START); } gtk_widget_set_hexpand(widget, hexpand); @@ -917,6 +935,16 @@ ct->layout.vexpand = expand; } +void ui_layout_hfill(UiObject *obj, UiBool fill) { + UiContainer *ct = uic_get_current_container(obj); + ct->layout.hfill = fill; +} + +void ui_layout_vfill(UiObject *obj, UiBool fill) { + UiContainer *ct = uic_get_current_container(obj); + ct->layout.vfill = fill; +} + void ui_layout_colspan(UiObject* obj, int cols) { UiContainer* ct = uic_get_current_container(obj); ct->layout.colspan = cols;
--- a/ui/gtk/container.h Sun Nov 10 10:16:47 2024 +0100 +++ b/ui/gtk/container.h Sun Nov 10 15:27:44 2024 +0100 @@ -62,6 +62,8 @@ char *label; UiBool hexpand; UiBool vexpand; + UiBool hfill; + UiBool vfill; int width; int colspan; int rowspan;
--- a/ui/ui/button.h Sun Nov 10 10:16:47 2024 +0100 +++ b/ui/ui/button.h Sun Nov 10 15:27:44 2024 +0100 @@ -39,6 +39,8 @@ UiTri fill; UiBool hexpand; UiBool vexpand; + UiBool hfill; + UiBool vfill; int colspan; int rowspan; const char *name; @@ -58,6 +60,8 @@ UiTri fill; UiBool hexpand; UiBool vexpand; + UiBool hfill; + UiBool vfill; int colspan; int rowspan; const char *name;
--- a/ui/ui/container.h Sun Nov 10 10:16:47 2024 +0100 +++ b/ui/ui/container.h Sun Nov 10 15:27:44 2024 +0100 @@ -61,6 +61,8 @@ UiTri fill; UiBool hexpand; UiBool vexpand; + UiBool hfill; + UiBool vfill; int colspan; int rowspan; const char *name; @@ -76,6 +78,8 @@ UiTri fill; UiBool hexpand; UiBool vexpand; + UiBool hfill; + UiBool vfill; int colspan; int rowspan; const char *name; @@ -96,6 +100,8 @@ UiTri fill; UiBool hexpand; UiBool vexpand; + UiBool hfill; + UiBool vfill; int colspan; int rowspan; const char *name; @@ -121,6 +127,8 @@ UiTri fill; UiBool hexpand; UiBool vexpand; + UiBool hfill; + UiBool vfill; int colspan; int rowspan; const char *name; @@ -195,6 +203,8 @@ // grid container layout functions UIEXPORT void ui_layout_hexpand(UiObject *obj, UiBool expand); UIEXPORT void ui_layout_vexpand(UiObject *obj, UiBool expand); +UIEXPORT void ui_layout_hfill(UiObject *obj, UiBool fill); +UIEXPORT void ui_layout_vfill(UiObject *obj, UiBool fill); UIEXPORT void ui_layout_width(UiObject *obj, int width); UIEXPORT void ui_layout_height(UiObject* obj, int width); UIEXPORT void ui_layout_colspan(UiObject *obj, int cols); @@ -214,6 +224,8 @@ 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.hfill) ui_layout_hfill(obj, 1); \ + if(args.vfill) ui_layout_vfill(obj, 1); \ if(args.colspan > 0) ui_layout_colspan(obj, args.colspan); \ if(args.rowspan > 0) ui_layout_rowspan(obj, args.rowspan); \ /*force caller to add ';'*/(void)0
--- a/ui/ui/display.h Sun Nov 10 10:16:47 2024 +0100 +++ b/ui/ui/display.h Sun Nov 10 15:27:44 2024 +0100 @@ -61,6 +61,8 @@ UiTri fill; UiBool hexpand; UiBool vexpand; + UiBool hfill; + UiBool vfill; int colspan; int rowspan; @@ -75,6 +77,8 @@ UiTri fill; UiBool hexpand; UiBool vexpand; + UiBool hfill; + UiBool vfill; int colspan; int rowspan; int width; @@ -89,6 +93,8 @@ UiTri fill; UiBool hexpand; UiBool vexpand; + UiBool hfill; + UiBool vfill; int colspan; int rowspan;
--- a/ui/ui/entry.h Sun Nov 10 10:16:47 2024 +0100 +++ b/ui/ui/entry.h Sun Nov 10 15:27:44 2024 +0100 @@ -40,6 +40,8 @@ UiTri fill; UiBool hexpand; UiBool vexpand; + UiBool hfill; + UiBool vfill; int colspan; int rowspan; const char *name;
--- a/ui/ui/image.h Sun Nov 10 10:16:47 2024 +0100 +++ b/ui/ui/image.h Sun Nov 10 15:27:44 2024 +0100 @@ -41,6 +41,8 @@ UiTri fill; UiBool hexpand; UiBool vexpand; + UiBool hfill; + UiBool vfill; int colspan; int rowspan; const char *name;
--- a/ui/ui/text.h Sun Nov 10 10:16:47 2024 +0100 +++ b/ui/ui/text.h Sun Nov 10 15:27:44 2024 +0100 @@ -39,6 +39,8 @@ UiTri fill; UiBool hexpand; UiBool vexpand; + UiBool hfill; + UiBool vfill; int colspan; int rowspan; int width; @@ -57,6 +59,8 @@ UiTri fill; UiBool hexpand; UiBool vexpand; + UiBool hfill; + UiBool vfill; int colspan; int rowspan; int width; @@ -86,6 +90,8 @@ UiTri fill; UiBool hexpand; UiBool vexpand; + UiBool hfill; + UiBool vfill; int colspan; int rowspan; const char *name;
--- a/ui/ui/toolkit.h Sun Nov 10 10:16:47 2024 +0100 +++ b/ui/ui/toolkit.h Sun Nov 10 15:27:44 2024 +0100 @@ -543,7 +543,7 @@ UIEXPORT UiStr ui_str_free(char *str, void (*free)(void *v)); -UIEXPORT char* ui_getappdir(); +UIEXPORT char* ui_getappdir(void); UIEXPORT char* ui_configfile(char *name); UIEXPORT UiCondVar* ui_condvar_create(void);
--- a/ui/ui/tree.h Sun Nov 10 10:16:47 2024 +0100 +++ b/ui/ui/tree.h Sun Nov 10 15:27:44 2024 +0100 @@ -103,6 +103,8 @@ UiTri fill; UiBool hexpand; UiBool vexpand; + UiBool hfill; + UiBool vfill; int colspan; int rowspan; const char *name;
--- a/ui/winui/container.cpp Sun Nov 10 10:16:47 2024 +0100 +++ b/ui/winui/container.cpp Sun Nov 10 15:27:44 2024 +0100 @@ -1,30 +1,30 @@ /* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 2023 Olaf Wintermann. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. +* +* Copyright 2023 Olaf Wintermann. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +*/ #include "pch.h" @@ -122,7 +122,7 @@ gl.Value = 0; gl.GridUnitType = GridUnitType::Auto; } - + control.HorizontalAlignment(HorizontalAlignment::Stretch); control.VerticalAlignment(VerticalAlignment::Stretch); @@ -237,9 +237,31 @@ cols++; } else if(hexpand) { // adjust column - gl.GridUnitType = GridUnitType::Star; - gl.Value = 1; - grid.ColumnDefinitions().GetAt(x).Width(gl); + if (layout.colspan == 0) { + gl.GridUnitType = GridUnitType::Star; + gl.Value = 1; + grid.ColumnDefinitions().GetAt(x).Width(gl); + } else { + int adjust_col = x; + bool adjust = true; + for (int i = 0; i < layout.colspan; i++) { + if (grid.ColumnDefinitions().Size() == x + i) { + break; + } + adjust_col = x + i; + GridLength w = grid.ColumnDefinitions().GetAt(adjust_col).Width(); + if (w.GridUnitType == GridUnitType::Star) { + adjust = false; + break; + } + } + + if (adjust) { + gl.GridUnitType = GridUnitType::Star; + gl.Value = 1; + grid.ColumnDefinitions().GetAt(adjust_col).Width(gl); + } + } } // add control @@ -302,7 +324,7 @@ frame.SetColumn(label, 0); frame.Children().Append(label); } - + // workarea frame frame.RowDefinitions().Append(rowdefFrame); @@ -485,9 +507,17 @@ return newobj; } +static UiTabView* tabview_pivot_create(UiObject* obj, UiTabViewArgs args) { + Pivot pivot = Pivot(); + UiPivotTabView* tabview = new UiPivotTabView(obj, pivot, args); + + return tabview; +} + UiPivotTabView::UiPivotTabView(UiObject* obj, Pivot pivot, UiTabViewArgs args) { this->current = obj; this->pivot = pivot; + this->subcontainer = args.subcontainer; this->margin = args.margin; this->spacing = args.spacing; this->columnspacing = args.columnspacing; @@ -516,20 +546,99 @@ pivot.Items().RemoveAt(index); } +void UiPivotTabView::Select(int index) { + +} + FrameworkElement UiPivotTabView::GetFrameworkElement() { return pivot; } -static UiTabView* tabview_pivot_create(UiObject* obj, UiTabViewArgs args) { - Pivot pivot = Pivot(); - UiPivotTabView* tabview = new UiPivotTabView(obj, pivot, args); + +static UiTabView* tabview_invisible_create(UiObject *obj, UiTabViewArgs args) { + Grid container = Grid(); + container.HorizontalAlignment(HorizontalAlignment::Stretch); + container.VerticalAlignment(VerticalAlignment::Stretch); + UiInvisibleTabView *tabview = new UiInvisibleTabView(obj, container, args); + return tabview; +} + +UiInvisibleTabView::UiInvisibleTabView(UiObject* obj, Grid container, UiTabViewArgs args) { + this->current = obj; + this->container = container; + this->subcontainer = args.subcontainer; + this->margin = args.margin; + this->spacing = args.spacing; + this->columnspacing = args.columnspacing; + this->rowspacing = args.rowspacing; + this->currentIndex = -1; + + GridLength gl; + gl.GridUnitType = GridUnitType::Star; + gl.Value = 1; + + ColumnDefinition coldef = ColumnDefinition(); + coldef.Width(gl); + container.ColumnDefinitions().Append(coldef); + + RowDefinition rowdef = RowDefinition(); + rowdef.Height(gl); + container.RowDefinitions().Append(rowdef); +} - return tabview; +UiObject* UiInvisibleTabView::AddTab(const char* label, int index) { + Grid subcontainer = Grid(); + subcontainer.HorizontalAlignment(HorizontalAlignment::Stretch); + subcontainer.VerticalAlignment(VerticalAlignment::Stretch); + + if (pages.size() == 0) { + container.Children().Append(subcontainer); + currentIndex = 0; + } + + if (index < 0) { + pages.push_back(subcontainer); + } else { + pages.insert(pages.begin() + index, subcontainer); + } + + // sub container + return create_subcontainer_obj(current, subcontainer, this->subcontainer, margin, spacing, columnspacing, rowspacing); +} + +void UiInvisibleTabView::Remove(int index) { + +} + +void UiInvisibleTabView::Select(int index) { + if (index >= 0 && index < pages.size()) { + if (currentIndex != -1) { + container.Children().RemoveAt(0); + } + + container.Children().Append(pages.at(index)); + } +} + +FrameworkElement UiInvisibleTabView::GetFrameworkElement() { + return container; +} + + +static UiTabView* tabview_main_create(UiObject* obj, UiTabViewArgs args) { + TabView tabview = TabView(); + tabview.IsAddTabButtonVisible(false); + //tabview.CanDragTabs(false); + //tabview.CanReorderTabs(false); + UiMainTabView* uitabview = new UiMainTabView(obj, tabview, args); + + return uitabview; } UiMainTabView::UiMainTabView(UiObject* obj, TabView tabview, UiTabViewArgs args) { this->current = obj; this->tabview = tabview; + this->subcontainer = args.subcontainer; this->margin = args.margin; this->spacing = args.spacing; this->columnspacing = args.columnspacing; @@ -560,18 +669,22 @@ this->tabview.TabItems().RemoveAt(index); } +void UiMainTabView::Select(int index) { + +} + FrameworkElement UiMainTabView::GetFrameworkElement() { return tabview; } -static UiTabView* tabview_main_create(UiObject* obj, UiTabViewArgs args) { - TabView tabview = TabView(); - tabview.IsAddTabButtonVisible(false); - //tabview.CanDragTabs(false); - //tabview.CanReorderTabs(false); - UiMainTabView* uitabview = new UiMainTabView(obj, tabview, args); - return uitabview; +static UiTabView* tabview_navigationview_create(UiObject* obj, UiTabViewArgs args, UiTabViewType type) { + NavigationView navigationview = NavigationView(); + UiNavigationTabView* tabview = new UiNavigationTabView(obj, navigationview, args, type); + navigationview.IsBackButtonVisible(NavigationViewBackButtonVisible::Collapsed); + navigationview.IsSettingsVisible(false); + + return tabview; } UiNavigationTabView::UiNavigationTabView(UiObject* obj, NavigationView navigationview, UiTabViewArgs args, UiTabViewType type) { @@ -619,6 +732,10 @@ pages.erase(pages.begin() + index); } +void UiNavigationTabView::Select(int index) { + +} + FrameworkElement UiNavigationTabView::GetFrameworkElement() { return navigationview; } @@ -634,13 +751,13 @@ } } -static UiTabView* tabview_navigationview_create(UiObject* obj, UiTabViewArgs args, UiTabViewType type) { - NavigationView navigationview = NavigationView(); - UiNavigationTabView* tabview = new UiNavigationTabView(obj, navigationview, args, type); - navigationview.IsBackButtonVisible(NavigationViewBackButtonVisible::Collapsed); - navigationview.IsSettingsVisible(false); +static int64_t ui_tabview_get(UiInteger *i) { + return 0; +} - return tabview; +static void ui_tabview_set(UiInteger *i, int64_t value) { + UiTabView *tabview = (UiTabView*)i->obj; + tabview->Select(value); } UIWIDGET ui_tabview_create(UiObject* obj, UiTabViewArgs args) { @@ -667,6 +784,10 @@ tabview = tabview_pivot_create(obj, args); break; } + case UI_TABVIEW_INVISIBLE: { + tabview = tabview_invisible_create(obj, args); + break; + } } UiTabViewContainer* ctn = new UiTabViewContainer(tabview); @@ -680,6 +801,17 @@ ui_context_add_widget_destructor(current->ctx, widget); widget->data1 = tabview; + // TODO: add tabview destructor + + // bind variable + UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_INTEGER); + if (var) { + UiInteger *i = (UiInteger*)var->value; + i->obj = tabview; + i->get = ui_tabview_get; + i->set = ui_tabview_set; + } + UiObject* newobj = uic_object_new(obj, widget); newobj->container = ctn; uic_obj_add(obj, newobj); @@ -696,7 +828,7 @@ UIEXPORT void ui_tabview_select(UIWIDGET tabview, int tab) { UiTabView* t = (UiTabView*)tabview->data1; - t->Remove(tab); + t->Select(tab); } UIEXPORT void ui_tabview_remove(UIWIDGET tabview, int tab) { @@ -742,11 +874,11 @@ /* - * -------------------- Layout Functions -------------------- - * - * functions for setting layout attributes for the current container - * - */ +* -------------------- Layout Functions -------------------- +* +* functions for setting layout attributes for the current container +* +*/ void ui_layout_fill(UiObject* obj, UiBool fill) { UiContainer* ct = uic_get_current_container(obj); @@ -763,6 +895,16 @@ ct->layout.vexpand = expand; } +void ui_layout_hfill(UiObject* obj, UiBool fill) { + UiContainer* ct = uic_get_current_container(obj); + ct->layout.hfill = fill; +} + +void ui_layout_vfill(UiObject* obj, UiBool fill) { + UiContainer* ct = uic_get_current_container(obj); + ct->layout.vfill = fill; +} + void ui_layout_width(UiObject* obj, int width) { UiContainer* ct = uic_get_current_container(obj); ct->layout.width = width;
--- a/ui/winui/container.h Sun Nov 10 10:16:47 2024 +0100 +++ b/ui/winui/container.h Sun Nov 10 15:27:44 2024 +0100 @@ -67,6 +67,8 @@ char* label; UiBool hexpand; UiBool vexpand; + UiBool hfill; + UiBool vfill; int width; int height; int colspan; @@ -122,7 +124,7 @@ virtual UiObject* AddTab(const char* label, int index = -1) = 0; virtual void Remove(int index) = 0; - + virtual void Select(int index) = 0; virtual FrameworkElement GetFrameworkElement() = 0; }; @@ -141,6 +143,7 @@ UiObject* AddTab(const char* label, int index = -1); void Remove(int index); + void Select(int index); FrameworkElement GetFrameworkElement(); }; @@ -151,6 +154,7 @@ UiObject* AddTab(const char* label, int index = -1); void Remove(int index); + void Select(int index); FrameworkElement GetFrameworkElement(); }; @@ -163,7 +167,21 @@ UiObject* AddTab(const char* label, int index = -1); void Remove(int index); + void Select(int index); FrameworkElement GetFrameworkElement(); void SelectionChanged(NavigationView const& sender, NavigationViewSelectionChangedEventArgs const& args); }; + +struct UiInvisibleTabView : UiTabView { + Grid container; + std::vector<FrameworkElement> pages; + int currentIndex; + + UiInvisibleTabView(UiObject *obj, Grid container, UiTabViewArgs args); + + UiObject* AddTab(const char* label, int index = -1); + void Remove(int index); + void Select(int index); + FrameworkElement GetFrameworkElement(); +}; \ No newline at end of file
--- a/ui/winui/list.cpp Sun Nov 10 10:16:47 2024 +0100 +++ b/ui/winui/list.cpp Sun Nov 10 15:27:44 2024 +0100 @@ -70,7 +70,10 @@ if (var) { UiList* list = (UiList*)var->value; list->update = ui_simple_list_update; + list->getselection = ui_listview_getselection; + list->setselection = ui_listview_setselection; list->obj = widget; + ui_simple_list_update(list, 0); } @@ -138,6 +141,8 @@ if (var) { UiList* list = (UiList*)var->value; list->update = ui_simple_list_update; + list->getselection = ui_dropdown_getselection; + list->setselection = ui_dropdown_setselection; list->obj = widget; ui_simple_list_update(list, 0); } @@ -169,6 +174,51 @@ return widget; } +UiListSelection ui_listview_getselection(UiList *list) { + UiWidget *widget = (UiWidget*)list->obj; + ListView listview = widget->uielement.as<ListView>(); + std::vector<int> selectedRows = ui_create_listview_selection(listview); + + UiListSelection selection = { NULL, 0 }; + if (selectedRows.size() > 0) { + selection.count = selectedRows.size(); + int *data = selectedRows.data(); + selection.rows = (int*)calloc(selection.count, sizeof(int)); + memcpy(selection.rows, data, selection.count); + } + + return selection; +} + +void ui_listview_setselection(UiList *list, UiListSelection selection) { + UiWidget* widget = (UiWidget*)list->obj; + if (selection.count > 0) { + ListView listview = widget->uielement.as<ListView>(); + listview.SelectedIndex(selection.rows[0]); + } +} + +UiListSelection ui_dropdown_getselection(UiList *list) { + UiWidget* widget = (UiWidget*)list->obj; + ComboBox cb = widget->uielement.as<ComboBox>(); + int index = cb.SelectedIndex(); + UiListSelection selection = { NULL, 0 }; + if (index >= 0) { + selection.rows = (int*)calloc(1, sizeof(int)); + selection.count = 1; + selection.rows[0] = index; + } + return selection; +} + +void ui_dropdown_setselection(UiList *list, UiListSelection selection) { + UiWidget* widget = (UiWidget*)list->obj; + if (selection.count > 0) { + ComboBox cb = widget->uielement.as<ComboBox>(); + cb.SelectedIndex(selection.rows[0]); + } +} + UIEXPORT UIWIDGET ui_breadcrumbbar_create(UiObject* obj, UiListArgs args) { UiObject* current = uic_current_obj(obj);
--- a/ui/winui/list.h Sun Nov 10 10:16:47 2024 +0100 +++ b/ui/winui/list.h Sun Nov 10 15:27:44 2024 +0100 @@ -40,3 +40,8 @@ std::vector<int> ui_create_listview_selection(winrt::Microsoft::UI::Xaml::Controls::ListView listview); +extern "C" UiListSelection ui_listview_getselection(UiList *list); +extern "C" void ui_listview_setselection(UiList *list, UiListSelection selection); + +extern "C" UiListSelection ui_dropdown_getselection(UiList *list); +extern "C" void ui_dropdown_setselection(UiList *list, UiListSelection selection);
--- a/ui/winui/packages.config Sun Nov 10 10:16:47 2024 +0100 +++ b/ui/winui/packages.config Sun Nov 10 15:27:44 2024 +0100 @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="utf-8"?> <packages> - <package id="Microsoft.Windows.CppWinRT" version="2.0.240111.5" targetFramework="native" /> - <package id="Microsoft.Windows.ImplementationLibrary" version="1.0.240122.1" targetFramework="native" /> - <package id="Microsoft.Windows.SDK.BuildTools" version="10.0.22621.3233" targetFramework="native" /> + <package id="Microsoft.Windows.CppWinRT" version="2.0.240405.15" targetFramework="native" /> + <package id="Microsoft.Windows.ImplementationLibrary" version="1.0.240803.1" targetFramework="native" /> + <package id="Microsoft.Windows.SDK.BuildTools" version="10.0.26100.1742" targetFramework="native" /> <package id="Microsoft.WindowsAppSDK" version="1.5.241001000" targetFramework="native" /> </packages> \ No newline at end of file
--- a/ui/winui/window.cpp Sun Nov 10 10:16:47 2024 +0100 +++ b/ui/winui/window.cpp Sun Nov 10 15:27:44 2024 +0100 @@ -65,12 +65,14 @@ UiObject* ui_window(const char* title, void* window_data) { UiObject* obj = ui_simple_window(title, window_data); + /* if (uic_get_menu_list()) { // create/add menubar MenuBar mb = ui_create_menubar(obj); mb.VerticalAlignment(VerticalAlignment::Top); obj->container->Add(mb, false); } + */ if (uic_toolbar_isenabled()) { // create a grid for the toolbar: ColumnDefinitions="Auto, *, Auto" @@ -230,7 +232,8 @@ } TextBox textfield{ nullptr }; - if (args.input) { + PasswordBox password{ nullptr }; + if(args.input || args.password) { StackPanel panel = StackPanel(); panel.Orientation(Orientation::Vertical); if (args.content) { @@ -241,13 +244,19 @@ free(str); } - textfield = TextBox(); Thickness margin = { 0, 5, 0, 0 }; - textfield.Margin(margin); + if (args.password) { + password = PasswordBox(); + password.Margin(margin); + panel.Children().Append(password); + } else { + textfield = TextBox(); + textfield.Margin(margin); + panel.Children().Append(textfield); + } + panel.Margin(margin); - panel.Children().Append(textfield); - dialog.Content(panel); } else { @@ -290,7 +299,11 @@ evt.intval = 2; } - if (args.input) { + if (args.password) { + std::wstring wstr(password.Password()); + char *text = wchar2utf8(wstr.c_str(), wstr.length()); + evt.eventdata = text; + } else if (args.input) { std::wstring wstr(textfield.Text()); char *text = wchar2utf8(wstr.c_str(), wstr.length()); evt.eventdata = text;
--- a/ui/winui/winui.vcxproj Sun Nov 10 10:16:47 2024 +0100 +++ b/ui/winui/winui.vcxproj Sun Nov 10 15:27:44 2024 +0100 @@ -1,8 +1,8 @@ <?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="..\..\make\vs\packages\Microsoft.Windows.SDK.BuildTools.10.0.26100.1742\build\Microsoft.Windows.SDK.BuildTools.props" Condition="Exists('..\..\make\vs\packages\Microsoft.Windows.SDK.BuildTools.10.0.26100.1742\build\Microsoft.Windows.SDK.BuildTools.props')" /> + <Import Project="..\..\make\vs\packages\Microsoft.Windows.CppWinRT.2.0.240405.15\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('..\..\make\vs\packages\Microsoft.Windows.CppWinRT.2.0.240405.15\build\native\Microsoft.Windows.CppWinRT.props')" /> <Import Project="..\..\make\vs\packages\Microsoft.WindowsAppSDK.1.5.241001000\build\native\Microsoft.WindowsAppSDK.props" Condition="Exists('..\..\make\vs\packages\Microsoft.WindowsAppSDK.1.5.241001000\build\native\Microsoft.WindowsAppSDK.props')" /> - <Import Project="..\..\make\vs\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('..\..\make\vs\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.props')" /> - <Import Project="..\..\make\vs\packages\Microsoft.Windows.SDK.BuildTools.10.0.22621.3233\build\Microsoft.Windows.SDK.BuildTools.props" Condition="Exists('..\..\make\vs\packages\Microsoft.Windows.SDK.BuildTools.10.0.22621.3233\build\Microsoft.Windows.SDK.BuildTools.props')" /> <PropertyGroup Label="Globals"> <CppWinRTOptimized>true</CppWinRTOptimized> <CppWinRTRootNamespaceAutoMerge>true</CppWinRTRootNamespaceAutoMerge> @@ -244,21 +244,21 @@ </PropertyGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> - <Import Project="..\..\make\vs\packages\Microsoft.Windows.SDK.BuildTools.10.0.22621.3233\build\Microsoft.Windows.SDK.BuildTools.targets" Condition="Exists('..\..\make\vs\packages\Microsoft.Windows.SDK.BuildTools.10.0.22621.3233\build\Microsoft.Windows.SDK.BuildTools.targets')" /> - <Import Project="..\..\make\vs\packages\Microsoft.Windows.ImplementationLibrary.1.0.240122.1\build\native\Microsoft.Windows.ImplementationLibrary.targets" Condition="Exists('..\..\make\vs\packages\Microsoft.Windows.ImplementationLibrary.1.0.240122.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" /> - <Import Project="..\..\make\vs\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('..\..\make\vs\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.targets')" /> <Import Project="..\..\make\vs\packages\Microsoft.WindowsAppSDK.1.5.241001000\build\native\Microsoft.WindowsAppSDK.targets" Condition="Exists('..\..\make\vs\packages\Microsoft.WindowsAppSDK.1.5.241001000\build\native\Microsoft.WindowsAppSDK.targets')" /> + <Import Project="..\..\make\vs\packages\Microsoft.Windows.CppWinRT.2.0.240405.15\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('..\..\make\vs\packages\Microsoft.Windows.CppWinRT.2.0.240405.15\build\native\Microsoft.Windows.CppWinRT.targets')" /> + <Import Project="..\..\make\vs\packages\Microsoft.Windows.ImplementationLibrary.1.0.240803.1\build\native\Microsoft.Windows.ImplementationLibrary.targets" Condition="Exists('..\..\make\vs\packages\Microsoft.Windows.ImplementationLibrary.1.0.240803.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" /> + <Import Project="..\..\make\vs\packages\Microsoft.Windows.SDK.BuildTools.10.0.26100.1742\build\Microsoft.Windows.SDK.BuildTools.targets" Condition="Exists('..\..\make\vs\packages\Microsoft.Windows.SDK.BuildTools.10.0.26100.1742\build\Microsoft.Windows.SDK.BuildTools.targets')" /> </ImportGroup> <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> <PropertyGroup> <ErrorText>Dieses Projekt verweist auf mindestens ein NuGet-Paket, das auf diesem Computer fehlt. Verwenden Sie die Wiederherstellung von NuGet-Paketen, um die fehlenden Dateien herunterzuladen. Weitere Informationen finden Sie unter "http://go.microsoft.com/fwlink/?LinkID=322105". Die fehlende Datei ist "{0}".</ErrorText> </PropertyGroup> - <Error Condition="!Exists('..\..\make\vs\packages\Microsoft.Windows.SDK.BuildTools.10.0.22621.3233\build\Microsoft.Windows.SDK.BuildTools.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\make\vs\packages\Microsoft.Windows.SDK.BuildTools.10.0.22621.3233\build\Microsoft.Windows.SDK.BuildTools.props'))" /> - <Error Condition="!Exists('..\..\make\vs\packages\Microsoft.Windows.SDK.BuildTools.10.0.22621.3233\build\Microsoft.Windows.SDK.BuildTools.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\make\vs\packages\Microsoft.Windows.SDK.BuildTools.10.0.22621.3233\build\Microsoft.Windows.SDK.BuildTools.targets'))" /> - <Error Condition="!Exists('..\..\make\vs\packages\Microsoft.Windows.ImplementationLibrary.1.0.240122.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\make\vs\packages\Microsoft.Windows.ImplementationLibrary.1.0.240122.1\build\native\Microsoft.Windows.ImplementationLibrary.targets'))" /> - <Error Condition="!Exists('..\..\make\vs\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\make\vs\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.props'))" /> - <Error Condition="!Exists('..\..\make\vs\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\make\vs\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.targets'))" /> <Error Condition="!Exists('..\..\make\vs\packages\Microsoft.WindowsAppSDK.1.5.241001000\build\native\Microsoft.WindowsAppSDK.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\make\vs\packages\Microsoft.WindowsAppSDK.1.5.241001000\build\native\Microsoft.WindowsAppSDK.props'))" /> <Error Condition="!Exists('..\..\make\vs\packages\Microsoft.WindowsAppSDK.1.5.241001000\build\native\Microsoft.WindowsAppSDK.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\make\vs\packages\Microsoft.WindowsAppSDK.1.5.241001000\build\native\Microsoft.WindowsAppSDK.targets'))" /> + <Error Condition="!Exists('..\..\make\vs\packages\Microsoft.Windows.CppWinRT.2.0.240405.15\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\make\vs\packages\Microsoft.Windows.CppWinRT.2.0.240405.15\build\native\Microsoft.Windows.CppWinRT.props'))" /> + <Error Condition="!Exists('..\..\make\vs\packages\Microsoft.Windows.CppWinRT.2.0.240405.15\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\make\vs\packages\Microsoft.Windows.CppWinRT.2.0.240405.15\build\native\Microsoft.Windows.CppWinRT.targets'))" /> + <Error Condition="!Exists('..\..\make\vs\packages\Microsoft.Windows.ImplementationLibrary.1.0.240803.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\make\vs\packages\Microsoft.Windows.ImplementationLibrary.1.0.240803.1\build\native\Microsoft.Windows.ImplementationLibrary.targets'))" /> + <Error Condition="!Exists('..\..\make\vs\packages\Microsoft.Windows.SDK.BuildTools.10.0.26100.1742\build\Microsoft.Windows.SDK.BuildTools.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\make\vs\packages\Microsoft.Windows.SDK.BuildTools.10.0.26100.1742\build\Microsoft.Windows.SDK.BuildTools.props'))" /> + <Error Condition="!Exists('..\..\make\vs\packages\Microsoft.Windows.SDK.BuildTools.10.0.26100.1742\build\Microsoft.Windows.SDK.BuildTools.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\make\vs\packages\Microsoft.Windows.SDK.BuildTools.10.0.26100.1742\build\Microsoft.Windows.SDK.BuildTools.targets'))" /> </Target> </Project> \ No newline at end of file