CYD-UI
A C++ library for building native graphic user interfaces
Loading...
Searching...
No Matches
stdui.cppm
Go to the documentation of this file.
1// Copyright (c) 2024, Víctor Castillo Agüero.
2// SPDX-License-Identifier: GPL-3.0-or-later
3
4module;
6
7export module cydui.std;
8
9import std;
10export import cydui;
11
12export import cydui.std.structural;
13export import cydui.std.input;
14export import cydui.std.charts;
15
16// namespace stdui {
17// #define ATTR_PROP(PROP) \
18// auto& PROP(decltype(props_t::PROP)& _##PROP) { \
19// props.PROP = _##PROP; \
20// return *this; \
21// } \
22// auto& PROP(decltype(props_t::PROP)&& _##PROP) { \
23// props.PROP = _##PROP; \
24// return *this; \
25// }
26
27// namespace layout {
28// struct COMPONENT(
29// Flow,
30// ;
31// enum class Direction{
32// HORIZONTAL,
33// VERTICAL,
34// };
35
36// struct props_t {
37// Direction dir = Direction::HORIZONTAL;
38// cydui::dimensions::dimensional_relation_t spacing = 0;
39// };
40// ATTR_PROP(dir) ATTR_PROP(spacing)
41
42// auto& horizontal() {
43// props.dir = Direction::HORIZONTAL;
44// return *this;
45// } auto& vertical() {
46// props.dir = Direction::VERTICAL;
47// return *this;
48// }
49
50// ) {
51// void horizontal_fixed_width() {
52// std::unordered_set<cydui::dimensions::dimension_t*> deps{};
53// deps.insert(&attrs->_w);
54// auto chi = $children;
55
56// for (auto& child: chi) {
57// deps.insert(&child->attrs()->_w);
58// }
59// for (auto& child: chi) {
60// auto ats = child->attrs();
61// ats->h($height);
62// ats->x(cydui::dimensions::dimensional_relation_t{
63// [=, this]() {
64// int total_w = 0;
65// for (const auto& dim: deps) {
66// if (dim != &attrs->_w) {
67// // avoid summing the container's width
68// total_w += dim->val();
69// }
70// }
71// int spacing = std::max(0, $width.val() - total_w) / ((int)deps.size() - 1);
72
73// int res = 0;
74// for (const auto& dim: deps) {
75// res += dim->val() + spacing;
76// }
77// return res;
78// },
79// deps
80// });
81// }
82// }
83// void vertical_fixed_height() {
84// std::unordered_set<cydui::dimensions::dimension_t*> deps{};
85// deps.insert(&attrs->_h);
86// auto chi = $children();
87
88// for (auto& child: chi) {
89// deps.insert(&child->attrs()->_h);
90// }
91// int index = 0;
92// for (auto& child: chi) {
93// auto ats = child->attrs();
94// ats->w($width);
95// ats->y(cydui::dimensions::dimensional_relation_t{
96// [=, this]() {
97// int total_h = 0;
98// for (const auto& dim: deps) {
99// if (dim != &attrs->_h) { // avoid summing the container's width
100// total_h += dim->val();
101// }
102// }
103// int spacing = std::max(0, $height.val() - total_h) / ((int)deps.size() - 1);
104
105// int res = 0;
106// int i = 0;
107// for (const auto& dim: deps) {
108// if (i == index)
109// break;
110// if (dim != &attrs->_h) { // avoid summing the container's width
111// res += dim->val() + spacing;
112// }
113// i++;
114// }
115// return res;
116// },
117// deps
118// });
119// index++;
120// }
121// }
122// void horizontal_free_width() {
123// auto* spacing = new cydui::dimensions::dimension_t{props.spacing};
124// std::unordered_set<cydui::dimensions::dimension_t*> deps{};
125// deps.insert(spacing);
126// auto chi = $children();
127// for (auto& child: chi) {
128// auto ats = child->attrs();
129// ats->h($height);
130// ats->x(cydui::dimensions::dimensional_relation_t{
131// [=, this]() {
132// int res = 0;
133// for (const auto& dim: deps) {
134// if (dim != spacing) {
135// res += dim->val() + spacing->val();
136// }
137// }
138// return res;
139// },
140// deps
141// });
142
143// deps.insert(&child->attrs()->_w);
144// }
145// }
146// void vertical_free_height() {
147// auto* spacing = new cydui::dimensions::dimension_t{props.spacing};
148// std::unordered_set<cydui::dimensions::dimension_t*> deps{};
149// deps.insert(spacing);
150// auto chi = $children();
151// for (auto& child: chi) {
152// auto ats = child->attrs();
153// ats->w($width);
154// ats->y(cydui::dimensions::dimensional_relation_t{
155// [=, this]() {
156// int res = 0;
157// for (const auto& dim: deps) {
158// if (dim != spacing) {
159// res += dim->val() + spacing->val();
160// }
161// }
162// return res;
163// },
164// deps
165// });
166
167// deps.insert(&child->attrs()->_h);
168// }
169// }
170
171// ON_REDRAW {
172// switch (props.dir) {
173// case Flow::Direction::HORIZONTAL:
174// if (attrs->_w_has_changed) {
175// horizontal_fixed_width();
176// } else {
177// horizontal_free_width();
178// }
179// break;
180// case Flow::Direction::VERTICAL:
181// if (attrs->_h_has_changed) {
182// vertical_fixed_height();
183// } else {
184// vertical_free_height();
185// }
186// break;
187// }
188
189// return {};
190// }
191// };
192
193// struct COMPONENT(
194// Grid,
195// {
196// unsigned int rows;
197// unsigned int cols;
198// int x_gap = 0;
199// int y_gap = 0;
200// };
201// ATTR_PROP(rows) ATTR_PROP(cols) ATTR_PROP(x_gap) ATTR_PROP(y_gap) STATE {
202// std::unordered_map<cydui::components::component_base_t*, std::pair<int, int>> positions{};
203// std::unordered_map<cydui::components::component_base_t*, std::pair<int, int>> sizes{};
204// }
205// ) {
206// ON_REDRAW {
207// state.positions.clear();
208// state.sizes.clear();
209// auto chi = $children();
210// std::unordered_set<cydui::dimensions::dimension_t*> deps{};
211// deps.insert(&attrs->_w);
212// deps.insert(&attrs->_h);
213
214// for (auto& child: chi) {
215// auto ats = child->attrs();
216// state.positions[child] = {ats->_x, ats->_y};
217// state.sizes[child] = {ats->_w, ats->_h};
218
219// ats->x(cydui::dimensions::dimensional_relation_t{
220// [=, this]() {
221// auto [grid_x, _] = state.positions[child];
222// int total_w = attrs->_w;
223// int step = total_w / (int)props.cols;
224// return grid_x * step + (props.x_gap / 2);
225// },
226// deps
227// });
228// ats->y(cydui::dimensions::dimensional_relation_t{
229// [=, this]() {
230// auto [_, grid_y] = state.positions[child];
231// int total_h = attrs->_h;
232// int step = total_h / (int)props.rows;
233// return grid_y * step + (props.y_gap / 2);
234// },
235// deps
236// });
237// ats->w(cydui::dimensions::dimensional_relation_t{
238// [=, this]() {
239// auto [grid_w, _] = state.sizes[child];
240// int total_w = attrs->_w;
241// int step = total_w / (int)props.cols;
242// return grid_w * step - props.x_gap;
243// },
244// deps
245// });
246// ats->h(cydui::dimensions::dimensional_relation_t{
247// [=, this]() {
248// auto [_, grid_h] = state.sizes[child];
249// int total_h = attrs->_h;
250// int step = total_h / (int)props.rows;
251// return grid_h * step - props.y_gap;
252// },
253// deps
254// });
255// }
256// return {};
257// }
258// };
259// }
260
261// template<typename F>
262// using fun = std::function<F>;
263
264// namespace control {
265// // Button
266// struct COMPONENT(
267// Button,
268// {
269// fun<void(int)> on_click;
270// }
271// ) {
272// };
273// // Toggle Button (checkbox, radial toggle,...)
274// // Slider
275// }
276
277// namespace media {
278// // Image
279// // Video / Video Player
280// // Audio / Audio Player
281// }
282
283// using namespace layout;
284// }