HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
text_field_widget.hpp
Go to the documentation of this file.
1// Copyright Take Vos 2021-2022.
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
9#pragma once
10
12#include "widget.hpp"
13#include "label_widget.hpp"
14#include "scroll_widget.hpp"
15#include "../label.hpp"
16#include <memory>
17#include <string>
18#include <array>
19#include <optional>
20#include <future>
21
22namespace hi { inline namespace v1 {
23
24template<typename Context>
26
62class text_field_widget final : public widget {
63public:
64 using delegate_type = text_field_delegate;
65 using super = widget;
66
68
72 observer<bool> continues = false;
73
76 observer<semantic_text_style> text_style = semantic_text_style::label;
77
80 observer<alignment> alignment = alignment::middle_flush();
81
82 virtual ~text_field_widget();
83
85
89 text_field_widget_attribute auto&&...attributes) noexcept :
91 {
92 set_attributes(hi_forward(attributes)...);
93 }
94
102 widget *parent,
103 different_from<std::shared_ptr<delegate_type>> auto&& value,
104 text_field_widget_attribute auto&&...attributes) noexcept requires requires
105 {
108
110 [[nodiscard]] generator<widget *> children() const noexcept override;
111 widget_constraints const& set_constraints(set_constraints_context const &context) noexcept override;
112 void set_layout(widget_layout const& context) noexcept override;
113 void draw(draw_context const& context) noexcept override;
114 bool handle_event(gui_event const& event) noexcept override;
115 hitbox hitbox_test(point3 position) const noexcept override;
116 [[nodiscard]] bool accepts_keyboard_focus(keyboard_focus_group group) const noexcept override;
117 [[nodiscard]] color focus_color() const noexcept override;
119private:
120 notifier<>::callback_token _delegate_cbt;
121
124 std::unique_ptr<scroll_widget<axis::none>> _scroll_widget;
125
128 text_widget *_text_widget = nullptr;
129
132 observer<gstring> _text;
133
136 aarectangle _box_rectangle;
137
140 aarectangle _text_rectangle;
141 widget_constraints _text_constraints;
142
145 observer<label> _error_label;
146 aarectangle _error_label_rectangle;
147 widget_constraints _error_label_constraints;
148 std::unique_ptr<label_widget> _error_label_widget;
149
150 typename decltype(continues)::callback_token _continues_cbt;
151 typename decltype(text_style)::callback_token _text_style_cbt;
152 typename decltype(_text)::callback_token _text_cbt;
153 typename decltype(_error_label)::callback_token _error_label_cbt;
154
155 void set_attributes() noexcept {}
156 void set_attributes(text_field_widget_attribute auto&& first, text_field_widget_attribute auto&&...rest) noexcept
157 {
158 if constexpr (forward_of<decltype(first), observer<hi::alignment>>) {
159 alignment = hi_forward(first);
160 } else if constexpr (forward_of<decltype(first), observer<hi::semantic_text_style>>) {
161 text_style = hi_forward(first);
162 } else {
164 }
165
166 set_attributes(hi_forward(rest)...);
167 }
168
169 void revert(bool force) noexcept;
170 void commit(bool force) noexcept;
171 void draw_background_box(draw_context const& context) const noexcept;
172};
173
174}} // namespace hi::v1
#define hi_static_no_default()
This part of the code should not be reachable, unless a programming bug.
Definition assert.hpp:172
#define hi_forward(x)
Forward a value, based on the decltype of the value.
Definition utility.hpp:29
Functionality for labels, text and icons.
Defines scroll_widget.
Defines delegate_field_delegate and some default text field delegates.
Defines widget.
Defines label_widget.
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
STL namespace.
DOXYGEN BUG.
Definition algorithm.hpp:15
The HikoGUI namespace.
Definition ascii.hpp:19
A user interface event.
Definition gui_event.hpp:76
The GUI widget displays and lays out text together with an icon.
Definition label_widget.hpp:41
The scroll widget allows a content widget to be shown in less space than is required.
Definition scroll_widget.hpp:45
Definition set_constraints_context.hpp:15
A delegate that controls the state of a text_field_widget.
Definition text_field_delegate.hpp:25
A single line text field.
Definition text_field_widget.hpp:62
observer< alignment > alignment
The alignment of the text.
Definition text_field_widget.hpp:80
observer< bool > continues
Continues update mode.
Definition text_field_widget.hpp:72
text_field_widget(widget *parent, different_from< std::shared_ptr< delegate_type > > auto &&value, text_field_widget_attribute auto &&...attributes) noexcept
Construct a text field widget.
Definition text_field_widget.hpp:101
observer< semantic_text_style > text_style
The style of the text.
Definition text_field_widget.hpp:76
A text widget.
Definition text_widget.hpp:61
An interactive graphical object as part of the user-interface.
Definition widget.hpp:45
widget(widget *parent) noexcept
widget * parent
Pointer to the parent widget.
Definition widget.hpp:50
The constraints of a widget.
Definition widget_constraints.hpp:26
The layout of a widget.
Definition widget_layout.hpp:40
Definition text_field_widget.hpp:25
Definition text_widget.hpp:33
T move(T... args)