7#include "../utility/utility.hpp"
8#include "../coroutine/module.hpp"
10#include <unordered_map>
14hi_export_module(hikogui.font.font_weight);
16namespace hi::inline
v1 {
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",
62 if (rhs < 50 or rhs > 1000) {
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];
82hi_export [[nodiscard]]
constexpr std::string
to_string(font_weight
const& x)
noexcept
84 return std::string{to_string_view(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);
91 return char_cast<char>(
'0' + x_);
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_;
100hi_export
inline std::ostream& operator<<(std::ostream& lhs, font_weight
const& rhs)
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;
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
@ medium
500: Medium
Definition font_weight.hpp:23
@ black
900: Heavy / Black
Definition font_weight.hpp:27
@ light
300: Light
Definition font_weight.hpp:21
@ semi_bold
600: Semi-bold / Demi-bold
Definition font_weight.hpp:24
@ thin
100: Thin / Hairline
Definition font_weight.hpp:19
@ bold
700: Bold
Definition font_weight.hpp:25
@ extra_light
200: Ultra-light / Extra-light
Definition font_weight.hpp:20
@ regular
400: Normal / Regular
Definition font_weight.hpp:22
@ extra_bold
800: Extra-bold / Ultra-bold
Definition font_weight.hpp:26
@ extra_black
950: Extra-black / Ultra-black
Definition font_weight.hpp:28
hi_export generator< font_weight > alternatives(font_weight start) noexcept
Generate alternatives for the font_weight.
Definition font_weight.hpp:116
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
A return value for a generator-function.
Definition generator.hpp:31