11#include "../utility/module.hpp"
14namespace hi::inline
v1 {
59 float guideline_width)
63 hi_axiom(is_integral_value(guideline_width));
67 hilet guideline_bottom =
bottom;
68 hilet guideline_top =
top - guideline_width;
70 hilet guideline_middle =
static_cast<float>(
static_cast<long long>((
bottom +
top - guideline_width) / 2.0f + 0.5f));
76 if (guideline_bottom <=
top) {
82 if (guideline_top >=
bottom) {
88 if (guideline_bottom <= guideline_top) {
89 return std::clamp(guideline_middle, guideline_bottom, guideline_top);
159 float guideline_width = 0.0f)
163 hi_axiom(is_integral_value(guideline_width));
167 hilet guideline_left = left;
168 hilet guideline_right = right - guideline_width;
170 hilet guideline_center =
static_cast<float>(
static_cast<long long>((left + right - guideline_width) / 2.0f + 0.5f));
176 if (guideline_left <= right) {
177 return guideline_left;
182 if (guideline_right >= left) {
183 return guideline_right;
188 if (guideline_left <= guideline_right) {
189 return std::clamp(guideline_center, guideline_left, guideline_right);
221[[nodiscard]]
constexpr horizontal_alignment resolve(horizontal_alignment
const& rhs,
bool left_to_right)
noexcept
223 if (rhs == horizontal_alignment::flush or rhs == horizontal_alignment::justified) {
224 return left_to_right ? horizontal_alignment::left : horizontal_alignment::right;
230[[nodiscard]]
constexpr horizontal_alignment resolve_mirror(horizontal_alignment
const& rhs,
bool left_to_right)
noexcept
232 return resolve(
mirror(rhs, left_to_right), left_to_right);
240 constexpr alignment() noexcept : _value(0) {}
241 constexpr alignment(alignment
const&)
noexcept =
default;
242 constexpr alignment(alignment&&)
noexcept =
default;
243 constexpr alignment& operator=(alignment
const&)
noexcept =
default;
244 constexpr alignment& operator=(alignment&&)
noexcept =
default;
246 constexpr explicit alignment(uint8_t value) noexcept : _value(value) {}
249 _value((to_underlying(v) << 4) | to_underlying(t))
256 _value((to_underlying(v) << 4) | to_underlying(h))
262 [[nodiscard]]
static constexpr alignment top_flush()
noexcept
267 [[nodiscard]]
static constexpr alignment top_left()
noexcept
272 [[nodiscard]]
static constexpr alignment top_center()
noexcept
277 [[nodiscard]]
static constexpr alignment top_justified()
noexcept
282 [[nodiscard]]
static constexpr alignment top_right()
noexcept
287 [[nodiscard]]
static constexpr alignment middle_flush()
noexcept
292 [[nodiscard]]
static constexpr alignment middle_left()
noexcept
297 [[nodiscard]]
static constexpr alignment middle_center()
noexcept
302 [[nodiscard]]
static constexpr alignment middle_justified()
noexcept
307 [[nodiscard]]
static constexpr alignment middle_right()
noexcept
312 [[nodiscard]]
static constexpr alignment bottom_left()
noexcept
317 [[nodiscard]]
static constexpr alignment bottom_center()
noexcept
322 [[nodiscard]]
static constexpr alignment bottom_right()
noexcept
337 [[nodiscard]]
constexpr friend bool operator==(alignment
const& lhs, alignment
const& rhs)
noexcept =
default;
339 [[nodiscard]]
constexpr friend bool operator==(alignment
const& lhs,
horizontal_alignment const& rhs)
noexcept
341 return lhs.horizontal() == rhs;
344 [[nodiscard]]
constexpr friend bool operator==(
horizontal_alignment const& lhs, alignment
const& rhs)
noexcept
346 return lhs == rhs.horizontal();
349 [[nodiscard]]
constexpr friend bool operator==(alignment
const& lhs,
vertical_alignment const& rhs)
noexcept
351 return lhs.vertical() == rhs;
354 [[nodiscard]]
constexpr friend bool operator==(
vertical_alignment const& lhs, alignment
const& rhs)
noexcept
356 return lhs == rhs.vertical();
359 [[nodiscard]]
constexpr friend alignment mirror(alignment
const& rhs)
noexcept
361 return alignment{mirror(rhs.horizontal()), rhs.vertical()};
364 [[nodiscard]]
constexpr friend alignment mirror(alignment
const& rhs,
bool left_to_right)
noexcept
366 return alignment{mirror(rhs.horizontal(), left_to_right), rhs.vertical()};
369 [[nodiscard]]
constexpr friend alignment resolve(alignment
const& rhs,
bool left_to_right)
noexcept
371 return alignment{resolve(rhs.horizontal(), left_to_right), rhs.vertical()};
374 [[nodiscard]]
constexpr friend alignment resolve_mirror(alignment
const& rhs,
bool left_to_right)
noexcept
376 return alignment{resolve_mirror(rhs.horizontal(), left_to_right), rhs.vertical()};
#define hi_no_default(...)
This part of the code should not be reachable, unless a programming bug.
Definition assert.hpp:279
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:253
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:55
vertical_alignment
Vertical alignment.
Definition alignment.hpp:19
horizontal_alignment
Horizontal alignment.
Definition alignment.hpp:100
@ none
No alignment.
Definition alignment.hpp:22
@ middle
Align to the vertical-middle.
Definition alignment.hpp:30
@ bottom
Align to the bottom.
Definition alignment.hpp:34
@ top
Align to the top.
Definition alignment.hpp:26
@ none
No alignment.
Definition alignment.hpp:103
@ right
Align the text to the right side.
Definition alignment.hpp:134
@ left
Align the text to the left side.
Definition alignment.hpp:116
@ flush
Align the text naturally based on the writing direction of each paragraph.
Definition alignment.hpp:110
@ justified
Stretch the text to be flush to both sides.
Definition alignment.hpp:128
@ center
Align the text in the center.
Definition alignment.hpp:122
DOXYGEN BUG.
Definition algorithm.hpp:13
constexpr horizontal_alignment mirror(horizontal_alignment const &rhs) noexcept
Mirror the horizontal alignment.
Definition alignment.hpp:199
Horizontal/Vertical alignment combination.
Definition alignment.hpp:238