HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
widget_baseline.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 "../alignment.hpp"
8
9namespace hi::inline v1 {
10
14public:
15 constexpr widget_baseline() noexcept = default;
16 constexpr widget_baseline(widget_baseline const&) noexcept = default;
17 constexpr widget_baseline(widget_baseline&&) noexcept = default;
18 constexpr widget_baseline& operator=(widget_baseline const&) noexcept = default;
19 constexpr widget_baseline& operator=(widget_baseline&&) noexcept = default;
20 [[nodiscard]] constexpr friend bool operator==(widget_baseline const&, widget_baseline const&) noexcept = default;
21
29 constexpr widget_baseline(
30 float priority,
32 float cap_height,
33 float graphic_height = 0.0f) noexcept :
34 _priority(priority)
35 {
36 if (alignment == vertical_alignment::top) {
37 _gain = 1.0f;
38 _bias = graphic_height * -0.5f + cap_height * -0.5f;
39 } else if (alignment == vertical_alignment::middle) {
40 _gain = 0.5f;
41 _bias = cap_height * -0.5f;
42 } else if (alignment == vertical_alignment::bottom) {
43 _gain = 0.5f;
44 _bias = graphic_height * 0.5f + cap_height * -0.5f;
45 } else {
46 hi_no_default();
47 }
48 }
49
57 constexpr widget_baseline(float priority, float gain, float bias) noexcept : _priority(priority), _gain(gain), _bias(bias) {}
58
59 [[nodiscard]] constexpr auto friend operator<=>(widget_baseline const& lhs, widget_baseline const& rhs) noexcept
60 {
61 return lhs._priority <=> rhs._priority;
62 }
63
64 [[nodiscard]] constexpr bool empty() const noexcept
65 {
66 return _priority == 0.0f;
67 }
68
69 explicit operator bool() const noexcept
70 {
71 return not empty();
72 }
73
79 [[nodiscard]] constexpr float absolute(float height) const noexcept
80 {
81 return height * _gain + _bias;
82 }
83
84private:
85 float _priority = 0.0f;
86 float _gain = 0.0f;
87 float _bias = 0.0f;
88};
89
90} // namespace hi::inline v1
vertical_alignment
Vertical alignment.
Definition alignment.hpp:17
Definition alignment.hpp:64
The base-line of a widget on which to set the text and graphics.
Definition widget_baseline.hpp:13
constexpr float absolute(float height) const noexcept
Calculate the absolute base-line.
Definition widget_baseline.hpp:79
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:29
constexpr widget_baseline(float priority, float gain, float bias) noexcept
Construct a widget base-line.
Definition widget_baseline.hpp:57