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 const &> children(bool include_invisible) const noexcept override;
111 [[nodiscard]] box_constraints update_constraints() 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(point2i 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 box_constraints _scroll_constraints;
126 box_shape _scroll_shape;
127
130 text_widget *_text_widget = nullptr;
131
134 observer<gstring> _text;
135
138 observer<label> _error_label;
139 std::unique_ptr<label_widget> _error_label_widget;
140 box_constraints _error_label_constraints;
141 box_shape _error_label_shape;
142
143 typename decltype(continues)::callback_token _continues_cbt;
144 typename decltype(text_style)::callback_token _text_style_cbt;
145 typename decltype(_text)::callback_token _text_cbt;
146 typename decltype(_error_label)::callback_token _error_label_cbt;
147
148 void set_attributes() noexcept {}
149 void set_attributes(text_field_widget_attribute auto&& first, text_field_widget_attribute auto&&...rest) noexcept
150 {
151 if constexpr (forward_of<decltype(first), observer<hi::alignment>>) {
152 alignment = hi_forward(first);
153 } else if constexpr (forward_of<decltype(first), observer<hi::semantic_text_style>>) {
154 text_style = hi_forward(first);
155 } else {
157 }
158
159 set_attributes(hi_forward(rest)...);
160 }
161
162 void revert(bool force) noexcept;
163 void commit(bool force) noexcept;
164 void draw_background_box(draw_context const& context) const noexcept;
165};
166
167}} // namespace hi::v1
Functionality for labels, text and icons.
Defines scroll_widget.
Defines delegate_field_delegate and some default text field delegates.
Defines widget.
Defines label_widget.
#define hi_static_no_default(...)
This part of the code should not be reachable, unless a programming bug.
Definition assert.hpp:308
#define hi_forward(x)
Forward a value, based on the decltype of the value.
Definition utility.hpp:29
axis
An enumeration of the 3 axis for 3D geometry.
Definition axis.hpp:18
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:13
geometry/margins.hpp
Definition cache.hpp:11
This is a RGBA floating point color.
Definition color.hpp:42
Draw context for drawing using the HikoGUI shaders.
Definition draw_context.hpp:211
A user interface event.
Definition gui_event.hpp:74
2D constraints.
Definition box_constraints.hpp:22
Definition box_shape.hpp:15
The GUI widget displays and lays out text together with an icon.
Definition label_widget.hpp:42
The scroll widget allows a content widget to be shown in less space than is required.
Definition scroll_widget.hpp:46
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:46
widget(widget *parent) noexcept
widget * parent
Pointer to the parent widget.
Definition widget.hpp:51
The layout of a widget.
Definition widget_layout.hpp:38
Definition text_field_widget.hpp:25
Definition text_widget.hpp:33
T move(T... args)