ui/winui/container.cpp

Sun, 01 Oct 2023 12:08:09 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 01 Oct 2023 12:08:09 +0200
branch
newapi
changeset 187
24ce2c326d85
parent 186
5db4979bf482
child 188
fbbae6738252
permissions
-rw-r--r--

implement toggle button (WinUI3)

182
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2023 Olaf Wintermann. All rights reserved.
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
6cf690e042bd add window container (WinUI)
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
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include "container.h"
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30
185
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
31 #include "../common/context.h"
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
32 #include "../common/object.h"
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
33
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
34
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
35 void ui_container_begin_close(UiObject* obj) {
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
36 UiContainer* ct = uic_get_current_container(obj);
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
37 ct->close = 1;
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
38 }
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
39
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
40 int ui_container_finish(UiObject* obj) {
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
41 UiContainer* ct = uic_get_current_container(obj);
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
42 if (ct->close) {
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
43 ui_end(obj);
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
44 return 0;
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
45 }
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
46 return 1;
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
47 }
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
48
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
49
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
50 // --------------------- UiBoxContainer ---------------------
182
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 UiBoxContainer::UiBoxContainer(Grid grid, enum UiBoxContainerType type) {
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 this->grid = grid;
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 this->type = type;
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55
185
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
56 GridLength gl;
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
57 gl.Value = 1;
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
58 gl.GridUnitType = GridUnitType::Star;
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
59
182
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 // hbox needs one row def, vbox needs one col def
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 // all other col/row defs are created when elements are added
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 if (type == UI_CONTAINER_HBOX) {
185
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
63 boxRowDef = RowDefinition();
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
64 boxRowDef.Height(gl);
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
65 grid.RowDefinitions().Append(boxRowDef);
182
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 } else {
185
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
67 boxColDef = ColumnDefinition();
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
68 boxColDef.Width(gl);
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
69 grid.ColumnDefinitions().Append(boxColDef);
182
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 }
185
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
71
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
72 ui_reset_layout(layout);
182
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 }
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74
185
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
75 void UiBoxContainer::Add(FrameworkElement control, UiBool fill) {
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
76 if (this->layout.fill != UI_LAYOUT_UNDEFINED) {
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
77 fill = ui_lb2bool(this->layout.fill);
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
78 }
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
79
182
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 GridLength gl;
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 if (fill) {
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 gl.Value = 1;
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 gl.GridUnitType = GridUnitType::Star;
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 }
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 else {
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 gl.Value = 0;
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 gl.GridUnitType = GridUnitType::Auto;
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 }
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89
185
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
90 control.HorizontalAlignment(HorizontalAlignment::Stretch);
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
91 control.VerticalAlignment(VerticalAlignment::Stretch);
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
92
182
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 if (type == UI_CONTAINER_HBOX) {
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 ColumnDefinition coldef = ColumnDefinition();
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 coldef.Width(gl);
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 grid.ColumnDefinitions().Append(coldef);
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 grid.SetColumn(control, grid.Children().Size());
185
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
98 grid.SetRow(control, 0);
182
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 } else {
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 RowDefinition rowdef = RowDefinition();
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 rowdef.Height(gl);
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 grid.RowDefinitions().Append(rowdef);
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 grid.SetRow(control, grid.Children().Size());
185
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
104 grid.SetColumn(control, 0);
182
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 }
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 grid.Children().Append(control);
185
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
108
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
109 ui_reset_layout(layout);
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
110 }
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
111
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
112 // --------------------- UiBoxContainer ---------------------
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
113
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
114 UIWIDGET ui_grid(UiObject* obj) {
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
115 return ui_grid_sp(obj, 0, 0, 0);
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
116 }
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
117
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
118 UIWIDGET ui_grid_sp(UiObject* obj, int margin, int columnspacing, int rowspacing) {
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
119 UiContainer* ct = uic_get_current_container(obj);
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
120
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
121 Grid grid = Grid();
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
122 ct->Add(grid, true);
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
123
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
124 UIElement elm = grid;
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
125 UiWidget* widget = new UiWidget(elm);
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
126
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
127 UiObject* newobj = uic_object_new(obj, widget);
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
128 newobj->container = new UiGridContainer(grid, margin, columnspacing, rowspacing);
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
129 uic_obj_add(obj, newobj);
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
130
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
131 return widget;
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
132 }
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
133
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
134 UiGridContainer::UiGridContainer(Grid grid, int margin, int columnspacing, int rowspacing) {
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
135 this->grid = grid;
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
136 Thickness t = { (double)margin, (double)margin, (double)margin, (double)margin };
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
137 grid.Margin(t);
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
138 grid.ColumnSpacing((double)columnspacing);
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
139 grid.RowSpacing((double)rowspacing);
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
140 ui_reset_layout(layout);
182
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141 }
6cf690e042bd add window container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142
185
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
143 void UiGridContainer::Add(FrameworkElement control, UiBool fill) {
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
144 GridLength gl;
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
145
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
146 int hexpand = FALSE;
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
147 int vexpand = FALSE;
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
148 if (layout.hexpand != UI_LAYOUT_UNDEFINED) {
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
149 hexpand = layout.hexpand;
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
150 }
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
151 if (layout.vexpand != UI_LAYOUT_UNDEFINED) {
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
152 vexpand = layout.vexpand;
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
153 }
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
154
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
155 // create new RowDefinition for the new line
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
156 if (layout.newline || y == -1) {
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
157 x = 0;
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
158 y++;
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
159 RowDefinition rowdef = RowDefinition();
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
160 if (vexpand) {
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
161 gl.GridUnitType = GridUnitType::Star;
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
162 gl.Value = 1;
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
163 }
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
164 else {
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
165 gl.GridUnitType = GridUnitType::Auto;
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
166 gl.Value = 0;
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
167 }
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
168 rowdef.Height(gl);
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
169 grid.RowDefinitions().Append(rowdef);
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
170 }
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
171
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
172 // create new columndefinition, if a new column is added
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
173 if (x == cols) {
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
174 if (hexpand) {
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
175 gl.GridUnitType = GridUnitType::Star;
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
176 gl.Value = 1;
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
177 }
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
178 else {
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
179 gl.GridUnitType = GridUnitType::Auto;
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
180 gl.Value = 0;
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
181 }
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
182 ColumnDefinition coldef = ColumnDefinition();
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
183 coldef.Width(gl);
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
184 grid.ColumnDefinitions().Append(coldef);
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
185 cols++;
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
186 }
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
187
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
188 // add control
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
189 control.HorizontalAlignment(HorizontalAlignment::Stretch);
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
190 control.VerticalAlignment(VerticalAlignment::Stretch);
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
191
186
5db4979bf482 implement new api style for ui_button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
192 if (layout.colspan > 0) {
5db4979bf482 implement new api style for ui_button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
193 grid.SetColumnSpan(control, layout.colspan);
5db4979bf482 implement new api style for ui_button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
194 }
5db4979bf482 implement new api style for ui_button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
195 if (layout.rowspan > 0) {
5db4979bf482 implement new api style for ui_button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
196 grid.SetRowSpan(control, layout.rowspan);
185
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
197 }
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
198
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
199 grid.SetRow(control, y);
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
200 grid.SetColumn(control, x);
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
201 grid.Children().Append(control);
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
202
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
203 x++;
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
204
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
205 ui_reset_layout(layout);
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
206 }
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
207
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
208 /*
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
209 * -------------------- Layout Functions --------------------
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
210 *
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
211 * functions for setting layout attributes for the current container
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
212 *
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
213 */
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
214
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
215 void ui_layout_fill(UiObject* obj, UiBool fill) {
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
216 UiContainer* ct = uic_get_current_container(obj);
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
217 ct->layout.fill = ui_bool2lb(fill);
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
218 }
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
219
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
220 void ui_layout_hexpand(UiObject* obj, UiBool expand) {
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
221 UiContainer* ct = uic_get_current_container(obj);
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
222 ct->layout.hexpand = expand;
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
223 }
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
224
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
225 void ui_layout_vexpand(UiObject* obj, UiBool expand) {
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
226 UiContainer* ct = uic_get_current_container(obj);
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
227 ct->layout.vexpand = expand;
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
228 }
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
229
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
230 void ui_layout_width(UiObject* obj, int width) {
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
231 UiContainer* ct = uic_get_current_container(obj);
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
232 ct->layout.width = width;
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
233 }
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
234
186
5db4979bf482 implement new api style for ui_button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
235 void ui_layout_height(UiObject* obj, int height) {
5db4979bf482 implement new api style for ui_button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
236 UiContainer* ct = uic_get_current_container(obj);
5db4979bf482 implement new api style for ui_button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
237 ct->layout.height = height;
5db4979bf482 implement new api style for ui_button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
238 }
5db4979bf482 implement new api style for ui_button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
239
5db4979bf482 implement new api style for ui_button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
240 void ui_layout_colspan(UiObject* obj, int cols) {
185
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
241 UiContainer* ct = uic_get_current_container(obj);
186
5db4979bf482 implement new api style for ui_button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
242 ct->layout.colspan = cols;
5db4979bf482 implement new api style for ui_button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
243 }
5db4979bf482 implement new api style for ui_button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
244
5db4979bf482 implement new api style for ui_button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
245 void ui_layout_rowspan(UiObject* obj, int rows) {
5db4979bf482 implement new api style for ui_button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
246 UiContainer* ct = uic_get_current_container(obj);
5db4979bf482 implement new api style for ui_button (WinUI3)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 185
diff changeset
247 ct->layout.rowspan = rows;
185
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
248 }
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
249
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
250 void ui_newline(UiObject* obj) {
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
251 UiContainer* ct = uic_get_current_container(obj);
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
252 ct->layout.newline = TRUE;
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
253 }
4a8b1a748f09 implement grid container (WinUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 182
diff changeset
254

mercurial