13#include "fixed_string.hpp"
14#include "i18n/translate.hpp"
15#include "unicode/gstring.hpp"
16#include "pixel_map.hpp"
17#include "rapid/sfloat_rgba16.hpp"
18#include "text/glyph_ids.hpp"
19#include "text/elusive_icon.hpp"
20#include "text/hikogui_icon.hpp"
26namespace hi::inline
v1 {
36class text :
public std::variant<std::monostate, std::string, gstring, translate> {
43 [[nodiscard]]
constexpr friend bool to_bool(
text const& rhs)
noexcept
45 return not std::holds_alternative<std::monostate>(rhs);
55 [](std::monostate
const &) {
return std::string{}; },
71 [](std::monostate
const &) {
return gstring{}; },
73 [](
gstring const &x) {
return x; },
90class icon :
public std::variant<std::monostate, elusive_icon, hikogui_icon, glyph_ids, pixel_map<sfloat_rgba16>>
96 [[nodiscard]]
constexpr friend bool to_bool(
icon const& rhs)
noexcept
98 return not std::holds_alternative<std::monostate>(rhs);
104template<
typename CharT>
105struct std::formatter<
hi::text, CharT> : std::formatter<std::string_view, CharT> {
106 auto format(hi::text
const& t,
auto& fc)
108 return std::formatter<std::string_view, CharT>::format(
to_string(t), fc);
112namespace hi::inline
v1 {
139 constexpr label(std::convertible_to<hi::icon>
auto&&
icon, std::convertible_to<hi::text>
auto&&
text) noexcept :
158 constexpr label(
label const& other)
noexcept =
default;
159 constexpr label& operator=(
label const& other)
noexcept =
default;
160 constexpr label(
label&& other)
noexcept =
default;
161 constexpr label& operator=(
label&& other)
noexcept =
default;
163 [[nodiscard]]
constexpr bool empty() const noexcept
165 return not(to_bool(
icon) or to_bool(
text));
168 constexpr explicit operator bool() const noexcept
183 template<fixed_
string>
184 [[nodiscard]]
auto& get(
label&)
const noexcept;
187 [[nodiscard]]
auto& get<
"text">(
label& rhs)
const noexcept
193 [[nodiscard]]
auto& get<
"icon">(
label& rhs)
const noexcept
201template<
typename CharT>
202struct std::formatter<
hi::label, CharT> : std::formatter<hi::text, CharT> {
203 auto format(hi::label
const& t,
auto& fc)
205 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:36
constexpr friend gstring to_gstring(hi::text const &rhs) noexcept
Convert the text into a gstring.
Definition label.hpp:66
constexpr friend bool to_bool(text const &rhs) noexcept
Check if text contains a string.
Definition label.hpp:43
constexpr friend std::string to_string(hi::text const &rhs) noexcept
Convert the text into a std::string.
Definition label.hpp:50
A variant of icon.
Definition label.hpp:91
constexpr friend bool to_bool(icon const &rhs) noexcept
Check if icon contains an image.
Definition label.hpp:96
A label consisting of localizable text and an icon.
Definition label.hpp:124
hi::icon icon
The icon.
Definition label.hpp:128
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:152
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:139
hi::text text
Localizable text.
Definition label.hpp:133
constexpr label() noexcept
Construct a empty label.
Definition label.hpp:156
constexpr label(std::convertible_to< hi::text > auto &&text) noexcept
Construct a new label from text.
Definition label.hpp:147
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:592
Helper type to turn a set of lambdas into a single overloaded type to pass to std::visit().
Definition type_traits.hpp:626