|
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 int width; |
|
71 int height; |
|
72 int colspan; |
|
73 int rowspan; |
|
74 }; |
|
75 |
|
76 struct UiContainer { |
|
77 UiLayout layout; |
|
78 int close = 0; |
|
79 |
|
80 virtual void Add(FrameworkElement control, UiBool fill) = 0; |
|
81 }; |
|
82 |
|
83 enum UiBoxContainerType { |
|
84 UI_BOX_CONTAINER_VBOX = 0, |
|
85 UI_BOX_CONTAINER_HBOX |
|
86 }; |
|
87 |
|
88 enum UiNavigationViewType { |
|
89 UI_NAVIGATIONVIEW_TOP = 0, |
|
90 UI_NAVIGATIONVIEW_SIDE |
|
91 }; |
|
92 |
|
93 struct UiBoxContainer : UiContainer { |
|
94 Grid grid; |
|
95 enum UiBoxContainerType type; |
|
96 RowDefinition boxRowDef; |
|
97 ColumnDefinition boxColDef; |
|
98 |
|
99 UiBoxContainer(Grid grid, enum UiBoxContainerType type, int margin, int spacing); |
|
100 |
|
101 void Add(FrameworkElement control, UiBool fill); |
|
102 }; |
|
103 |
|
104 struct UiGridContainer : UiContainer { |
|
105 Grid grid; |
|
106 int x = 0; |
|
107 int y = -1; |
|
108 int cols = 0; |
|
109 |
|
110 UiGridContainer(Grid grid, int margin, int columnspacing, int rowspacing); |
|
111 |
|
112 void Add(FrameworkElement control, UiBool fill); |
|
113 }; |
|
114 |
|
115 struct UiTabView { |
|
116 UiObject* current; |
|
117 UiSubContainerType subcontainer; |
|
118 int margin; |
|
119 int spacing; |
|
120 int columnspacing; |
|
121 int rowspacing; |
|
122 |
|
123 virtual UiObject* AddTab(const char* label) = 0; |
|
124 |
|
125 virtual FrameworkElement GetFrameworkElement() = 0; |
|
126 }; |
|
127 |
|
128 struct UiTabViewContainer : UiContainer { |
|
129 UiTabView* tabview; |
|
130 |
|
131 UiTabViewContainer(UiTabView* tabview); |
|
132 |
|
133 void Add(FrameworkElement control, UiBool fill); |
|
134 }; |
|
135 |
|
136 struct UiPivotTabView : UiTabView { |
|
137 Pivot pivot; |
|
138 |
|
139 UiPivotTabView(UiObject *obj, Pivot pivot, UiTabViewArgs args); |
|
140 |
|
141 UiObject* AddTab(const char* label); |
|
142 FrameworkElement GetFrameworkElement(); |
|
143 }; |
|
144 |
|
145 struct UiMainTabView : UiTabView { |
|
146 TabView tabview; |
|
147 |
|
148 UiMainTabView(UiObject* obj, TabView tabview, UiTabViewArgs args); |
|
149 |
|
150 UiObject* AddTab(const char* label); |
|
151 FrameworkElement GetFrameworkElement(); |
|
152 }; |
|
153 |
|
154 struct UiNavigationTabView : UiTabView { |
|
155 NavigationView navigationview; |
|
156 UiTabViewType type; |
|
157 std::vector<std::tuple<NavigationViewItem, FrameworkElement> > pages; |
|
158 |
|
159 UiNavigationTabView(UiObject* obj, NavigationView navigationview, UiTabViewArgs args, UiTabViewType type); |
|
160 |
|
161 UiObject* AddTab(const char* label); |
|
162 FrameworkElement GetFrameworkElement(); |
|
163 |
|
164 void SelectionChanged(NavigationView const& sender, NavigationViewSelectionChangedEventArgs const& args); |
|
165 }; |