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 tt {
13class text_field_widget;
14
16public:
18
19 virtual void init(text_field_widget const &sender) noexcept {}
20 virtual void deinit(text_field_widget const &sender) noexcept {}
21
22 virtual callback_ptr_type subscribe(text_field_widget &sender, callback_ptr_type const &callback_ptr) noexcept
23 {
24 return callback_ptr;
25 }
26
29 template<typename Callback>
30 requires(std::is_invocable_v<Callback>) [[nodiscard]] callback_ptr_type
31 subscribe(text_field_widget &sender, Callback &&callback) noexcept
32 {
33 return subscribe(sender, std::make_shared<std::function<void()>>(std::forward<Callback>(callback)));
34 }
35
36 virtual void unsubscribe(text_field_widget &sender, callback_ptr_type const &callback_ptr) noexcept
37 {
38 }
39
44 virtual std::optional<label> validate(text_field_widget &sender, std::string_view text) noexcept
45 {
46 return {};
47 }
48
55 virtual std::string text(text_field_widget &sender) noexcept
56 {
57 return {};
58 }
59
69 virtual void set_text(text_field_widget &sender, std::string_view text) noexcept
70 {
71 }
72};
73
74} // namespace tt
Definition text_field_delegate.hpp:15
callback_ptr_type subscribe(text_field_widget &sender, Callback &&callback) noexcept
Subscribe a callback for notifying the widget of a data change.
Definition text_field_delegate.hpp:31
virtual std::optional< label > validate(text_field_widget &sender, std::string_view text) noexcept
Validate the text field.
Definition text_field_delegate.hpp:44
virtual std::string text(text_field_widget &sender) noexcept
Get the text to show in the text field.
Definition text_field_delegate.hpp:55
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:69
A single line text field.
Definition text_field_widget.hpp:55
T make_shared(T... args)