7#include "../utility/utility.hpp"
8#include "../coroutine/module.hpp"
10#include <unordered_map>
14hi_export_module(hikogui.font.font_weight);
31hi_export
constexpr font_weight& operator++(font_weight& rhs)
noexcept
33 hi_axiom(rhs < font_weight::extra_black);
34 return rhs =
static_cast<font_weight
>(std::to_underlying(rhs) + 1);
37hi_export
constexpr font_weight& operator--(font_weight& rhs)
noexcept
39 hi_axiom(rhs > font_weight::thin);
40 return rhs =
static_cast<font_weight>(std::to_underlying(rhs) - 1);
44constexpr auto font_weight_metadata = enum_metadata{
45 font_weight::thin,
"thin",
46 font_weight::extra_light,
"extra-light",
47 font_weight::light,
"light",
48 font_weight::regular,
"regular",
49 font_weight::medium,
"medium",
50 font_weight::semi_bold,
"semi-bold",
51 font_weight::bold,
"bold",
52 font_weight::extra_bold,
"extra-bold",
53 font_weight::black,
"black",
54 font_weight::extra_black,
"extra-black",
63 throw parse_error(std::format(
"Unknown font-weight {}", rhs));
65 return static_cast<font_weight>(((rhs + 50) / 100) - 1);
68hi_export [[
nodiscard]]
constexpr font_weight font_weight_from_string(std::string_view rhs)
71 return font_weight_metadata.at(rhs);
73 throw parse_error(std::format(
"Unknown font-weight {}", rhs));
77hi_export [[
nodiscard]]
constexpr std::string_view to_string_view(font_weight
const& x)
noexcept
79 return font_weight_metadata[x];
87hi_export [[
nodiscard]]
constexpr char to_char(font_weight
const& x)
noexcept
89 hilet
x_ =
static_cast<int>(x);
90 hi_axiom(
x_ >= 0 &&
x_ <= 9);
94hi_export [[
nodiscard]]
constexpr int to_int(font_weight
const& x)
noexcept
96 hilet
x_ = (
static_cast<int>(x) + 1) * 100;
97 return (
x_ == 1000) ? 950 :
x_;
105hi_export
constexpr bool almost_equal(font_weight
const& lhs, font_weight
const& rhs)
noexcept
108 return (lhs > font_weight::medium) == (rhs > font_weight::medium);
122 auto forward =
false;
123 while (min > font_weight::thin
or max < font_weight::extra_black) {
124 if ((forward
and max == font_weight::extra_black)
or (
not forward
and min == font_weight::thin)) {
126 forward =
not forward;
136 forward =
not forward;
142hi_export
template<
typename CharT>
143struct std::formatter<
hi::font_weight, CharT> : std::formatter<std::string_view, CharT> {
144 auto format(hi::font_weight
const& t,
auto& fc)
const
146 return std::formatter<std::string_view, CharT>::format(hi::to_string_view(t), fc);
DOXYGEN BUG.
Definition algorithm.hpp:16
hi_export 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:60
font_weight
Definition font_weight.hpp:18
@ 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 lookahead_iterator.hpp:5
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
A return value for a generator-function.
Definition generator.hpp:31