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/utility.hpp"
10#include "../macros.hpp"
11#include <limits>
12#include <optional>
13
14
15
16namespace hi { inline namespace v1 {
17
18struct box_shape {
20 std::optional<float> baseline = {};
21 std::optional<float> centerline = {};
22
23 constexpr box_shape() noexcept = default;
24 constexpr box_shape(box_shape const&) noexcept = default;
25 constexpr box_shape(box_shape&&) noexcept = default;
26 constexpr box_shape& operator=(box_shape const&) noexcept = default;
27 constexpr box_shape& operator=(box_shape&&) noexcept = default;
28 [[nodiscard]] constexpr friend bool operator==(box_shape const&, box_shape const&) noexcept = default;
29
30 constexpr box_shape(extent2 size) noexcept : rectangle(size), baseline(), centerline() {}
31
32 constexpr box_shape(
34 box_constraints const& constraints,
36 float baseline_adjustment) noexcept :
38 baseline(make_guideline(
39 constraints.alignment.vertical(),
40 rectangle.bottom(),
41 rectangle.top(),
42 constraints.padding.bottom(),
43 constraints.padding.top(),
44 baseline_adjustment)),
45 centerline(make_guideline(
46 constraints.alignment.horizontal(),
47 rectangle.left(),
48 rectangle.right(),
49 constraints.padding.left(),
50 constraints.padding.right()))
51 {
52 }
53
54 constexpr box_shape(box_constraints const& constraints, aarectangle rectangle, float baseline_adjustment) noexcept :
55 box_shape(override_t{}, constraints, rectangle, baseline_adjustment)
56 {
57 hi_axiom(rectangle.size() >= constraints.minimum);
58 }
59
60 [[nodiscard]] constexpr float x() const noexcept
61 {
62 return rectangle.x();
63 }
64
65 [[nodiscard]] constexpr float y() const noexcept
66 {
67 return rectangle.y();
68 }
69
70 [[nodiscard]] constexpr extent2 size() const noexcept
71 {
72 return rectangle.size();
73 }
74
75 [[nodiscard]] constexpr float width() const noexcept
76 {
77 return rectangle.width();
78 }
79
80 [[nodiscard]] constexpr float height() const noexcept
81 {
82 return rectangle.height();
83 }
84};
85
86}} // namespace hi::v1
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:60
DOXYGEN BUG.
Definition algorithm.hpp:16
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
Class which represents an axis-aligned rectangle.
Definition aarectangle.hpp:29
A high-level geometric extent.
Definition extent2.hpp:29
A rectangle / parallelogram in 3D space.
Definition rectangle.hpp:21
float height() const noexcept
The height, or length of the up vector.
Definition rectangle.hpp:148
float width() const noexcept
The width, or length of the right vector.
Definition rectangle.hpp:141
constexpr extent2 size() const noexcept
The size, or length of the right and up vectors.
Definition rectangle.hpp:155
2D constraints.
Definition box_constraints.hpp:25
Definition box_shape.hpp:18
Tag used for special functions or constructions to do a override compared to another function of the ...
Definition misc.hpp:79