ui/winui/container.h

changeset 431
bb7da585debc
parent 378
d41b1ffc5f77
equal deleted inserted replaced
169:fe49cff3c571 431:bb7da585debc
1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright 2023 Olaf Wintermann. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #pragma once
30
31 #include "toolkit.h"
32 #include "../ui/container.h"
33
34 #include <Windows.h>
35 #undef GetCurrentTime
36 #include <winrt/Windows.Foundation.Collections.h>
37 #include <winrt/Windows.UI.Xaml.Interop.h>
38 #include <winrt/Microsoft.UI.Xaml.Controls.h>
39 #include <winrt/Microsoft.UI.Xaml.Controls.Primitives.h>
40 #include <winrt/Microsoft.UI.Xaml.XamlTypeInfo.h>
41 #include <winrt/Microsoft.UI.Xaml.Markup.h>
42
43
44 #define ui_reset_layout(layout) memset(&(layout), 0, sizeof(UiLayout))
45 #define ui_lb2bool(b) ((b) == UI_LAYOUT_TRUE ? TRUE : FALSE)
46 #define ui_bool2lb(b) ((b) ? UI_LAYOUT_TRUE : UI_LAYOUT_FALSE)
47
48 typedef struct UiLayout UiLayout;
49 typedef enum UiLayoutBool UiLayoutBool;
50
51 using namespace winrt;
52 using namespace Microsoft::UI::Xaml;
53 using namespace Microsoft::UI::Xaml::Controls;
54 using namespace Microsoft::UI::Xaml::XamlTypeInfo;
55 using namespace Microsoft::UI::Xaml::Markup;
56 using namespace Windows::UI::Xaml::Interop;
57
58 enum UiLayoutBool {
59 UI_LAYOUT_UNDEFINED = 0,
60 UI_LAYOUT_TRUE,
61 UI_LAYOUT_FALSE,
62 };
63
64 struct UiLayout {
65 UiLayoutBool fill;
66 UiBool newline;
67 char* label;
68 UiBool hexpand;
69 UiBool vexpand;
70 UiBool hfill;
71 UiBool vfill;
72 int width;
73 int height;
74 int colspan;
75 int rowspan;
76 };
77
78 struct UiContainer {
79 UiLayout layout;
80 int close = 0;
81
82 virtual void Add(FrameworkElement control, UiBool fill) = 0;
83 };
84
85 enum UiBoxContainerType {
86 UI_BOX_CONTAINER_VBOX = 0,
87 UI_BOX_CONTAINER_HBOX
88 };
89
90 enum UiNavigationViewType {
91 UI_NAVIGATIONVIEW_TOP = 0,
92 UI_NAVIGATIONVIEW_SIDE
93 };
94
95 struct UiBoxContainer : UiContainer {
96 Grid grid;
97 enum UiBoxContainerType type;
98 RowDefinition boxRowDef;
99 ColumnDefinition boxColDef;
100
101 UiBoxContainer(Grid grid, enum UiBoxContainerType type, int margin, int spacing);
102
103 void Add(FrameworkElement control, UiBool fill);
104 };
105
106 struct UiGridContainer : UiContainer {
107 Grid grid;
108 int x = 0;
109 int y = -1;
110 int cols = 0;
111
112 UiGridContainer(Grid grid, int margin, int columnspacing, int rowspacing);
113
114 void Add(FrameworkElement control, UiBool fill);
115 };
116
117 struct UiTabView {
118 UiObject* current;
119 UiSubContainerType subcontainer;
120 int margin;
121 int spacing;
122 int columnspacing;
123 int rowspacing;
124
125 virtual UiObject* AddTab(const char* label, int index = -1) = 0;
126 virtual void Remove(int index) = 0;
127 virtual void Select(int index) = 0;
128 virtual FrameworkElement GetFrameworkElement() = 0;
129 };
130
131 struct UiTabViewContainer : UiContainer {
132 UiTabView* tabview;
133
134 UiTabViewContainer(UiTabView* tabview);
135
136 void Add(FrameworkElement control, UiBool fill);
137 };
138
139 struct UiPivotTabView : UiTabView {
140 Pivot pivot;
141
142 UiPivotTabView(UiObject *obj, Pivot pivot, UiTabViewArgs args);
143
144 UiObject* AddTab(const char* label, int index = -1);
145 void Remove(int index);
146 void Select(int index);
147 FrameworkElement GetFrameworkElement();
148 };
149
150 struct UiMainTabView : UiTabView {
151 TabView tabview;
152
153 UiMainTabView(UiObject* obj, TabView tabview, UiTabViewArgs args);
154
155 UiObject* AddTab(const char* label, int index = -1);
156 void Remove(int index);
157 void Select(int index);
158 FrameworkElement GetFrameworkElement();
159 };
160
161 struct UiNavigationTabView : UiTabView {
162 NavigationView navigationview;
163 UiTabViewType type;
164 std::vector<std::tuple<NavigationViewItem, FrameworkElement> > pages;
165
166 UiNavigationTabView(UiObject* obj, NavigationView navigationview, UiTabViewArgs args, UiTabViewType type);
167
168 UiObject* AddTab(const char* label, int index = -1);
169 void Remove(int index);
170 void Select(int index);
171 FrameworkElement GetFrameworkElement();
172
173 void SelectionChanged(NavigationView const& sender, NavigationViewSelectionChangedEventArgs const& args);
174 };
175
176 struct UiInvisibleTabView : UiTabView {
177 Grid container;
178 std::vector<FrameworkElement> pages;
179 int currentIndex;
180
181 UiInvisibleTabView(UiObject *obj, Grid container, UiTabViewArgs args);
182
183 UiObject* AddTab(const char* label, int index = -1);
184 void Remove(int index);
185 void Select(int index);
186 FrameworkElement GetFrameworkElement();
187 };

mercurial