HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
widget_baseline.hpp
Go to the documentation of this file.
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
9#pragma once
10
11#include "../alignment.hpp"
12
13namespace hi { inline namespace v1 {
14
20public:
21 constexpr widget_baseline() noexcept = default;
22 constexpr widget_baseline(widget_baseline const&) noexcept = default;
23 constexpr widget_baseline(widget_baseline&&) noexcept = default;
24 constexpr widget_baseline& operator=(widget_baseline const&) noexcept = default;
25 constexpr widget_baseline& operator=(widget_baseline&&) noexcept = default;
26 [[nodiscard]] constexpr friend bool operator==(widget_baseline const&, widget_baseline const&) noexcept = default;
27
35 constexpr widget_baseline(
36 float priority,
37 vertical_alignment alignment,
38 float cap_height,
39 float graphic_height = 0.0f) noexcept :
40 _priority(priority)
41 {
42 if (alignment == vertical_alignment::top) {
43 _gain = 1.0f;
44 _bias = graphic_height * -0.5f + cap_height * -0.5f;
45 } else if (alignment == vertical_alignment::middle) {
46 _gain = 0.5f;
47 _bias = cap_height * -0.5f;
48 } else if (alignment == vertical_alignment::bottom) {
49 _gain = 0.5f;
50 _bias = graphic_height * 0.5f + cap_height * -0.5f;
51 } else {
52 hi_no_default();
53 }
54 }
55
63 constexpr widget_baseline(float priority, float gain, float bias) noexcept : _priority(priority), _gain(gain), _bias(bias) {}
64
65 [[nodiscard]] constexpr auto friend operator<=>(widget_baseline const& lhs, widget_baseline const& rhs) noexcept
66 {
67 return lhs._priority <=> rhs._priority;
68 }
69
70 [[nodiscard]] constexpr bool empty() const noexcept
71 {
72 return _priority == 0.0f;
73 }
74
75 explicit operator bool() const noexcept
76 {
77 return not empty();
78 }
79
85 [[nodiscard]] constexpr float absolute(float height) const noexcept
86 {
87 return height * _gain + _bias;
88 }
89
90private:
91 float _priority = 0.0f;
92 float _gain = 0.0f;
93 float _bias = 0.0f;
94};
95
96}} // namespace hi::v1
DOXYGEN BUG.
Definition algorithm.hpp:15
The HikoGUI namespace.
Definition ascii.hpp:19
The base-line of a widget on which to set the text and graphics.
Definition widget_baseline.hpp:19
constexpr float absolute(float height) const noexcept
Calculate the absolute base-line.
Definition widget_baseline.hpp:85
constexpr widget_baseline(float priority, vertical_alignment alignment, float cap_height, float graphic_height=0.0f) noexcept
Construct a widget base-line.
Definition widget_baseline.hpp:35
constexpr widget_baseline(float priority, float gain, float bias) noexcept
Construct a widget base-line.
Definition widget_baseline.hpp:63