12#include "../observer/module.hpp"
18namespace hi {
inline namespace v1 {
19class text_field_widget;
27 using notifier_type = notifier<>;
28 using callback_token = notifier_type::callback_token;
29 using callback_proto = notifier_type::callback_proto;
71 subscribe(forward_of<callback_proto>
auto&& callback, callback_flags flags = callback_flags::synchronous)
noexcept
73 return _notifier.subscribe(
hi_forward(callback), flags);
77 notifier_type _notifier;
95template<std::
integral T>
100 observer<value_type> value;
104 _value_cbt = this->value.subscribe([&](
auto...) {
112 [[maybe_unused]]
auto dummy = from_string<value_type>(
to_string(text), 10);
114 return {tr{
"Invalid integer"}};
128 value = from_string<value_type>(
to_string(text), 10);
136 typename decltype(value)::callback_token _value_cbt;
146template<std::
floating_po
int T>
147class default_text_field_delegate<T> :
public text_field_delegate {
149 using value_type = T;
151 observer<value_type> value;
153 default_text_field_delegate(forward_of<observer<value_type>>
auto&& value) noexcept : value(
hi_forward(value))
155 _value_cbt = this->value.subscribe([&](
auto...) {
163 [[maybe_unused]]
auto dummy = from_string<value_type>(
to_string(text));
165 return {elusive_icon::WarningSign, tr{
"Invalid floating point number"}};
179 value = from_string<value_type>(
to_string(text));
187 typename decltype(value)::callback_token _value_cbt;
202 using value_type = observer_decay_t<
decltype(value)>;
203 return std::make_shared<default_text_field_delegate<value_type>>(
hi_forward(value));
Functionality for labels, text and icons.
#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
std::shared_ptr< text_field_delegate > make_default_text_field_delegate(auto &&value) noexcept
Create a shared pointer to a default text delegate.
Definition text_field_delegate.hpp:197
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11
Exception thrown during parsing on an error.
Definition exception.hpp:63
A delegate that controls the state of a text_field_widget.
Definition text_field_delegate.hpp:25
virtual gstring text(text_field_widget &sender) noexcept
Get the text to show in the text field.
Definition text_field_delegate.hpp:53
virtual label validate(text_field_widget &sender, gstring const &text) noexcept
Validate the text field.
Definition text_field_delegate.hpp:41
virtual void set_text(text_field_widget &sender, gstring const &text) noexcept
Set the text as entered by the user.
Definition text_field_delegate.hpp:68
A default text delegate.
Definition text_field_delegate.hpp:86
label validate(text_field_widget &sender, gstring const &text) noexcept override
Validate the text field.
Definition text_field_delegate.hpp:160
gstring text(text_field_widget &sender) noexcept override
Get the text to show in the text field.
Definition text_field_delegate.hpp:120
std::optional< label > validate(text_field_widget &sender, gstring const &text) noexcept override
Validate the text field.
Definition text_field_delegate.hpp:109
void set_text(text_field_widget &sender, gstring const &text) noexcept override
Set the text as entered by the user.
Definition text_field_delegate.hpp:176
A single line text field.
Definition text_field_widget.hpp:62