HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
box_shape.hpp
1// Copyright Take Vos 2022.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "box_constraints.hpp"
8#include "../geometry/module.hpp"
9#include "../utility/module.hpp"
10#include <limits>
11#include <optional>
12
13namespace hi { inline namespace v1 {
14
15struct box_shape {
16 aarectanglei rectangle;
17 std::optional<int> baseline = {};
18 std::optional<int> centerline = {};
19
20 constexpr box_shape() noexcept = default;
21 constexpr box_shape(box_shape const&) noexcept = default;
22 constexpr box_shape(box_shape&&) noexcept = default;
23 constexpr box_shape& operator=(box_shape const&) noexcept = default;
24 constexpr box_shape& operator=(box_shape&&) noexcept = default;
25 [[nodiscard]] constexpr friend bool operator==(box_shape const&, box_shape const&) noexcept = default;
26
27 constexpr box_shape(extent2i size) noexcept : rectangle(size), baseline(), centerline() {}
28
29 constexpr box_shape(
31 box_constraints const& constraints,
32 aarectanglei const& rectangle,
33 int baseline_adjustment) noexcept :
34 rectangle(rectangle),
35 baseline(make_guideline(
36 constraints.alignment.vertical(),
37 rectangle.bottom(),
38 rectangle.top(),
39 constraints.padding.bottom(),
40 constraints.padding.top(),
41 baseline_adjustment)),
42 centerline(make_guideline(
43 constraints.alignment.horizontal(),
44 rectangle.left(),
45 rectangle.right(),
46 constraints.padding.left(),
47 constraints.padding.right()))
48 {
49 }
50
51 constexpr box_shape(box_constraints const& constraints, aarectanglei rectangle, int baseline_adjustment) noexcept :
52 box_shape(override_t{}, constraints, rectangle, baseline_adjustment)
53 {
54 hi_axiom(rectangle.size() >= constraints.minimum);
55 }
56
57 [[deprecated]] constexpr box_shape(
59 box_constraints const& constraints,
60 aarectangle const& rectangle,
61 int baseline_adjustment) noexcept :
62 box_shape(override_t{}, constraints, narrow_cast<aarectanglei>(rectangle), baseline_adjustment)
63 {
64 }
65
66 [[deprecated]] constexpr box_shape(
67 box_constraints const& constraints,
68 aarectangle const& rectangle,
69 int baseline_adjustment) noexcept :
70 box_shape(constraints, narrow_cast<aarectanglei>(rectangle), baseline_adjustment)
71 {
72 }
73
74 [[nodiscard]] constexpr int x() const noexcept
75 {
76 return rectangle.x();
77 }
78
79 [[nodiscard]] constexpr int y() const noexcept
80 {
81 return rectangle.y();
82 }
83
84 [[nodiscard]] constexpr extent2i size() const noexcept
85 {
86 return rectangle.size();
87 }
88
89 [[nodiscard]] constexpr int width() const noexcept
90 {
91 return rectangle.width();
92 }
93
94 [[nodiscard]] constexpr int height() const noexcept
95 {
96 return rectangle.height();
97 }
98};
99
100}} // namespace hi::v1
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:238
geo::extent< int, 2 > extent2i
A 2D extent.
Definition extent.hpp:512
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11
2D constraints.
Definition box_constraints.hpp:22
Definition box_shape.hpp:15
Tag used for special functions or constructions to do a override compared to another function of the ...
Definition utility.hpp:235