HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
text_field_widget.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 "text_field_delegate.hpp"
8#include "default_text_field_delegate.hpp"
9#include "widget.hpp"
10#include "../text/editable_text.hpp"
11#include "../format.hpp"
12#include "../label.hpp"
13#include "../weak_or_unique_ptr.hpp"
14#include <memory>
15#include <string>
16#include <array>
17#include <optional>
18#include <future>
19
20namespace tt {
21
55class text_field_widget final : public widget {
56public:
58 using super = widget;
59
64
66
67 template<typename Value>
68 text_field_widget(gui_window &window, widget *parent, Value &&value) noexcept
69 requires(not std::is_convertible_v<Value, weak_or_unique_ptr<delegate_type>>) :
70 text_field_widget(window, parent, make_unique_default_text_field_delegate(std::forward<Value>(value)))
71 {
72 }
73
75 void init() noexcept override;
76 void deinit() noexcept override;
77 [[nodiscard]] bool constrain(hires_utc_clock::time_point display_time_point, bool need_reconstrain) noexcept override;
78 void layout(hires_utc_clock::time_point display_time_point, bool need_layout) noexcept override;
79 void draw(draw_context context, hires_utc_clock::time_point display_time_point) noexcept override;
80 bool handle_event(command command) noexcept override;
81 bool handle_event(mouse_event const &event) noexcept override;
82 bool handle_event(keyboard_event const &event) noexcept override;
83 hitbox hitbox_test(point2 position) const noexcept override;
84 [[nodiscard]] bool accepts_keyboard_focus(keyboard_focus_group group) const noexcept override;
85 [[nodiscard]] color focus_color() const noexcept override;
87private:
88 weak_or_unique_ptr<delegate_type> _delegate;
89 typename delegate_type::callback_ptr_type _delegate_callback;
90
91 bool _continues = false;
92
95 std::optional<label>(_error);
96
97 float _text_width = 0.0f;
98 aarectangle _text_rectangle = {};
99
100 aarectangle _text_field_rectangle;
101 aarectangle _text_field_clipping_rectangle;
102
103 editable_text _field;
104 shaped_text _shaped_text;
105 aarectangle _left_to_right_caret = {};
106
110 float _drag_scroll_speed_x = 0.0f;
111
114 int _drag_click_count = 0;
115
116 point2 _drag_select_position = {};
117
120 float _text_scroll_x = 0.0f;
121
122 translate2 _text_translate;
123 translate2 _text_inv_translate;
124
125 static constexpr hires_utc_clock::duration _blink_interval = 500ms;
126 hires_utc_clock::time_point _next_redraw_time_point;
127 hires_utc_clock::time_point _last_update_time_point;
128
129 text_field_widget(gui_window &window, widget *parent, weak_or_unique_ptr<delegate_type> delegate) noexcept;
130 void revert(bool force) noexcept;
131 void commit(bool force) noexcept;
132 void drag_select() noexcept;
133 void scroll_text() noexcept;
134 void draw_background_box(draw_context context) const noexcept;
135 void draw_selection_rectangles(draw_context context) const noexcept;
136 void draw_partial_grapheme_caret(draw_context context) const noexcept;
137 void draw_caret(draw_context context, hires_utc_clock::time_point display_time_point) noexcept;
138 void draw_text(draw_context context) const noexcept;
139};
140
141} // namespace tt
STL namespace.
This is a RGBA floating point color.
Definition color.hpp:36
Class which represents an axis-aligned rectangle.
Definition axis_aligned_rectangle.hpp:20
Draw context for drawing using the TTauri shaders.
Definition draw_context.hpp:29
Definition gui_window.hpp:36
Definition hitbox.hpp:14
Definition keyboard_event.hpp:40
Definition mouse_event.hpp:15
Timestamp.
Definition hires_utc_clock.hpp:19
A label consisting of localizable text and an icon.
Definition label.hpp:27
An observable value.
Definition observable.hpp:280
Class that hold either a weak_ptr or a unique_ptr This class is to hold a weak_ptr,...
Definition weak_or_unique_ptr.hpp:25
Definition text_field_delegate.hpp:15
A single line text field.
Definition text_field_widget.hpp:55
observable< bool > continues
Continues update mode.
Definition text_field_widget.hpp:63
An interactive graphical object as part of the user-interface.
Definition widget.hpp:39
widget *const parent
Pointer to the parent widget.
Definition widget.hpp:48
gui_window & window
Convenient reference to the Window.
Definition widget.hpp:43
widget(gui_window &window, widget *parent) noexcept