13#include "fixed_string.hpp"
14#include "i18n/translate.hpp"
15#include "unicode/gstring.hpp"
17#include "pixel_map.hpp"
18#include "rapid/sfloat_rgba16.hpp"
19#include "text/glyph_ids.hpp"
20#include "text/elusive_icon.hpp"
21#include "text/hikogui_icon.hpp"
27namespace hi::inline
v1 {
37class text :
public std::variant<std::monostate, std::string, gstring, translate> {
44 [[nodiscard]]
constexpr friend bool to_bool(
text const& rhs)
noexcept
46 return not std::holds_alternative<std::monostate>(rhs);
56 [](std::monostate
const &) {
return std::string{}; },
72 [](std::monostate
const &) {
return gstring{}; },
74 [](
gstring const &x) {
return x; },
91class icon :
public std::variant<std::monostate, elusive_icon, hikogui_icon, glyph_ids, pixel_map<sfloat_rgba16>>
97 [[nodiscard]]
constexpr friend bool to_bool(
icon const& rhs)
noexcept
99 return not std::holds_alternative<std::monostate>(rhs);
105template<
typename CharT>
106struct std::formatter<
hi::text, CharT> : std::formatter<std::string_view, CharT> {
107 auto format(hi::text
const& t,
auto& fc)
109 return std::formatter<std::string_view, CharT>::format(
to_string(t), fc);
113namespace hi::inline
v1 {
140 constexpr label(std::convertible_to<hi::icon>
auto&&
icon, std::convertible_to<hi::text>
auto&&
text) noexcept :
159 constexpr label(
label const& other)
noexcept =
default;
160 constexpr label& operator=(
label const& other)
noexcept =
default;
161 constexpr label(
label&& other)
noexcept =
default;
162 constexpr label& operator=(
label&& other)
noexcept =
default;
164 [[nodiscard]]
constexpr bool empty() const noexcept
166 return not(to_bool(
icon) or to_bool(
text));
169 constexpr explicit operator bool() const noexcept
184 template<fixed_
string>
185 [[nodiscard]]
auto& get(
label&)
const noexcept;
188 [[nodiscard]]
auto& get<
"text">(
label& rhs)
const noexcept
194 [[nodiscard]]
auto& get<
"icon">(
label& rhs)
const noexcept
202template<
typename CharT>
203struct std::formatter<
hi::label, CharT> : std::formatter<hi::text, CharT> {
204 auto format(hi::label
const& t,
auto& fc)
206 return std::formatter<hi::text, CharT>::format(t.text, fc);
Utilities used by the HikoGUI library itself.
#define hi_forward(x)
Forward a value, based on the decltype of the value.
Definition utility.hpp:29
constexpr std::string to_string(std::u32string_view rhs) noexcept
Conversion from UTF-32 to UTF-8.
Definition to_string.hpp:215
DOXYGEN BUG.
Definition algorithm.hpp:15
gstring to_gstring(std::u32string_view rhs, char32_t new_line_char=U'\u2029') noexcept
Convert a UTF-32 string to a grapheme-string.
The HikoGUI namespace.
Definition ascii.hpp:19
A 2D canvas of pixels.
Definition pixel_map.hpp:111
A localizable message.
Definition translate.hpp:155
A variant of text.
Definition label.hpp:37
constexpr friend gstring to_gstring(hi::text const &rhs) noexcept
Convert the text into a gstring.
Definition label.hpp:67
constexpr friend bool to_bool(text const &rhs) noexcept
Check if text contains a string.
Definition label.hpp:44
constexpr friend std::string to_string(hi::text const &rhs) noexcept
Convert the text into a std::string.
Definition label.hpp:51
A variant of icon.
Definition label.hpp:92
constexpr friend bool to_bool(icon const &rhs) noexcept
Check if icon contains an image.
Definition label.hpp:97
A label consisting of localizable text and an icon.
Definition label.hpp:125
hi::icon icon
The icon.
Definition label.hpp:129
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:153
constexpr label(std::convertible_to< hi::icon > auto &&icon, std::convertible_to< hi::text > auto &&text) noexcept
Construct a new label from an icon and text.
Definition label.hpp:140
hi::text text
Localizable text.
Definition label.hpp:134
constexpr label() noexcept
Construct a empty label.
Definition label.hpp:157
constexpr label(std::convertible_to< hi::text > auto &&text) noexcept
Construct a new label from text.
Definition label.hpp:148
A set of glyph-ids of a font which composites into a single glyph.
Definition glyph_ids.hpp:135
This selector allows access to member variable by name.
Definition type_traits.hpp:583
Helper type to turn a set of lambdas into a single overloaded type to pass to std::visit().
Definition type_traits.hpp:617