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/geometry.hpp"
9#include "../utility/utility.hpp"
10#include "../macros.hpp"
11#include <limits>
12#include <optional>
13
14hi_export_module(hikogui.layout.box_shape);
15
16hi_export namespace 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(
33 std::in_place_t,
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 baseline_adjustment)),
43 centerline(make_guideline(
44 constraints.alignment.horizontal(),
45 rectangle.left(),
46 rectangle.right()))
47 {
48 }
49
50 constexpr box_shape(box_constraints const& constraints, aarectangle rectangle, float baseline_adjustment) noexcept :
51 box_shape(std::in_place, constraints, rectangle, baseline_adjustment)
52 {
53 hi_axiom(rectangle.size() >= constraints.minimum);
54 }
55
56 [[nodiscard]] constexpr float x() const noexcept
57 {
58 return rectangle.x();
59 }
60
61 [[nodiscard]] constexpr float y() const noexcept
62 {
63 return rectangle.y();
64 }
65
66 [[nodiscard]] constexpr extent2 size() const noexcept
67 {
68 return rectangle.size();
69 }
70
71 [[nodiscard]] constexpr float width() const noexcept
72 {
73 return rectangle.width();
74 }
75
76 [[nodiscard]] constexpr float height() const noexcept
77 {
78 return rectangle.height();
79 }
80};
81
82}} // namespace hi::v1
constexpr std::optional< float > make_guideline(vertical_alignment alignment, float bottom, float top, float guideline_width)
Create a guideline between two points.
Definition alignment.hpp:61
The HikoGUI namespace.
Definition array_generic.hpp:20
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
Class which represents an axis-aligned rectangle.
Definition aarectangle.hpp:33
A high-level geometric extent.
Definition extent2.hpp:32
A rectangle / parallelogram in 3D space.
Definition rectangle.hpp:25
float height() const noexcept
The height, or length of the up vector.
Definition rectangle.hpp:152
float width() const noexcept
The width, or length of the right vector.
Definition rectangle.hpp:145
constexpr extent2 size() const noexcept
The size, or length of the right and up vectors.
Definition rectangle.hpp:159
2D constraints.
Definition box_constraints.hpp:25
Definition box_shape.hpp:18