lecui 1.0.0-alpha.20
lecui C++ user interface library
widget.h
1//
2// widget.h - 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 "../form.h"
15#include "../containers/page.h"
16#else
17#include <liblec/lecui/form.h>
18#endif
19
20namespace liblec {
21 namespace lecui {
22 namespace widgets {
24 class lecui_api widget {
25 public:
27 enum class cursor_type {
29 arrow,
30
32 hand,
33
35 caret,
36 };
37
38 protected:
39 std::string _text;
40 std::string _tooltip;
42 resize_params _on_resize = { 0.f, 0.f, 0.f, 0.f };
43 cursor_type _cursor = cursor_type::arrow;
44 std::string _font = "Segoe UI";
45 float _font_size = 9.f;
46 color _color_text = { 0, 0, 0, 255 };
47 color _color_fill = { 0, 120, 170, 255 };
48 color _color_hot = { 0, 120, 170, 255 };
49 color _color_selected = { 0, 120, 170, 30 };
50 color _color_disabled = { 180, 180, 180, 255 };
51
52 public:
54 widget() {};
55
57 virtual ~widget() {};
58
63 bool operator==(const widget& param);
64
69 bool operator!=(const widget& param);
70
72 struct basic_events {
75 std::function<void()> action = nullptr;
76
78 std::function<void()> click = nullptr;
79
81 std::function<void()> right_click = nullptr;
82
84 std::function<void()> mouse_enter = nullptr;
85
87 std::function<void()> mouse_leave = nullptr;
88 };
89
94 virtual std::string& text() = 0;
95
99 virtual std::string& tooltip() = 0;
100
103 virtual lecui::rect& rect() = 0;
104
107 virtual resize_params& on_resize() = 0;
108
112 virtual cursor_type& cursor() = 0;
113
116 virtual std::string& font() = 0;
117
120 virtual float& font_size() = 0;
121
124 virtual color& color_text() = 0;
125
130 virtual color& color_fill() = 0;
131
136 virtual color& color_hot() = 0;
137
140 virtual color& color_selected() = 0;
141
144 virtual color& color_disabled() = 0;
145
149 basic_events& events() { return _events; }
150
153 const std::string& alias() { return _alias; }
154
155 private:
156 basic_events _events;
157 std::string _alias;
158
159 void alias(const std::string alias) {
160 _alias = alias;
161 }
162
163#if defined(LECUI_EXPORTS)
164 friend class containers::page;
165
166 // implementation classes for widgets that use special panes ... they need access to private variables for redirection
167 friend class table_view_impl;
168 friend class tree_view_impl;
169 friend class html_editor_impl;
170 friend class time_impl;
171 friend class date_impl;
172 friend class icon_impl;
173#endif
174 };
175
177 class lecui_api badge_specs {
178 public:
180 enum class badge_position {
182 top_left,
183
185 top_right,
186
189
192 };
193
194 protected:
195 std::string _text;
196 std::string _font = "Segoe UI";
197 float _font_size = 8.f;
198 float _border = .5f;
199 color _color = { 255, 0, 0, 180 };
200 color _color_border = { 255, 255, 255, 180 };
201 color _color_text = { 255, 255, 255, 255 };
202 badge_position _position = badge_position::bottom_right;
203
204 public:
209 bool operator==(const badge_specs& param);
210
215 bool operator!=(const badge_specs& param);
216
219 std::string& text();
220
224 badge_specs& text(const std::string& text);
225
228 std::string& font();
229
233 badge_specs& font(const std::string& font);
234
237 float& font_size();
238
242 badge_specs& font_size(const float& font_size);
243
246 float& border();
247
251 badge_specs& border(const float& border);
252
256
261
265
269 badge_specs& color_border(const lecui::color& color_border);
270
274
279
283
288 };
289
292 class lecui_api badge_widget {
293 protected:
295
296 public:
301 bool operator==(const badge_widget& param);
302
307 bool operator!=(const badge_widget& param);
308
313 virtual badge_specs& badge() = 0;
314 };
315 }
316
318 class lecui_api widget_manager {
319 public:
323
326
333 bool enable(const std::string& path, std::string& error);
334
341 bool disable(const std::string& path, std::string& error);
342
349 bool show(const std::string& path, std::string& error);
350
357 bool hide(const std::string& path, std::string& error);
358
372 void close(const std::string& path);
373
379 void select(const std::string& path);
380
392 bool refresh(const std::string& path, std::string& error);
393
394 private:
395 class impl;
396 impl& _d;
397
398 // Default constructor and copying an object of this class are not allowed
399 widget_manager() = delete;
400 widget_manager(const widget_manager&) = delete;
401 widget_manager& operator=(const widget_manager&) = delete;
402 };
403 }
404}
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
Widget manager class.
Definition: widget.h:318
widget_manager(form &fm)
Widget manager constructor.
bool show(const std::string &path, std::string &error)
Show a widget.
bool enable(const std::string &path, std::string &error)
Enable a widget.
void close(const std::string &path)
Close a widget.
bool hide(const std::string &path, std::string &error)
Hide a widget.
bool refresh(const std::string &path, std::string &error)
Refresh a widget.
bool disable(const std::string &path, std::string &error)
Disable a widget.
void select(const std::string &path)
Select a widget.
~widget_manager()
Widget manager destructor.
Badge specifications.
Definition: widget.h:177
badge_specs & color(const lecui::color &color)
Set the color of the badge.
badge_position
Badge position within the widget.
Definition: widget.h:180
badge_specs & color_border(const lecui::color &color_border)
Set the color of the badge's border.
bool operator==(const badge_specs &param)
Check whether badge specs are equal. Only those properties that require the widget's basic resources ...
badge_specs & text(const std::string &text)
Set the badge text.
badge_specs & font(const std::string &font)
Set the badge font.
lecui::color & color()
Get or set the color of the badge.
bool operator!=(const badge_specs &param)
Check whether badge specs are NOT equal. Only those properties that require the widget's basic resour...
badge_specs & border(const float &border)
Set the thickness of the border.
std::string & text()
Get or set the badge text.
badge_specs & color_text(const lecui::color &color_text)
Set the color of the badge's text.
lecui::color & color_border()
Get or set the color of the badge's border.
float & font_size()
Get or set the badge's font size in points, e.g. 9.0f.
float & border()
Get or set the thickness of the border.
badge_position & position()
Get or set the badge's position.
badge_specs & position(const badge_position &position)
Set the badge's position.
badge_specs & font_size(const float &font_size)
Set the badge's font size.
std::string _text
The badge's text.
Definition: widget.h:195
lecui::color & color_text()
Get or set the color of the badge's text.
std::string & font()
Get or set the default badge font, e.g. "Georgia".
Base class for all widgets with badges.
Definition: widget.h:292
badge_specs _badge
The badge's specs.
Definition: widget.h:294
bool operator==(const badge_widget &param)
Check whether two badges are equal. Only those badge properties that require the badge's resources to...
bool operator!=(const badge_widget &param)
Check whether two badges are NOT equal. Only those badge properties that require the badge's resource...
virtual badge_specs & badge()=0
Get or set the widget's badge.
Base class for all widgets.
Definition: widget.h:24
std::string _tooltip
The widget's tooltip text.
Definition: widget.h:40
const std::string & alias()
The widget's alias, either user defined or automatically generated by the library.
Definition: widget.h:153
std::string _text
The widget's text.
Definition: widget.h:39
lecui::rect _rect
The widget's rectangle.
Definition: widget.h:41
virtual color & color_fill()=0
Get or set the fill color of the widget.
bool operator==(const widget &param)
Check whether widget's basic specifications are equal. Only those properties that require the widget'...
virtual color & color_hot()=0
Get or set the widget's color when the mouse is hovered over it.
cursor_type
Mouse cursor type.
Definition: widget.h:27
virtual std::string & tooltip()=0
Get or set the widget's tooltip text.
virtual resize_params & on_resize()=0
Get or set the behaviour of the widget when its container is resized.
virtual lecui::rect & rect()=0
Get or set the position and dimensions of the widget.
basic_events & events()
Widget events.
Definition: widget.h:149
virtual float & font_size()=0
Get or set the default widget font size in points, e.g. 9.0f.
widget()
Widget constructor.
Definition: widget.h:54
virtual ~widget()
Widget descructor.
Definition: widget.h:57
bool operator!=(const widget &param)
Check whether widget's basic specifications are NOT equal. Only those properties that require the wid...
virtual std::string & text()=0
Get or set the widget text.
virtual color & color_text()=0
Get or set the color of the widget's text.
virtual cursor_type & cursor()=0
Get or set the mouse cursor to use then over the widget.
virtual color & color_disabled()=0
Get or set the widget's color when it's disabled.
virtual color & color_selected()=0
Get or set the widget's color when selected.
virtual std::string & font()=0
Get or set the default widget font, e.g. "Georgia".
@ bottom_left
Pin the form to the bottom left corner of the working area.
@ top_left
Pin the form to the top left corner of the working area.
@ bottom_right
Pin the form to the bottom right corner of the working area.
@ top_right
Pin the form to the top right corner of the working area.
Top level namespace for the liblec libraries.
Definition: appearance.h:19
Events common to all widgets.
Definition: widget.h:72