11#include "../utility/utility.hpp"
12#include "../macros.hpp"
18hi_export_module(hikogui.geometry : alignment);
20hi_export
namespace hi {
inline namespace v1 {
65 float guideline_width)
68 hi_axiom(guideline_width >= 0.0f);
70 auto const guideline_bottom =
bottom;
71 auto const guideline_top =
top - guideline_width;
72 auto const guideline_middle = (
bottom +
top - guideline_width) / 2.0f;
78 if (guideline_bottom <=
top) {
84 if (guideline_top >=
bottom) {
90 if (guideline_bottom <= guideline_top) {
91 return std::clamp(guideline_middle, guideline_bottom, guideline_top);
162 float guideline_width = 0.0f)
165 hi_axiom(guideline_width >= 0.0f);
167 auto const guideline_left =
left;
168 auto const guideline_right =
right - guideline_width;
169 auto const guideline_center = (
left +
right - guideline_width) / 2.0f;
175 if (guideline_left <=
right) {
176 return guideline_left;
181 if (guideline_right >=
left) {
182 return guideline_right;
188 if (guideline_left <= guideline_right) {
189 return std::clamp(guideline_center, guideline_left, guideline_right);
238 return resolve(
mirror(rhs, left_to_right), left_to_right);
246 constexpr alignment() noexcept : _value(0) {}
252 constexpr explicit alignment(uint8_t value) noexcept : _value(value) {}
255 _value((std::to_underlying(v) << 4) | std::to_underlying(t))
257 hi_axiom(std::to_underlying(v) <= 0xf);
258 hi_axiom(std::to_underlying(t) <= 0xf);
262 _value((std::to_underlying(v) << 4) | std::to_underlying(h))
264 hi_axiom(std::to_underlying(v) <= 0xf);
265 hi_axiom(std::to_underlying(h) <= 0xf);
268 [[nodiscard]]
constexpr static alignment top_flush()
noexcept
273 [[nodiscard]]
constexpr static alignment top_left()
noexcept
278 [[nodiscard]]
constexpr static alignment top_center()
noexcept
283 [[nodiscard]]
constexpr static alignment top_justified()
noexcept
288 [[nodiscard]]
constexpr static alignment top_right()
noexcept
293 [[nodiscard]]
constexpr static alignment middle_flush()
noexcept
298 [[nodiscard]]
constexpr static alignment middle_left()
noexcept
303 [[nodiscard]]
constexpr static alignment middle_center()
noexcept
308 [[nodiscard]]
constexpr static alignment middle_justified()
noexcept
313 [[nodiscard]]
constexpr static alignment middle_right()
noexcept
318 [[nodiscard]]
constexpr static alignment bottom_left()
noexcept
323 [[nodiscard]]
constexpr static alignment bottom_center()
noexcept
328 [[nodiscard]]
constexpr static alignment bottom_right()
noexcept
343 [[nodiscard]]
constexpr friend bool operator==(
alignment const& lhs,
alignment const& rhs)
noexcept =
default;
347 return lhs.horizontal() == rhs;
352 return lhs == rhs.horizontal();
357 return lhs.vertical() == rhs;
362 return lhs == rhs.vertical();
367 return alignment{mirror(rhs.horizontal()), rhs.vertical()};
370 [[nodiscard]]
constexpr friend alignment mirror(
alignment const& rhs,
bool left_to_right)
noexcept
372 return alignment{mirror(rhs.horizontal(), left_to_right), rhs.vertical()};
375 [[nodiscard]]
constexpr friend alignment resolve(
alignment const& rhs,
bool left_to_right)
noexcept
377 return alignment{resolve(rhs.horizontal(), left_to_right), rhs.vertical()};
380 [[nodiscard]]
constexpr friend alignment resolve_mirror(
alignment const& rhs,
bool left_to_right)
noexcept
382 return alignment{resolve_mirror(rhs.horizontal(), left_to_right), rhs.vertical()};
vertical_alignment
Vertical alignment.
Definition alignment.hpp:25
horizontal_alignment
Horizontal alignment.
Definition alignment.hpp:102
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
@ middle
Align to the vertical-middle.
@ bottom
Align to the bottom.
@ right
Align the text to the right side.
@ left
Align the text to the left side.
@ flush
Align the text naturally based on the writing direction of each paragraph.
@ justified
Stretch the text to be flush to both sides.
@ center
Align the text in the center.
The HikoGUI namespace.
Definition array_generic.hpp:20
constexpr horizontal_alignment mirror(horizontal_alignment const &rhs) noexcept
Mirror the horizontal alignment.
Definition alignment.hpp:205
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
Horizontal/Vertical alignment combination.
Definition alignment.hpp:244