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 {
17 std::optional<float> baseline = {};
18 std::optional<float> 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(extent2 size) noexcept : rectangle(size), baseline(), centerline() {}
28
29 constexpr box_shape(
31 box_constraints const& constraints,
33 float baseline_adjustment) noexcept :
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, aarectangle rectangle, float baseline_adjustment) noexcept :
52 box_shape(override_t{}, constraints, rectangle, baseline_adjustment)
53 {
54 hi_axiom(rectangle.size() >= constraints.minimum);
55 }
56
57 [[nodiscard]] constexpr float x() const noexcept
58 {
59 return rectangle.x();
60 }
61
62 [[nodiscard]] constexpr float y() const noexcept
63 {
64 return rectangle.y();
65 }
66
67 [[nodiscard]] constexpr extent2 size() const noexcept
68 {
69 return rectangle.size();
70 }
71
72 [[nodiscard]] constexpr float width() const noexcept
73 {
74 return rectangle.width();
75 }
76
77 [[nodiscard]] constexpr float height() const noexcept
78 {
79 return rectangle.height();
80 }
81};
82
83}} // namespace hi::v1
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:253
constexpr std::optional< float > make_guideline(vertical_alignment alignment, float bottom, float top, float padding_bottom, float padding_top, float guideline_width)
Create a guideline between two points.
Definition alignment.hpp:57
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11
Class which represents an axis-aligned rectangle.
Definition aarectangle.hpp:26
A high-level geometric extent.
Definition extent2.hpp:26
A rectangle / parallelogram in 3D space.
Definition rectangle.hpp:20
float height() const noexcept
The height, or length of the up vector.
Definition rectangle.hpp:147
float width() const noexcept
The width, or length of the right vector.
Definition rectangle.hpp:140
constexpr extent2 size() const noexcept
The size, or length of the right and up vectors.
Definition rectangle.hpp:154
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:223