7#include "../utility/module.hpp"
8#include "../strings.hpp"
9#include "../generator.hpp"
11#include <unordered_map>
15namespace hi::inline
v1 {
30constexpr font_weight& operator++(font_weight& rhs)
noexcept
32 hi_axiom(rhs < font_weight::extra_black);
33 return rhs =
static_cast<font_weight
>(to_underlying(rhs) + 1);
36constexpr font_weight& operator--(font_weight& rhs)
noexcept
39 return rhs =
static_cast<font_weight>(to_underlying(rhs) - 1);
43constexpr auto font_weight_metadata = enum_metadata{
44 font_weight::thin,
"thin",
45 font_weight::extra_light,
"extra-light",
46 font_weight::light,
"light",
47 font_weight::regular,
"regular",
48 font_weight::medium,
"medium",
49 font_weight::semi_bold,
"semi-bold",
50 font_weight::bold,
"bold",
51 font_weight::extra_bold,
"extra-bold",
52 font_weight::black,
"black",
53 font_weight::extra_black,
"extra-black",
61 if (rhs < 50 || rhs > 1000) {
62 throw parse_error(std::format(
"Unknown font-weight {}", rhs));
64 return static_cast<font_weight>(((rhs + 50) / 100) - 1);
67[[nodiscard]]
constexpr font_weight font_weight_from_string(std::string_view rhs)
70 return font_weight_metadata.at(rhs);
72 throw parse_error(std::format(
"Unknown font-weight {}", rhs));
76[[nodiscard]]
constexpr std::string_view to_string_view(font_weight
const& x)
noexcept
78 return font_weight_metadata[x];
86[[nodiscard]]
constexpr char to_char(font_weight
const& x)
noexcept
88 hilet x_ =
static_cast<int>(x);
90 return char_cast<char>(
'0' + x_);
93[[nodiscard]]
constexpr int to_int(font_weight
const& x)
noexcept
95 hilet x_ = (
static_cast<int>(x) + 1) * 100;
96 return (x_ == 1000) ? 950 : x_;
104constexpr bool almost_equal(font_weight
const& lhs, font_weight
const& rhs)
noexcept
107 return (lhs > font_weight::medium) == (rhs > font_weight::medium);
121 auto forward =
false;
122 while (min > font_weight::thin and max < font_weight::extra_black) {
123 if ((forward and max == font_weight::extra_black) or (not forward and min == font_weight::thin)) {
125 forward = not forward;
135 forward = not forward;
141template<
typename CharT>
142struct std::formatter<
hi::font_weight, CharT> : std::formatter<std::string_view, CharT> {
143 auto format(hi::font_weight
const& t,
auto& fc)
145 return std::formatter<std::string_view, CharT>::format(hi::to_string_view(t), fc);
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:253
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
DOXYGEN BUG.
Definition algorithm.hpp:13
constexpr font_weight font_weight_from_int(numeric_integral auto rhs)
Convert a font weight value between 50 and 1000 to a font weight.
Definition font_weight.hpp:59
font_weight
Definition font_weight.hpp:17
@ black
900: Heavy / Black
@ semi_bold
600: Semi-bold / Demi-bold
@ thin
100: Thin / Hairline
@ extra_light
200: Ultra-light / Extra-light
@ regular
400: Normal / Regular
@ extra_bold
800: Extra-bold / Ultra-bold
@ extra_black
950: Extra-black / Ultra-black
geometry/margins.hpp
Definition cache.hpp:11
A return value for a generator-function.
Definition generator.hpp:29
Definition concepts.hpp:24