lecui 1.0.0-alpha.20
lecui C++ user interface library
text_field.h
1//
2// text_field.h - text_field widget interface
3//
4// lecui user interface library, part of the liblec library
5// Copyright (c) 2019 Alec Musasa (alecmus at live dot com)
6//
7// Released under the MIT license. For full details see the
8// file LICENSE.txt
9//
10
11#pragma once
12
13#if defined(LECUI_EXPORTS)
14#include "widget.h"
15#else
16#include <liblec/lecui/widgets/widget.h>
17#endif
18
19#include <set>
20
21namespace liblec {
22 namespace lecui {
23 namespace widgets {
26 class lecui_api text_field : public widget {
27 float _border = .5f;
28 color _color_border;
29 float _corner_radius_x = 3.f;
30 float _corner_radius_y = 3.f;
31 std::string _prompt = "Enter text here";
32 color _color_prompt;
33 color _color_caret;
34 color _color_input_error;
35 std::set<char> _allowed_characters;
36 std::set<char> _forbidden_characters;
37 int _maximum_length = 0;
38
39 public:
42 _cursor = cursor_type::caret;
43 _rect.size({ 200.f, 25.f });
44 }
45
50 std::function<void(const std::string&)> change = nullptr;
51 };
52
56 return _text_field_events;
57 }
58
63 bool operator==(const text_field& param);
64
69 bool operator!=(const text_field& param);
70
71 // generic widget
72
75 std::string& text() override;
76
80 text_field& text(const std::string& text);
81
84 std::string& tooltip() override;
85
89 text_field& tooltip(const std::string& tooltip);
90
94 lecui::rect& rect() override;
95
100
104
109
112 cursor_type& cursor() override;
113
118
121 std::string& font() override;
122
126 text_field& font(const std::string& font);
127
130 float& font_size() override;
131
135 text_field& font_size(const float& font_size);
136
139 color& color_text() override;
140
144 text_field& color_text(const color& color_text);
145
148 color& color_fill() override;
149
153 text_field& color_fill(const color& color_fill);
154
157 color& color_hot() override;
158
162 text_field& color_hot(const color& color_hot);
163
167
171 text_field& color_selected(const color& color_selected);
172
176
180 text_field& color_disabled(const color& color_disabled);
181
182 // widget specific widget
183
186 float& border();
187
191 text_field& border(const float& border);
192
196
200 text_field& color_border(const color& color_border);
201
205
209 text_field& corner_radius_x(const float& corner_radius_x);
210
214
218 text_field& corner_radius_y(const float& corner_radius_y);
219
222 std::string& prompt();
223
227 text_field& prompt(const std::string& prompt);
228
232
236 text_field& color_prompt(const color& color_prompt);
237
241
245 text_field& color_caret(const color& color_caret);
246
250
254 text_field& color_input_error(const color& color_input_error);
255
259 std::set<char>& allowed_characters();
260
264 text_field& allowed_characters(const std::set<char>& allowed_characters);
265
269 std::set<char>& forbidden_characters();
270
275 text_field& forbidden_characters(const std::set<char>& forbidden_characters);
276
280
284 text_field& maximum_length(const int& maximum_length);
285
286 public:
293 [[nodiscard]]
294 static text_field& add(containers::page& page, const std::string& alias = std::string());
295
302 [[nodiscard]]
303 static text_field& get(form& fm, const std::string& path);
304
305 private:
307 char mask = '\0';
308
310 text_field_events _text_field_events;
311
312#if defined(LECUI_EXPORTS)
313 friend class password_field_builder;
314 friend class text_field_impl;
315#endif
316 };
317 }
318 }
319}
320
321#if defined(lecui_helper)
323#define get_text_field(path) liblec::lecui::widgets::text_field::get(*this, path)
324#endif
RGBA color on a standard 0 to 255 scale. For the alpha channel 0 is transparent and 255 is opaque.
Definition: lecui.h:583
Page container.
Definition: page.h:32
Form base class. The user must inherit from this class and call one of the two constructors from its ...
Definition: form.h:122
Rectangle class.
Definition: lecui.h:158
Resize parameters.
Definition: lecui.h:363
Text field widget. To instantiate and add to a container use the add static method.
Definition: text_field.h:26
std::string & tooltip() override
Get or set the widget's tooltip text.
bool operator==(const text_field &param)
Check whether widget specs are equal. Only those properties that require the widget resources to be r...
lecui::rect & rect() override
Get or set the position and dimensions of the widget.
float & font_size() override
Get or set the default widget font size in points, e.g. 9.0f.
text_field & corner_radius_y(const float &corner_radius_y)
Set the vertical radius of the corners.
color & color_disabled() override
Get or set the widget's color when it is disabled.
text_field()
Constructor.
Definition: text_field.h:41
text_field & color_text(const color &color_text)
Set the color of the widget's text.
std::string & text() override
Get or set the widget text.
text_field & color_disabled(const color &color_disabled)
Set the widget's color when it is disabled.
color & color_input_error()
Get or set the color to show that there has been an input error.
text_field & on_resize(const resize_params &on_resize)
Set the behaviour of the widget when its container is resized.
cursor_type & cursor() override
Get or set the mouse cursor to use then over the widget.
text_field & color_input_error(const color &color_input_error)
Set the color to show that there has been an input error.
text_field & forbidden_characters(const std::set< char > &forbidden_characters)
Set the set of characters to prevent from being typed in.
text_field & allowed_characters(const std::set< char > &allowed_characters)
Set the character set to limit input to.
color & color_fill() override
Get or set the fill color of the widget.
text_field & color_selected(const color &color_selected)
Set the widget's color when selected.
float & corner_radius_x()
Get or set the horizontal radius of the corners.
static text_field & add(containers::page &page, const std::string &alias=std::string())
Add a text field to a container.
color & color_hot() override
Get or set the widget's color when the mouse is hovered over it.
float & border()
Get or set the thickness of the border.
text_field & color_hot(const color &color_hot)
Set the widget's color when the mouse is hovered over it.
bool operator!=(const text_field &param)
Check whether widget specs are NOT equal. Only those properties that require the widget resources to ...
color & color_caret()
Get or set the color of the caret.
text_field & text(const std::string &text)
Set the widget's text.
int & maximum_length()
Get or set the maximum length of the input string. 0 means unlimited length.
color & color_text() override
Get or set the color of the widget's text.
text_field & color_prompt(const color &color_prompt)
Set the color of the prompt text.
text_field & color_border(const color &color_border)
Set the color of the border.
std::set< char > & forbidden_characters()
Get or set the set of characters to prevent from being typed in.
resize_params & on_resize() override
Get or set the behaviour of the widget when its container is resized.
static text_field & get(form &fm, const std::string &path)
Get the specifications of a text field.
color & color_prompt()
Get or set the color of the prompt text.
text_field & tooltip(const std::string &tooltip)
Set the tooltip text.
color & color_border()
Get or set the color of the border.
text_field & border(const float &border)
Set the thickness of the border.
float & corner_radius_y()
Get or set the vertical radius of the corners.
std::string & font() override
Get or set the default widget font, e.g. "Georgia".
text_field & color_fill(const color &color_fill)
Set the fill color of the widget.
std::set< char > & allowed_characters()
Get or set the character set to limit input to.
text_field & font_size(const float &font_size)
Set the widget's font size.
text_field & rect(const lecui::rect &rect)
Set the position and dimensions of the widget.
std::string & prompt()
Get or set the text to be displayed when the widget is empty.
text_field & prompt(const std::string &prompt)
Set the text to be displayed when the widget is empty.
text_field & corner_radius_x(const float &corner_radius_x)
Set the horizontal radius of the corners.
text_field_events & events()
Text field events.
Definition: text_field.h:55
text_field & maximum_length(const int &maximum_length)
Set the maximum length of the input string.
text_field & font(const std::string &font)
Set the default widget font.
text_field & color_caret(const color &color_caret)
Set the color of the caret.
color & color_selected() override
Get or set the widget's color when selected.
text_field & cursor(const cursor_type cursor)
Set the mouse cursor to use when over the widget.
Base class for all widgets.
Definition: widget.h:24
cursor_type
Mouse cursor type.
Definition: widget.h:27
Top level namespace for the liblec libraries.
Definition: appearance.h:19
Events specific to this widget.
Definition: text_field.h:47
Events common to all widgets.
Definition: widget.h:72