Simple GUI Library
utils.h
Go to the documentation of this file.
1/**
2 * @author Nikita Mochalov (github.com/tralf-strues)
3 * @file utils.h
4 * @date 2021-11-07
5 *
6 * @copyright Copyright (c) 2021
7 */
8
9#pragma once
10
11/**
12 * type = {Pref, Min, Max}
13 * dimension = {Width, Height}
14 * axis = {X, Y}
15 * children = children container
16 */
17#define COMPONENT_COMPUTE_DIMENSION(type, dimension, dependency, axis, children, enabledValue, addition) \
18 if (enabledValue != Sgl::Component::USE_COMPUTED_SIZE) { return enabledValue; } \
19 \
20 int32_t min##axis = INT32_MAX; \
21 int32_t max##axis = 0; \
22 for (const Component* child : children) \
23 { \
24 int32_t child##axis = child->getLayout##axis(); \
25 int32_t child##dimension = child->compute##type##dimension(dependency); \
26 \
27 if (child##dimension == Sgl::Component::UNLIMITED_SIZE) \
28 { \
29 return Sgl::Component::UNLIMITED_SIZE; \
30 } \
31 \
32 min##axis = std::min(min##axis, child##axis); \
33 max##axis = std::max(max##axis, child##axis + child##dimension); \
34 } \
35 \
36 if (min##axis != INT32_MAX) \
37 { \
38 return max##axis + addition; \
39 } \
40 \
41 return addition;