11#include "../observer/observer.hpp"
12#include "../utility/utility.hpp"
13#include "../concurrency/concurrency.hpp"
14#include "../dispatch/dispatch.hpp"
15#include "../GUI/GUI.hpp"
16#include "../macros.hpp"
17#include "../l10n/l10n.hpp"
18#include "../macros.hpp"
24hi_export_module(hikogui.widgets.text_field_delegate);
26hi_export
namespace hi {
inline namespace v1 {
34 using notifier_type = notifier<void()>;
37 virtual void init(
widget_intf const& sender)
noexcept {}
38 virtual void deinit(
widget_intf const& sender)
noexcept {}
75 template<forward_of<
void()> Func>
76 callback<void()> subscribe(Func&& func, callback_flags flags = callback_flags::synchronous)
noexcept
78 return _notifier.subscribe(std::forward<Func>(func), flags);
82 notifier_type _notifier;
100template<std::
integral T>
103 using value_type = T;
107 template<forward_of<observer<value_type>> Value>
110 _value_cbt = this->value.
subscribe([&](
auto...) {
118 [[maybe_unused]]
auto dummy = from_string<value_type>(to_string(text), 10);
120 return {
txt(
"Invalid integer")};
128 return to_gstring(to_string(*value));
134 value = from_string<value_type>(to_string(text), 10);
142 callback<void(value_type)> _value_cbt;
152template<std::
floating_po
int T>
155 using value_type = T;
159 template<forward_of<observer<value_type>> Value>
162 _value_cbt = this->value.
subscribe([&](
auto...) {
170 [[maybe_unused]]
auto dummy = from_string<value_type>(to_string(text));
172 return {elusive_icon::WarningSign,
txt(
"Invalid floating point number")};
180 return to_gstring(to_string(*value));
186 value = from_string<value_type>(to_string(text));
194 callback<void(value_type)> _value_cbt;
204template<
typename Value>
208 using value_type = observer_decay_t<Value>;
209 return std::make_shared<default_text_field_delegate<value_type>>(std::forward<Value>(value));
std::shared_ptr< text_field_delegate > make_default_text_field_delegate(Value &&value) noexcept
Create a shared pointer to a default text delegate.
Definition text_field_delegate.hpp:205
The HikoGUI namespace.
Definition array_generic.hpp:20
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
Definition callback.hpp:77
Definition widget_intf.hpp:24
A localizable message.
Definition txt.hpp:100
A observer pointing to the whole or part of a observed_base.
Definition observer_intf.hpp:32
callback< void(value_type)> subscribe(Func &&func, callback_flags flags=callback_flags::synchronous) noexcept
Subscribe a callback to this observer.
Definition observer_intf.hpp:456
Exception thrown during parsing on an error.
Definition exception_intf.hpp:48
A delegate that controls the state of a text_field_widget.
Definition text_field_delegate.hpp:32
virtual label validate(widget_intf const &sender, gstring const &text) noexcept
Validate the text field.
Definition text_field_delegate.hpp:46
virtual gstring text(widget_intf const &sender) noexcept
Get the text to show in the text field.
Definition text_field_delegate.hpp:58
virtual void set_text(widget_intf const &sender, gstring const &text) noexcept
Set the text as entered by the user.
Definition text_field_delegate.hpp:73
A default text delegate.
Definition text_field_delegate.hpp:91
void set_text(widget_intf const &sender, gstring const &text) noexcept override
Set the text as entered by the user.
Definition text_field_delegate.hpp:131
label validate(widget_intf const &sender, gstring const &text) noexcept override
Validate the text field.
Definition text_field_delegate.hpp:115
gstring text(widget_intf const &sender) noexcept override
Get the text to show in the text field.
Definition text_field_delegate.hpp:126