7#include "../utility/utility.hpp"
8#include "../macros.hpp"
11#include <unordered_map>
17hi_export_module(hikogui.font.font_weight);
19hi_export
namespace hi::inline
v1 {
34constexpr font_weight& operator++(font_weight& rhs)
noexcept
36 hi_axiom(rhs < font_weight::extra_black);
37 return rhs =
static_cast<font_weight
>(std::to_underlying(rhs) + 1);
40constexpr font_weight& operator--(font_weight& rhs)
noexcept
42 hi_axiom(rhs > font_weight::thin);
43 return rhs =
static_cast<font_weight>(std::to_underlying(rhs) - 1);
47constexpr auto font_weight_metadata = enum_metadata{
48 font_weight::thin,
"thin",
49 font_weight::extra_light,
"extra-light",
50 font_weight::light,
"light",
51 font_weight::regular,
"regular",
52 font_weight::medium,
"medium",
53 font_weight::semi_bold,
"semi-bold",
54 font_weight::bold,
"bold",
55 font_weight::extra_bold,
"extra-bold",
56 font_weight::black,
"black",
57 font_weight::extra_black,
"extra-black",
65 if (rhs < 50 or rhs > 1000) {
66 throw parse_error(std::format(
"Unknown font-weight {}", rhs));
68 return static_cast<font_weight>(((rhs + 50) / 100) - 1);
71[[nodiscard]]
constexpr font_weight font_weight_from_string(std::string_view rhs)
73 if (
auto weight = font_weight_metadata.at_if(rhs)) {
76 throw parse_error(std::format(
"Unknown font-weight {}", rhs));
80[[nodiscard]]
constexpr std::string_view to_string_view(font_weight
const& x)
noexcept
82 return font_weight_metadata[x];
90[[nodiscard]]
constexpr char to_char(font_weight
const& x)
noexcept
92 auto const x_ =
static_cast<int>(x);
93 hi_axiom(x_ >= 0 && x_ <= 9);
94 return char_cast<char>(
'0' + x_);
97[[nodiscard]]
constexpr int to_int(font_weight
const& x)
noexcept
99 auto const x_ = (
static_cast<int>(x) + 1) * 100;
100 return (x_ == 1000) ? 950 : x_;
108constexpr bool almost_equal(font_weight
const& lhs, font_weight
const& rhs)
noexcept
111 return (lhs > font_weight::medium) == (rhs > font_weight::medium);
125 auto forward =
false;
126 while (min > font_weight::thin or max < font_weight::extra_black) {
127 if ((forward and max == font_weight::extra_black) or (not forward and min == font_weight::thin)) {
129 forward = not forward;
139 forward = not forward;
147struct std::formatter<
hi::font_weight, char> : std::formatter<std::string_view, char> {
148 auto format(hi::font_weight
const& t,
auto& fc)
const
150 return std::formatter<std::string_view, char>::format(hi::to_string_view(t), fc);
The HikoGUI namespace.
Definition array_generic.hpp:20
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
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:63
font_weight
Definition font_weight.hpp:21
@ 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
A return value for a generator-function.
Definition generator.hpp:31