sandbox
Loading...
Searching...
No Matches
layout.hpp
1// SPDX-License-Identifier: MIT
2#ifndef LIBSBX_UI_LAYOUT_HPP_
3#define LIBSBX_UI_LAYOUT_HPP_
4
5#include <vector>
6#include <memory>
7#include <limits>
8
9#include <libsbx/math/vector2.hpp>
10
11namespace sbx::ui {
12
13class element;
14
15struct rectangle {
16 std::float_t x{0.0f};
17 std::float_t y{0.0f};
18 std::float_t width{0.0f};
19 std::float_t height{0.0f};
20
21 [[nodiscard]] auto contains(const math::vector2& point) const -> bool;
22
23}; // struct rectangle
24
25struct padding {
26 std::float_t top{0.0f};
27 std::float_t right{0.0f};
28 std::float_t bottom{0.0f};
29 std::float_t left{0.0f};
30}; // struct padding
31
32struct size_hints {
33 math::vector2 preferred{0.0f, 0.0f};
34 math::vector2 min{0.0f, 0.0f};
35 math::vector2 max{std::numeric_limits<std::float_t>::max(), std::numeric_limits<std::float_t>::max()};
36 std::float_t flex{0.0f};
37}; // struct size_hints
38
39class layout {
40
41public:
42
44
45 layout() = default;
46
47 virtual ~layout() = default;
48
49 virtual auto arrange(const rectangle& bounds, std::vector<std::unique_ptr<element>>& children) -> void = 0;
50
51protected:
52
53 [[nodiscard]] auto content_rectangle(const rectangle& bounds) const -> rectangle;
54
55}; // class layout
56
57} // namespace sbx::ui
58
59#endif // LIBSBX_UI_LAYOUT_HPP_
A vector in two-dimensional space.
Definition: vector2.hpp:28
Definition: layout.hpp:39
Definition: layout.hpp:25
Definition: layout.hpp:15
Definition: layout.hpp:32