11#include "../i18n/translate.hpp"
12#include "../unicode/gstring.hpp"
18namespace hi {
inline namespace v1 {
27 using notifier_type = notifier<>;
28 using callback_token = notifier_type::callback_token;
29 using callback_proto = notifier_type::callback_proto;
34 virtual void deinit(
text_widget& sender)
noexcept {}
46 [[nodiscard]] callback_token
47 subscribe(forward_of<callback_proto>
auto&& callback, callback_flags flags = callback_flags::synchronous)
noexcept
49 return _notifier.subscribe(
hi_forward(callback), flags);
53 notifier_type _notifier;
73 observer<value_type> value;
81 _value_cbt = this->value.subscribe([&](
auto...) {
88 return to_gstring(*value);
97 typename decltype(value)::callback_token _value_cbt;
107 using value_type = gstring;
109 observer<value_type> value;
117 _value_cbt = this->value.subscribe([&](
auto...) {
129 *value.copy() = text;
133 typename decltype(value)::callback_token _value_cbt;
143 using value_type = translate;
145 observer<value_type> value;
153 _value_cbt = this->value.subscribe([&](
auto...) {
160 return to_gstring(value.read()());
169 typename decltype(value)::callback_token _value_cbt;
179 using value_type = text;
181 observer<value_type> value;
189 _value_cbt = this->value.subscribe([&](
auto...) {
196 return to_gstring(*value.read());
201 auto proxy = value.copy();
204 if (
auto *string_ptr = get_if<std::string>(ptr)) {
206 }
else if (
auto *gstring_ptr = get_if<gstring>(ptr)) {
214 typename decltype(value)::callback_token _value_cbt;
#define hi_not_implemented()
This part of the code has not been implemented yet.
Definition assert.hpp:182
#define hi_no_default()
This part of the code should not be reachable, unless a programming bug.
Definition assert.hpp:145
#define hi_forward(x)
Forward a value, based on the decltype of the value.
Definition utility.hpp:29
Functionality for labels, text and icons.
constexpr std::string to_string(std::u32string_view rhs) noexcept
Conversion from UTF-32 to UTF-8.
Definition to_string.hpp:215
std::shared_ptr< text_delegate > make_default_text_delegate(auto &&value) noexcept
Create a shared pointer to a default text delegate.
Definition text_delegate.hpp:224
DOXYGEN BUG.
Definition algorithm.hpp:15
The HikoGUI namespace.
Definition ascii.hpp:19
A delegate that controls the state of a text_widget.
Definition text_delegate.hpp:25
virtual gstring read(text_widget &sender) noexcept=0
Read text as a string of graphemes.
callback_token subscribe(forward_of< callback_proto > auto &&callback, callback_flags flags=callback_flags::synchronous) noexcept
Subscribe a callback for notifying the widget of a data change.
Definition text_delegate.hpp:47
virtual void write(text_widget &sender, gstring const &text) noexcept=0
Write text from a string of graphemes.
A default text delegate.
Definition text_delegate.hpp:62
default_text_delegate(forward_of< observer< value_type > > auto &&value) noexcept
Construct a delegate.
Definition text_delegate.hpp:79
gstring read(text_widget &sender) noexcept override
Read text as a string of graphemes.
Definition text_delegate.hpp:86
void write(text_widget &sender, gstring const &text) noexcept override
Write text from a string of graphemes.
Definition text_delegate.hpp:91
default_text_delegate(forward_of< observer< value_type > > auto &&value) noexcept
Construct a delegate.
Definition text_delegate.hpp:115
void write(text_widget &sender, gstring const &text) noexcept override
Write text from a string of graphemes.
Definition text_delegate.hpp:127
gstring read(text_widget &sender) noexcept override
Read text as a string of graphemes.
Definition text_delegate.hpp:122
default_text_delegate(forward_of< observer< value_type > > auto &&value) noexcept
Construct a delegate.
Definition text_delegate.hpp:151
gstring read(text_widget &sender) noexcept override
Read text as a string of graphemes.
Definition text_delegate.hpp:158
void write(text_widget &sender, gstring const &text) noexcept override
Write text from a string of graphemes.
Definition text_delegate.hpp:163
gstring read(text_widget &sender) noexcept override
Read text as a string of graphemes.
Definition text_delegate.hpp:194
default_text_delegate(forward_of< observer< value_type > > auto &&value) noexcept
Construct a delegate.
Definition text_delegate.hpp:187
void write(text_widget &sender, gstring const &text) noexcept override
Write text from a string of graphemes.
Definition text_delegate.hpp:199
A text widget.
Definition text_widget.hpp:61