HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
text_field_delegate.hpp
1// Copyright Take Vos 2021.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include <string>
8#include <string_view>
9#include <optional>
10#include "../label.hpp"
11
12namespace hi::inline v1 {
13class text_field_widget;
14
16public:
18
19 virtual ~text_field_delegate() = default;
20 virtual void init(text_field_widget const &sender) noexcept {}
21 virtual void deinit(text_field_widget const &sender) noexcept {}
22
23 auto subscribe(text_field_widget& sender, callback_flags flags, std::invocable<> auto&& callback) noexcept
24 {
25 return _notifier.subscribe(flags, hi_forward(callback));
26 }
27
28 auto subscribe(text_field_widget& sender, std::invocable<> auto&& callback) noexcept
29 {
30 return subscribe(sender, callback_flags::synchronous, hi_forward(callback));
31 }
32
37 virtual label validate(text_field_widget &sender, std::string_view text) noexcept
38 {
39 return {};
40 }
41
48 virtual std::string text(text_field_widget &sender) noexcept
49 {
50 return {};
51 }
52
62 virtual void set_text(text_field_widget &sender, std::string_view text) noexcept {}
63
64protected:
65 notifier<> _notifier;
66};
67
68} // namespace hi::inline v1
#define hi_forward(x)
Forward a value, based on the decltype of the value.
Definition required.hpp:29
A label consisting of localizable text and an icon.
Definition label.hpp:27
A notifier which can be used to call a set of registered callbacks.
Definition notifier.hpp:24
Definition text_field_delegate.hpp:15
virtual std::string text(text_field_widget &sender) noexcept
Get the text to show in the text field.
Definition text_field_delegate.hpp:48
virtual void set_text(text_field_widget &sender, std::string_view text) noexcept
Set the text as entered by the user.
Definition text_field_delegate.hpp:62
virtual label validate(text_field_widget &sender, std::string_view text) noexcept
Validate the text field.
Definition text_field_delegate.hpp:37
A single line text field.
Definition text_field_widget.hpp:55