10#include "utility/module.hpp"
12#include "l10n/module.hpp"
13#include "unicode/module.hpp"
14#include "image/module.hpp"
15#include "font/module.hpp"
21namespace hi::inline
v1 {
30class text_variant :
public std::variant<std::monostate, hi::text, hi::translate> {
31 using std::variant<std::monostate,
hi::text, hi::translate>::variant;
39 return not std::holds_alternative<std::monostate>(rhs);
44 [[nodiscard]]
constexpr friend text
to_text(hi::text_variant
const& rhs)
noexcept
49 [](std::monostate
const &) {
return text{}; },
51 [](hi::translate
const &x) {
return x(); }
57 [[nodiscard]]
constexpr friend gstring to_gstring(hi::text_variant
const& rhs)
noexcept
59 return to_gstring(to_text(rhs));
62 [[nodiscard]]
constexpr friend std::string to_string(hi::text_variant
const& rhs)
noexcept
64 return to_string(to_text(rhs));
81class icon :
public std::variant<std::monostate, elusive_icon, hikogui_icon, font_book::font_glyph_type, pixmap<sfloat_rgba16>> {
86 [[nodiscard]]
constexpr friend bool to_bool(
icon const& rhs)
noexcept
88 return not std::holds_alternative<std::monostate>(rhs);
94template<
typename CharT>
95struct std::formatter<
hi::text_variant, CharT> : std::formatter<std::string_view, CharT> {
96 auto format(hi::text_variant
const& t,
auto& fc)
98 return std::formatter<std::string_view, CharT>::format(
to_string(t), fc);
102namespace hi::inline
v1 {
129 constexpr label(std::convertible_to<hi::icon>
auto&&
icon, std::convertible_to<hi::text_variant>
auto&& text) noexcept :
137 constexpr label(std::convertible_to<hi::text_variant>
auto&& text) noexcept :
icon(), text(
hi_forward(text)) {}
148 constexpr label(
label const& other)
noexcept =
default;
149 constexpr label& operator=(
label const& other)
noexcept =
default;
150 constexpr label(
label&& other)
noexcept =
default;
151 constexpr label& operator=(
label&& other)
noexcept =
default;
153 [[nodiscard]]
constexpr bool empty() const noexcept
155 return not(to_bool(
icon) or to_bool(text));
158 constexpr explicit operator bool() const noexcept
173 template<fixed_
string>
174 [[nodiscard]]
auto& get(
label&)
const noexcept;
177 [[nodiscard]]
auto& get<
"text">(
label& rhs)
const noexcept
183 [[nodiscard]]
auto& get<
"icon">(
label& rhs)
const noexcept
191template<
typename CharT>
192struct std::formatter<
hi::label, CharT> : std::formatter<hi::text_variant, CharT> {
193 auto format(hi::label
const& t,
auto& fc)
195 return std::formatter<hi::text_variant, CharT>::format(t.text, fc);
#define hi_forward(x)
Forward a value, based on the decltype of the value.
Definition utility.hpp:29
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11
Definition font_book.hpp:31
A variant of text.
Definition label.hpp:30
constexpr friend bool to_bool(text_variant const &rhs) noexcept
Check if text contains a string.
Definition label.hpp:37
constexpr friend text to_text(hi::text_variant const &rhs) noexcept
Convert the text into a gstring.
Definition label.hpp:44
A variant of icon.
Definition label.hpp:81
constexpr friend bool to_bool(icon const &rhs) noexcept
Check if icon contains an image.
Definition label.hpp:86
A label consisting of localizable text and an icon.
Definition label.hpp:114
constexpr label(std::convertible_to< hi::text_variant > auto &&text) noexcept
Construct a new label from text.
Definition label.hpp:137
hi::icon icon
The icon.
Definition label.hpp:118
constexpr friend bool operator==(label const &lhs, label const &rhs) noexcept=default
Compare if both labels are equal.
constexpr label(std::convertible_to< hi::icon > auto &&icon) noexcept
Construct a new label from an icon.
Definition label.hpp:142
hi::text_variant text
Localizable text.
Definition label.hpp:123
constexpr label(std::convertible_to< hi::icon > auto &&icon, std::convertible_to< hi::text_variant > auto &&text) noexcept
Construct a new label from an icon and text.
Definition label.hpp:129
constexpr label() noexcept
Construct a empty label.
Definition label.hpp:146
This selector allows access to member variable by name.
Definition type_traits.hpp:642
Helper type to turn a set of lambdas into a single overloaded type to pass to std::visit().
Definition type_traits.hpp:671