Sat, 14 Oct 2023 10:01:22 +0200
fix ui_fileicon (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" |
215
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
34 | #include "icons.h" |
203
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 "../common/context.h" |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | #include "../common/object.h" |
215
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
38 | #include "../common/types.h" |
203
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 | #include <winrt/Microsoft.UI.Xaml.Data.h> |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | #include <winrt/Microsoft.UI.Xaml.Media.h> |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | #include <winrt/Microsoft.UI.Xaml.Input.h> |
214
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
43 | #include <winrt/Windows.UI.Core.h> |
203
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | using namespace winrt; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | using namespace Microsoft::UI::Xaml; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | using namespace Microsoft::UI::Xaml::Controls; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | using namespace Windows::UI::Xaml::Interop; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | using namespace winrt::Windows::Foundation; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | using namespace winrt::Microsoft::UI::Xaml::Controls::Primitives; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | using namespace winrt::Microsoft::UI::Xaml::Media; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | using namespace winrt::Windows::UI::Xaml::Input; |
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 | 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
|
55 | // TODO: |
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 | UIEXPORT UIWIDGET ui_table_create(UiObject* obj, UiListArgs args) { |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | if (!args.model) { |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | return nullptr; |
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 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | UiObject* current = uic_current_obj(obj); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | // create widgets and wrapper obj |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | ScrollViewer scrollW = ScrollViewer(); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | Grid grid = Grid(); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | scrollW.Content(grid); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | UiTable* uitable = new UiTable(scrollW, grid); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | reg_table_destructor(current->ctx, uitable); |
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 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73 | 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
|
74 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75 | // grid styling |
210
83556205edad
change table colors (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
76 | 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
|
77 | SolidColorBrush brush = SolidColorBrush(bg); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
78 | grid.Background(brush); |
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 | // add columns from args.model |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81 | uitable->add_header(args.model); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
82 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
83 | // bind var |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
84 | 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
|
85 | if (var) { |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
86 | UiList* list = (UiList*)var->value; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
87 | list->update = ui_table_update; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
88 | list->obj = uitable; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
89 | uitable->update(list, 0); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
90 | } |
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 | // create toolkit wrapper object and register destructor |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
93 | UIElement elm = scrollW; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
94 | UiWidget* widget = new UiWidget(elm); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
95 | ui_context_add_widget_destructor(current->ctx, widget); |
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 | // add scrollW to current container |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
98 | UI_APPLY_LAYOUT1(current, args); |
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 | current->container->Add(scrollW, false); |
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 | return widget; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
103 | } |
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 | 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
|
106 | UiTable* table = (UiTable*)list->obj; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
107 | table->clear(); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
108 | table->update(list, i); |
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 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
111 | 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
|
112 | this->scrollw = scrollw; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
113 | this->grid = grid; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
114 | |
210
83556205edad
change table colors (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
115 | 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
|
116 | highlightBrush = SolidColorBrush(highlightBg); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
117 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
118 | 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
|
119 | defaultBrush = SolidColorBrush(defaultBg); |
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 selectedBg = { 255, 204, 232, 255 }; // test color |
203
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
122 | selectedBrush = SolidColorBrush(selectedBg); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
123 | |
210
83556205edad
change table colors (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
205
diff
changeset
|
124 | 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
|
125 | selectedBorderBrush = SolidColorBrush(selectedFg); |
214
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
126 | |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
127 | grid.KeyDown( |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
128 | winrt::Microsoft::UI::Xaml::Input::KeyEventHandler( |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
129 | [=](IInspectable const& sender, winrt::Microsoft::UI::Xaml::Input::KeyRoutedEventArgs const& args) { |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
130 | // key event for hanling the table cursor or enter |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
131 | }) |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
132 | ); |
203
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 | |
215
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
135 | UiTable::~UiTable() { |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
136 | ui_model_free(NULL, model); |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
137 | } |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
138 | |
203
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
139 | void UiTable::add_header(UiModel* model) { |
215
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
140 | this->model = ui_model_copy(NULL, model); |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
141 | |
203
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
142 | GridLength gl; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
143 | gl.Value = 0; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
144 | gl.GridUnitType = GridUnitType::Auto; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
145 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
146 | // add header row definition |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
147 | auto headerRowDef = RowDefinition(); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
148 | headerRowDef.Height(gl); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
149 | grid.RowDefinitions().Append(headerRowDef); |
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 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
152 | for (int i = 0; i < model->columns;i++) { |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
153 | char* title = model->titles[i]; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
154 | UiModelType type = model->types[i]; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
155 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
156 | // add grid column definition |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
157 | auto colDef = ColumnDefinition(); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
158 | colDef.Width(gl); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
159 | grid.ColumnDefinitions().Append(colDef); |
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 | // add button |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
162 | auto button = Button(); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
163 | wchar_t* wlabel = str2wstr(title, nullptr); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
164 | button.Content(box_value(wlabel)); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
165 | free(wlabel); |
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 | // some styling for the button |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
168 | Thickness border = { 0,0,1,0 }; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
169 | CornerRadius corner = { 0,0,0,0 }; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
170 | button.BorderThickness(border); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
171 | button.CornerRadius(corner); |
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 | grid.SetColumn(button, i); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
174 | grid.SetRow(button, 0); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
175 | grid.Children().Append(button); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
176 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
177 | UiTableColumn h; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
178 | h.header = button; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
179 | header.push_back(h); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
180 | } |
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 | maxrows = 1; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
183 | } |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
184 | |
215
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
185 | static void textblock_set_str(TextBlock &t, const char *str) { |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
186 | if (str) { |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
187 | wchar_t* wstr = str2wstr(str, nullptr); |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
188 | t.Text(winrt::hstring(wstr)); |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
189 | free(wstr); |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
190 | } |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
191 | } |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
192 | |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
193 | static void textblock_set_int(TextBlock& t, int i) { |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
194 | wchar_t buf[16]; |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
195 | swprintf(buf, 16, L"%d", i); |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
196 | t.Text(winrt::hstring(buf)); |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
197 | } |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
198 | |
203
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
199 | void UiTable::update(UiList* list, int i) { |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
200 | if (getvalue == nullptr) { |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
201 | return; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
202 | } |
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 | Thickness b1 = { 1, 1, 0, 1 }; // first col |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
205 | Thickness b2 = { 0, 1, 0, 1 }; // middle |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
206 | Thickness b3 = { 0, 1, 1, 1 }; // last col |
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 | GridLength gl; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
209 | gl.Value = 0; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
210 | gl.GridUnitType = GridUnitType::Auto; |
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 | int row = 1; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
213 | void* elm = list->first(list); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
214 | while (elm) { |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
215 | if (row >= maxrows) { |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
216 | auto rowdef = RowDefinition(); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
217 | rowdef.Height(gl); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
218 | grid.RowDefinitions().Append(rowdef); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
219 | maxrows = row; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
220 | } |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
221 | |
215
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
222 | Thickness cellpadding = { 10,0,4,0 }; |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
223 | |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
224 | int model_col = 0; |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
225 | for (int col = 0; col < header.size(); col++, model_col++) { |
214
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
226 | // create ui elements with the correct cell border |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
227 | // dependeing on the column |
203
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
228 | Border cellBorder = Border(); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
229 | cellBorder.Background(defaultBrush); |
215
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
230 | |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
231 | // set the cell value |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
232 | UiModelType type = model->types[col]; |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
233 | switch (type) { |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
234 | case UI_STRING: { |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
235 | TextBlock cell = TextBlock(); |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
236 | cell.Padding(cellpadding); |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
237 | cell.VerticalAlignment(VerticalAlignment::Stretch); |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
238 | textblock_set_str(cell, (char*)getvalue(elm, model_col)); |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
239 | cellBorder.Child(cell); |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
240 | break; |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
241 | } |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
242 | case UI_INTEGER: { |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
243 | TextBlock cell = TextBlock(); |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
244 | cell.Padding(cellpadding); |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
245 | cell.VerticalAlignment(VerticalAlignment::Stretch); |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
246 | int *value = (int*)getvalue(elm, model_col); |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
247 | if (value) { |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
248 | textblock_set_int(cell, *value); |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
249 | } |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
250 | cellBorder.Child(cell); |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
251 | break; |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
252 | } |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
253 | case UI_ICON: { |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
254 | UiIcon* iconConstr = (UiIcon*)getvalue(elm, model_col); |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
255 | if (iconConstr) { |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
256 | IconElement icon = iconConstr->getIcon(); |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
257 | cellBorder.Child(icon); |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
258 | } |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
259 | break; |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
260 | } |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
261 | case UI_ICON_TEXT: { |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
262 | StackPanel cellPanel = StackPanel(); |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
263 | cellPanel.Spacing(2); |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
264 | cellPanel.Padding(cellpadding); |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
265 | cellPanel.VerticalAlignment(VerticalAlignment::Stretch); |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
266 | |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
267 | cellPanel.Orientation(Orientation::Horizontal); |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
268 | UiIcon* iconConstr = (UiIcon*)getvalue(elm, model_col++); |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
269 | char* str = (char*)getvalue(elm, model_col); |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
270 | if (iconConstr) { |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
271 | IconElement icon = iconConstr->getIcon(); |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
272 | cellPanel.Children().Append(icon); |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
273 | } |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
274 | TextBlock cell = TextBlock(); |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
275 | textblock_set_str(cell, str); |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
276 | cellPanel.Children().Append(cell); |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
277 | cellBorder.Child(cellPanel); |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
278 | break; |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
279 | } |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
280 | } |
1bd5534c395d
add support for icons in the table widget (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
214
diff
changeset
|
281 | |
203
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
282 | cellBorder.BorderBrush(defaultBrush); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
283 | if (col == 0) { |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
284 | cellBorder.BorderThickness(b1); |
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 | else if (col + 1 == header.size()) { |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
287 | cellBorder.BorderThickness(b3); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
288 | } |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
289 | else { |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
290 | cellBorder.BorderThickness(b2); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
291 | } |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
292 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
293 | // event handler |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
294 | cellBorder.PointerPressed( |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
295 | winrt::Microsoft::UI::Xaml::Input::PointerEventHandler( |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
296 | [=](IInspectable const& sender, winrt::Microsoft::UI::Xaml::Input::PointerRoutedEventArgs const& args) { |
214
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
297 | winrt::Windows::System::VirtualKeyModifiers modifiers = args.KeyModifiers(); |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
298 | |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
299 | if (modifiers == winrt::Windows::System::VirtualKeyModifiers::Control) { |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
300 | // add/remove current row |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
301 | if (!is_row_selected(row)) { |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
302 | row_background(row, selectedBrush, selectedBorderBrush); |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
303 | selection.push_back(row); |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
304 | } |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
305 | else { |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
306 | row_background(row, highlightBrush, highlightBrush); |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
307 | remove_from_selection(row); |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
308 | } |
203
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
309 | } |
214
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
310 | else if (modifiers == winrt::Windows::System::VirtualKeyModifiers::None || selection.size() == 0) { |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
311 | // no modifier or shift is pressed but there is no selection |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
312 | if (selection.size() > 0) { |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
313 | change_rows_bg(selection, defaultBrush, defaultBrush); |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
314 | } |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
315 | |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
316 | row_background(row, selectedBrush, selectedBorderBrush); |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
317 | selection = { row }; |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
318 | } |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
319 | else if (modifiers == winrt::Windows::System::VirtualKeyModifiers::Shift) { |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
320 | // select everything between the first selection and the current row |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
321 | std::sort(selection.begin(), selection.end()); |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
322 | int first = selection.front(); |
216
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
323 | int last = row; |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
324 | if (first > row) { |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
325 | last = first; |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
326 | first = row; |
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
327 | } |
214
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
328 | |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
329 | // clear previous selection |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
330 | change_rows_bg(selection, defaultBrush, defaultBrush); |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
331 | |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
332 | // create new selection |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
333 | std::vector<int> newselection; |
216
391c2c723029
add dll icon loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
215
diff
changeset
|
334 | for (int s = first; s <= last; s++) { |
214
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
335 | newselection.push_back(s); |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
336 | } |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
337 | selection = newselection; |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
338 | change_rows_bg(selection, selectedBrush, selectedBorderBrush); |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
339 | } |
203
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
340 | }) |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
341 | ); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
342 | cellBorder.PointerReleased( |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
343 | winrt::Microsoft::UI::Xaml::Input::PointerEventHandler( |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
344 | [=](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
|
345 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
346 | }) |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
347 | ); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
348 | cellBorder.PointerEntered( |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
349 | winrt::Microsoft::UI::Xaml::Input::PointerEventHandler( |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
350 | [=](IInspectable const& sender, winrt::Microsoft::UI::Xaml::Input::PointerRoutedEventArgs const& args) { |
214
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
351 | if (!is_row_selected(row)) { |
203
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
352 | row_background(row, highlightBrush, highlightBrush); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
353 | } |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
354 | }) |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
355 | ); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
356 | cellBorder.PointerExited( |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
357 | winrt::Microsoft::UI::Xaml::Input::PointerEventHandler( |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
358 | [=](IInspectable const& sender, winrt::Microsoft::UI::Xaml::Input::PointerRoutedEventArgs const& args) { |
214
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
359 | if (!is_row_selected(row)) { |
203
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
360 | row_background(row, defaultBrush, defaultBrush); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
361 | } |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
362 | }) |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
363 | ); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
364 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
365 | grid.SetColumn(cellBorder, col); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
366 | grid.SetRow(cellBorder, row); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
367 | grid.Children().Append(cellBorder); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
368 | } |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
369 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
370 | row++; |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
371 | elm = list->next(list); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
372 | } |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
373 | } |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
374 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
375 | void UiTable::clear() { |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
376 | 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
|
377 | FrameworkElement elm = grid.Children().GetAt(i).as<FrameworkElement>(); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
378 | int child_row = grid.GetRow(elm); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
379 | if (child_row > 0) { |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
380 | grid.Children().RemoveAt(i); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
381 | } |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
382 | } |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
383 | } |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
384 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
385 | 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
|
386 | Thickness b1 = { 1, 1, 0, 1 }; // first col |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
387 | Thickness b2 = { 0, 1, 0, 1 }; // middle |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
388 | Thickness b3 = { 0, 1, 1, 1 }; // last col |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
389 | |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
390 | for (auto child : grid.Children()) { |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
391 | FrameworkElement elm = child.as<FrameworkElement>(); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
392 | int child_row = grid.GetRow(elm); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
393 | if (child_row == row) { |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
394 | Border b = elm.as<Border>(); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
395 | b.Background(brush); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
396 | b.BorderBrush(borderBrush); |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
397 | } |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
398 | } |
0e94be3d9722
add semi-functional table (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
399 | } |
214
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
400 | |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
401 | void UiTable::change_rows_bg(std::vector<int> rows, winrt::Microsoft::UI::Xaml::Media::Brush brush, winrt::Microsoft::UI::Xaml::Media::Brush borderBrush) { |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
402 | std::for_each(rows.cbegin(), rows.cend(), [&](const int& row) {row_background(row, brush, borderBrush); }); |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
403 | } |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
404 | |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
405 | bool UiTable::is_row_selected(int row) { |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
406 | return std::find(selection.begin(), selection.end(), row) != selection.end() ? true : false; |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
407 | } |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
408 | |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
409 | void UiTable::remove_from_selection(int row) { |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
410 | selection.erase(std::remove(selection.begin(), selection.end(), row), selection.end()); |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
411 | selection.shrink_to_fit(); |
279c0c81d3b1
improve table row selection, add support for multiple selections (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
210
diff
changeset
|
412 | } |