ui/winui/table.cpp

Fri, 06 Oct 2023 19:38:10 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Fri, 06 Oct 2023 19:38:10 +0200
branch
newapi
changeset 204
4a258d47f964
parent 203
0e94be3d9722
child 205
b1ac0dd1d38b
permissions
-rw-r--r--

add breadcrumb bar

203
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2023 Olaf Wintermann. All rights reserved.
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include "table.h"
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include "container.h"
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include "util.h"
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include "../common/context.h"
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 #include "../common/object.h"
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 #include <winrt/Microsoft.UI.Xaml.Data.h>
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 #include <winrt/Microsoft.UI.Xaml.Media.h>
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 #include <winrt/Microsoft.UI.Xaml.Input.h>
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 using namespace winrt;
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 using namespace Microsoft::UI::Xaml;
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 using namespace Microsoft::UI::Xaml::Controls;
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 using namespace Windows::UI::Xaml::Interop;
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 using namespace winrt::Windows::Foundation;
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 using namespace winrt::Microsoft::UI::Xaml::Controls::Primitives;
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 using namespace winrt::Microsoft::UI::Xaml::Media;
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 using namespace winrt::Windows::UI::Xaml::Input;
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 extern "C" void reg_table_destructor(UiContext * ctx, UiTable * table) {
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 // TODO:
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 }
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 UIEXPORT UIWIDGET ui_table_create(UiObject* obj, UiListArgs args) {
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 if (!args.model) {
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 return nullptr;
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 }
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 UiObject* current = uic_current_obj(obj);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 // create widgets and wrapper obj
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 ScrollViewer scrollW = ScrollViewer();
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 Grid grid = Grid();
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 scrollW.Content(grid);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 UiTable* uitable = new UiTable(scrollW, grid);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 reg_table_destructor(current->ctx, uitable);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 uitable->getvalue = args.model->getvalue ? args.model->getvalue : args.getvalue;
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 // grid styling
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 winrt::Windows::UI::Color bg = { 233, 233, 255, 255 }; // test color
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 SolidColorBrush brush = SolidColorBrush(bg);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 grid.Background(brush);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 // add columns from args.model
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 uitable->add_header(args.model);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 // bind var
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.list, args.varname, UI_VAR_LIST);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 if (var) {
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 UiList* list = (UiList*)var->value;
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 list->update = ui_table_update;
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 list->obj = uitable;
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 uitable->update(list, 0);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 }
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 // create toolkit wrapper object and register destructor
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 UIElement elm = scrollW;
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 UiWidget* widget = new UiWidget(elm);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 ui_context_add_widget_destructor(current->ctx, widget);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 // add scrollW to current container
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 UI_APPLY_LAYOUT1(current, args);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 current->container->Add(scrollW, false);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 return widget;
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98 }
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 extern "C" void ui_table_update(UiList * list, int i) {
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 UiTable* table = (UiTable*)list->obj;
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 table->clear();
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 table->update(list, i);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 }
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 UiTable::UiTable(winrt::Microsoft::UI::Xaml::Controls::ScrollViewer scrollW, winrt::Microsoft::UI::Xaml::Controls::Grid grid) {
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 this->scrollw = scrollw;
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108 this->grid = grid;
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 winrt::Windows::UI::Color highlightBg = { 120, 120, 255, 255 }; // test color
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 highlightBrush = SolidColorBrush(highlightBg);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113 winrt::Windows::UI::Color defaultBg = { 0, 0, 0, 0 }; // default
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 defaultBrush = SolidColorBrush(defaultBg);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 winrt::Windows::UI::Color selectedBg = { 255, 120, 120, 255 }; // test color
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 selectedBrush = SolidColorBrush(selectedBg);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 winrt::Windows::UI::Color selectedFg = { 255, 20, 20, 255 }; // test color
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 selectedBorderBrush = SolidColorBrush(selectedFg);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121 }
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 void UiTable::add_header(UiModel* model) {
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 GridLength gl;
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 gl.Value = 0;
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 gl.GridUnitType = GridUnitType::Auto;
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128 // add header row definition
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 auto headerRowDef = RowDefinition();
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 headerRowDef.Height(gl);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 grid.RowDefinitions().Append(headerRowDef);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134 for (int i = 0; i < model->columns;i++) {
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135 char* title = model->titles[i];
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 UiModelType type = model->types[i];
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138 // add grid column definition
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139 auto colDef = ColumnDefinition();
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 colDef.Width(gl);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141 grid.ColumnDefinitions().Append(colDef);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143 // add button
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144 auto button = Button();
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145 wchar_t* wlabel = str2wstr(title, nullptr);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146 button.Content(box_value(wlabel));
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
147 free(wlabel);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
148
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149 // some styling for the button
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150 Thickness border = { 0,0,1,0 };
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
151 CornerRadius corner = { 0,0,0,0 };
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
152 button.BorderThickness(border);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
153 button.CornerRadius(corner);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
155 grid.SetColumn(button, i);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
156 grid.SetRow(button, 0);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
157 grid.Children().Append(button);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159 UiTableColumn h;
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
160 h.header = button;
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
161 header.push_back(h);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
162 }
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164 maxrows = 1;
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165 }
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
166
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
167 void UiTable::update(UiList* list, int i) {
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
168 if (getvalue == nullptr) {
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
169 return;
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
170 }
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
171
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
172 Thickness b1 = { 1, 1, 0, 1 }; // first col
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
173 Thickness b2 = { 0, 1, 0, 1 }; // middle
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
174 Thickness b3 = { 0, 1, 1, 1 }; // last col
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
175
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
176 GridLength gl;
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
177 gl.Value = 0;
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178 gl.GridUnitType = GridUnitType::Auto;
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
179
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
180 int row = 1;
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
181 void* elm = list->first(list);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
182 while (elm) {
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183 if (row >= maxrows) {
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184 auto rowdef = RowDefinition();
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185 rowdef.Height(gl);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186 grid.RowDefinitions().Append(rowdef);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187 maxrows = row;
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188 }
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
189
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
190 for (int col = 0; col < header.size(); col++) {
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
191 Border cellBorder = Border();
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
192 cellBorder.Background(defaultBrush);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193 TextBlock cell = TextBlock();
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
194 cellBorder.Child(cell);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
195 cellBorder.BorderBrush(defaultBrush);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196 if (col == 0) {
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197 cellBorder.BorderThickness(b1);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198 }
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199 else if (col + 1 == header.size()) {
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
200 cellBorder.BorderThickness(b3);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
201 }
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
202 else {
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
203 cellBorder.BorderThickness(b2);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
204 }
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
205
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
206 char* value = (char*)getvalue(elm, col);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
207 if (value) {
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
208 wchar_t* wstr = str2wstr(value, nullptr);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
209 cell.Text(winrt::hstring(wstr));
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
210 free(wstr);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
211 }
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
212 Thickness padding = { 10,0,4,0 };
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
213 cell.Padding(padding);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
214 cell.VerticalAlignment(VerticalAlignment::Stretch);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
215
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
216 // event handler
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
217 cellBorder.PointerPressed(
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
218 winrt::Microsoft::UI::Xaml::Input::PointerEventHandler(
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
219 [=](IInspectable const& sender, winrt::Microsoft::UI::Xaml::Input::PointerRoutedEventArgs const& args) {
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
220 if (selection > 0) {
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
221 row_background(selection, defaultBrush, defaultBrush);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
222 }
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
223 row_background(row, selectedBrush, selectedBorderBrush);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
224 selection = row;
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
225 })
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
226 );
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
227 cellBorder.PointerReleased(
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
228 winrt::Microsoft::UI::Xaml::Input::PointerEventHandler(
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
229 [=](IInspectable const& sender, winrt::Microsoft::UI::Xaml::Input::PointerRoutedEventArgs const& args) {
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
230
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
231 })
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
232 );
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
233 cellBorder.PointerEntered(
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
234 winrt::Microsoft::UI::Xaml::Input::PointerEventHandler(
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
235 [=](IInspectable const& sender, winrt::Microsoft::UI::Xaml::Input::PointerRoutedEventArgs const& args) {
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
236 if (selection != row) {
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
237 row_background(row, highlightBrush, highlightBrush);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
238 }
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
239 })
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
240 );
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
241 cellBorder.PointerExited(
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
242 winrt::Microsoft::UI::Xaml::Input::PointerEventHandler(
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
243 [=](IInspectable const& sender, winrt::Microsoft::UI::Xaml::Input::PointerRoutedEventArgs const& args) {
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
244 if (selection != row) {
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
245 row_background(row, defaultBrush, defaultBrush);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
246 }
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
247 })
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
248 );
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
249
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
250 grid.SetColumn(cellBorder, col);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
251 grid.SetRow(cellBorder, row);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
252 grid.Children().Append(cellBorder);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
253 }
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
254
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
255 row++;
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
256 elm = list->next(list);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
257 }
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
258 }
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
259
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
260 void UiTable::clear() {
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
261 for (int i = grid.Children().Size()-1; i >= 0; i--) {
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
262 FrameworkElement elm = grid.Children().GetAt(i).as<FrameworkElement>();
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
263 int child_row = grid.GetRow(elm);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
264 if (child_row > 0) {
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
265 grid.Children().RemoveAt(i);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
266 }
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
267 }
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
268 }
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
269
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
270 void UiTable::row_background(int row, winrt::Microsoft::UI::Xaml::Media::Brush brush, winrt::Microsoft::UI::Xaml::Media::Brush borderBrush) {
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
271 Thickness b1 = { 1, 1, 0, 1 }; // first col
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
272 Thickness b2 = { 0, 1, 0, 1 }; // middle
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
273 Thickness b3 = { 0, 1, 1, 1 }; // last col
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
274
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
275 for (auto child : grid.Children()) {
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
276 FrameworkElement elm = child.as<FrameworkElement>();
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
277 int child_row = grid.GetRow(elm);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
278 if (child_row == row) {
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
279 Border b = elm.as<Border>();
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
280 b.Background(brush);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
281 b.BorderBrush(borderBrush);
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
282 }
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
283 }
0e94be3d9722 add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
284 }

mercurial