Thu, 12 Oct 2023 13:52:18 +0200
add custom titlebar (WinUI3)
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 | |
205
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
203
diff
changeset
|
29 | #include "pch.h" |
b1ac0dd1d38b
new winui vs project, add toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
203
diff
changeset
|
30 | |
203
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
31 | #include "table.h" |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
32 | #include "container.h" |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
33 | #include "util.h" |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | #include "../common/context.h" |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | #include "../common/object.h" |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | #include <winrt/Microsoft.UI.Xaml.Data.h> |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | #include <winrt/Microsoft.UI.Xaml.Media.h> |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | #include <winrt/Microsoft.UI.Xaml.Input.h> |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | using namespace winrt; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | using namespace Microsoft::UI::Xaml; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | using namespace Microsoft::UI::Xaml::Controls; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | using namespace Windows::UI::Xaml::Interop; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | using namespace winrt::Windows::Foundation; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | using namespace winrt::Microsoft::UI::Xaml::Controls::Primitives; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | using namespace winrt::Microsoft::UI::Xaml::Media; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | using namespace winrt::Windows::UI::Xaml::Input; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | 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
|
52 | // TODO: |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | } |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | UIEXPORT UIWIDGET ui_table_create(UiObject* obj, UiListArgs args) { |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | if (!args.model) { |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | return nullptr; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | } |
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 | UiObject* current = uic_current_obj(obj); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | // create widgets and wrapper obj |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | ScrollViewer scrollW = ScrollViewer(); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | Grid grid = Grid(); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | scrollW.Content(grid); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | UiTable* uitable = new UiTable(scrollW, grid); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | reg_table_destructor(current->ctx, uitable); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | |
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 | 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
|
71 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72 | // grid styling |
210
83556205edad
change table colors (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
73 | winrt::Windows::UI::Color bg = { 255, 255, 255, 255 }; // test color |
203
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | SolidColorBrush brush = SolidColorBrush(bg); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75 | grid.Background(brush); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
76 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77 | // add columns from args.model |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
78 | uitable->add_header(args.model); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
79 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80 | // bind var |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81 | 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
|
82 | if (var) { |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
83 | UiList* list = (UiList*)var->value; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
84 | list->update = ui_table_update; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
85 | list->obj = uitable; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
86 | uitable->update(list, 0); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
87 | } |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
88 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
89 | // create toolkit wrapper object and register destructor |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
90 | UIElement elm = scrollW; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
91 | UiWidget* widget = new UiWidget(elm); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
92 | ui_context_add_widget_destructor(current->ctx, widget); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
93 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
94 | // add scrollW to current container |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
95 | UI_APPLY_LAYOUT1(current, args); |
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 | current->container->Add(scrollW, false); |
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 | return widget; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
100 | } |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
101 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
102 | 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
|
103 | UiTable* table = (UiTable*)list->obj; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
104 | table->clear(); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
105 | table->update(list, i); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
106 | } |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
107 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
108 | 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
|
109 | this->scrollw = scrollw; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
110 | this->grid = grid; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
111 | |
210
83556205edad
change table colors (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
112 | winrt::Windows::UI::Color highlightBg = { 255, 234, 234, 234 }; |
203
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
113 | highlightBrush = SolidColorBrush(highlightBg); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
114 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
115 | 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
|
116 | defaultBrush = SolidColorBrush(defaultBg); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
117 | |
210
83556205edad
change table colors (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
118 | winrt::Windows::UI::Color selectedBg = { 255, 204, 232, 255 }; // test color |
203
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
119 | selectedBrush = SolidColorBrush(selectedBg); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
120 | |
210
83556205edad
change table colors (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
121 | winrt::Windows::UI::Color selectedFg = { 255, 0, 90, 158 }; // test color |
203
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
122 | selectedBorderBrush = SolidColorBrush(selectedFg); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
123 | } |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
124 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
125 | void UiTable::add_header(UiModel* model) { |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
126 | GridLength gl; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
127 | gl.Value = 0; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
128 | gl.GridUnitType = GridUnitType::Auto; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
129 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
130 | // add header row definition |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
131 | auto headerRowDef = RowDefinition(); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
132 | headerRowDef.Height(gl); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
133 | grid.RowDefinitions().Append(headerRowDef); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
134 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
135 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
136 | for (int i = 0; i < model->columns;i++) { |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
137 | char* title = model->titles[i]; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
138 | UiModelType type = model->types[i]; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
139 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
140 | // add grid column definition |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
141 | auto colDef = ColumnDefinition(); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
142 | colDef.Width(gl); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
143 | grid.ColumnDefinitions().Append(colDef); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
144 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
145 | // add button |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
146 | auto button = Button(); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
147 | wchar_t* wlabel = str2wstr(title, nullptr); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
148 | button.Content(box_value(wlabel)); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
149 | free(wlabel); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
150 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
151 | // some styling for the button |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
152 | Thickness border = { 0,0,1,0 }; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
153 | CornerRadius corner = { 0,0,0,0 }; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
154 | button.BorderThickness(border); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
155 | button.CornerRadius(corner); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
156 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
157 | grid.SetColumn(button, i); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
158 | grid.SetRow(button, 0); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
159 | grid.Children().Append(button); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
160 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
161 | UiTableColumn h; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
162 | h.header = button; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
163 | header.push_back(h); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
164 | } |
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 | maxrows = 1; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
167 | } |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
168 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
169 | void UiTable::update(UiList* list, int i) { |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
170 | if (getvalue == nullptr) { |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
171 | return; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
172 | } |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
173 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
174 | Thickness b1 = { 1, 1, 0, 1 }; // first col |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
175 | Thickness b2 = { 0, 1, 0, 1 }; // middle |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
176 | Thickness b3 = { 0, 1, 1, 1 }; // last col |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
177 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
178 | GridLength gl; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
179 | gl.Value = 0; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
180 | gl.GridUnitType = GridUnitType::Auto; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
181 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
182 | int row = 1; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
183 | void* elm = list->first(list); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
184 | while (elm) { |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
185 | if (row >= maxrows) { |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
186 | auto rowdef = RowDefinition(); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
187 | rowdef.Height(gl); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
188 | grid.RowDefinitions().Append(rowdef); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
189 | maxrows = row; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
190 | } |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
191 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
192 | for (int col = 0; col < header.size(); col++) { |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
193 | Border cellBorder = Border(); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
194 | cellBorder.Background(defaultBrush); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
195 | TextBlock cell = TextBlock(); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
196 | cellBorder.Child(cell); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
197 | cellBorder.BorderBrush(defaultBrush); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
198 | if (col == 0) { |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
199 | cellBorder.BorderThickness(b1); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
200 | } |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
201 | else if (col + 1 == header.size()) { |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
202 | cellBorder.BorderThickness(b3); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
203 | } |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
204 | else { |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
205 | cellBorder.BorderThickness(b2); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
206 | } |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
207 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
208 | char* value = (char*)getvalue(elm, col); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
209 | if (value) { |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
210 | wchar_t* wstr = str2wstr(value, nullptr); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
211 | cell.Text(winrt::hstring(wstr)); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
212 | free(wstr); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
213 | } |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
214 | Thickness padding = { 10,0,4,0 }; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
215 | cell.Padding(padding); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
216 | cell.VerticalAlignment(VerticalAlignment::Stretch); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
217 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
218 | // event handler |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
219 | cellBorder.PointerPressed( |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
220 | winrt::Microsoft::UI::Xaml::Input::PointerEventHandler( |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
221 | [=](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
|
222 | if (selection > 0) { |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
223 | row_background(selection, defaultBrush, defaultBrush); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
224 | } |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
225 | row_background(row, selectedBrush, selectedBorderBrush); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
226 | selection = row; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
227 | }) |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
228 | ); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
229 | cellBorder.PointerReleased( |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
230 | winrt::Microsoft::UI::Xaml::Input::PointerEventHandler( |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
231 | [=](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
|
232 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
233 | }) |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
234 | ); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
235 | cellBorder.PointerEntered( |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
236 | winrt::Microsoft::UI::Xaml::Input::PointerEventHandler( |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
237 | [=](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
|
238 | if (selection != row) { |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
239 | row_background(row, highlightBrush, highlightBrush); |
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 | }) |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
242 | ); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
243 | cellBorder.PointerExited( |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
244 | winrt::Microsoft::UI::Xaml::Input::PointerEventHandler( |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
245 | [=](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
|
246 | if (selection != row) { |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
247 | row_background(row, defaultBrush, defaultBrush); |
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 | ); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
251 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
252 | grid.SetColumn(cellBorder, col); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
253 | grid.SetRow(cellBorder, row); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
254 | grid.Children().Append(cellBorder); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
255 | } |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
256 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
257 | row++; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
258 | elm = list->next(list); |
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 | } |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
261 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
262 | void UiTable::clear() { |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
263 | 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
|
264 | FrameworkElement elm = grid.Children().GetAt(i).as<FrameworkElement>(); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
265 | int child_row = grid.GetRow(elm); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
266 | if (child_row > 0) { |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
267 | grid.Children().RemoveAt(i); |
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 | } |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
271 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
272 | 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
|
273 | Thickness b1 = { 1, 1, 0, 1 }; // first col |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
274 | Thickness b2 = { 0, 1, 0, 1 }; // middle |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
275 | Thickness b3 = { 0, 1, 1, 1 }; // last col |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
276 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
277 | for (auto child : grid.Children()) { |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
278 | FrameworkElement elm = child.as<FrameworkElement>(); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
279 | int child_row = grid.GetRow(elm); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
280 | if (child_row == row) { |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
281 | Border b = elm.as<Border>(); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
282 | b.Background(brush); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
283 | b.BorderBrush(borderBrush); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
284 | } |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
285 | } |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
286 | } |