11#include "../utility/utility.hpp"
12#include "../macros.hpp"
17namespace hi {
inline namespace v1 {
66 float guideline_width)
69 hi_axiom(guideline_width >= 0.0f);
71 hilet guideline_bottom =
bottom + padding_bottom;
72 hilet guideline_top =
top - padding_top - guideline_width;
73 hilet guideline_middle = (
bottom +
top - guideline_width) / 2.0f;
79 if (guideline_bottom <=
top) {
85 if (guideline_top >=
bottom) {
91 if (guideline_bottom <= guideline_top) {
92 return std::clamp(guideline_middle, guideline_bottom, guideline_top);
167 float guideline_width = 0.0f)
170 hi_axiom(guideline_width >= 0.0f);
172 hilet guideline_left =
left + padding_left;
173 hilet guideline_right =
right - padding_right - guideline_width;
174 hilet guideline_center = (
left +
right - guideline_width) / 2.0f;
180 if (guideline_left <=
right) {
181 return guideline_left;
186 if (guideline_right >=
left) {
187 return guideline_right;
192 if (guideline_left <= guideline_right) {
193 return std::clamp(guideline_center, guideline_left, guideline_right);
236 return resolve(
mirror(rhs, left_to_right), left_to_right);
244 constexpr alignment() noexcept : _value(0) {}
250 constexpr explicit alignment(uint8_t value) noexcept : _value(value) {}
253 _value((std::to_underlying(v) << 4) | std::to_underlying(t))
255 hi_axiom(std::to_underlying(v) <= 0xf);
256 hi_axiom(std::to_underlying(t) <= 0xf);
260 _value((std::to_underlying(v) << 4) | std::to_underlying(h))
262 hi_axiom(std::to_underlying(v) <= 0xf);
263 hi_axiom(std::to_underlying(h) <= 0xf);
266 [[nodiscard]]
constexpr static alignment top_flush()
noexcept
271 [[nodiscard]]
constexpr static alignment top_left()
noexcept
276 [[nodiscard]]
constexpr static alignment top_center()
noexcept
281 [[nodiscard]]
constexpr static alignment top_justified()
noexcept
286 [[nodiscard]]
constexpr static alignment top_right()
noexcept
291 [[nodiscard]]
constexpr static alignment middle_flush()
noexcept
296 [[nodiscard]]
constexpr static alignment middle_left()
noexcept
301 [[nodiscard]]
constexpr static alignment middle_center()
noexcept
306 [[nodiscard]]
constexpr static alignment middle_justified()
noexcept
311 [[nodiscard]]
constexpr static alignment middle_right()
noexcept
316 [[nodiscard]]
constexpr static alignment bottom_left()
noexcept
321 [[nodiscard]]
constexpr static alignment bottom_center()
noexcept
326 [[nodiscard]]
constexpr static alignment bottom_right()
noexcept
341 [[nodiscard]]
constexpr friend bool operator==(
alignment const& lhs,
alignment const& rhs)
noexcept =
default;
345 return lhs.horizontal() == rhs;
350 return lhs == rhs.horizontal();
355 return lhs.vertical() == rhs;
360 return lhs == rhs.vertical();
370 return alignment{
mirror(rhs.horizontal(), left_to_right), rhs.vertical()};
373 [[nodiscard]]
constexpr friend alignment resolve(
alignment const& rhs,
bool left_to_right)
noexcept
375 return alignment{resolve(rhs.horizontal(), left_to_right), rhs.vertical()};
378 [[nodiscard]]
constexpr friend alignment resolve_mirror(
alignment const& rhs,
bool left_to_right)
noexcept
380 return alignment{resolve_mirror(rhs.horizontal(), left_to_right), rhs.vertical()};
vertical_alignment
Vertical alignment.
Definition alignment.hpp:22
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
horizontal_alignment
Horizontal alignment.
Definition alignment.hpp:103
@ none
No alignment.
Definition alignment.hpp:25
@ middle
Align to the vertical-middle.
Definition alignment.hpp:33
@ bottom
Align to the bottom.
Definition alignment.hpp:37
@ top
Align to the top.
Definition alignment.hpp:29
@ none
No alignment.
Definition alignment.hpp:106
@ right
Align the text to the right side.
Definition alignment.hpp:137
@ left
Align the text to the left side.
Definition alignment.hpp:119
@ flush
Align the text naturally based on the writing direction of each paragraph.
Definition alignment.hpp:113
@ justified
Stretch the text to be flush to both sides.
Definition alignment.hpp:131
@ center
Align the text in the center.
Definition alignment.hpp:125
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
The HikoGUI API version 1.
Definition lookahead_iterator.hpp:6
constexpr horizontal_alignment mirror(horizontal_alignment const &rhs) noexcept
Mirror the horizontal alignment.
Definition alignment.hpp:203
Horizontal/Vertical alignment combination.
Definition alignment.hpp:242