lecui 1.0.0-alpha.20
lecui C++ user interface library
form.h
1//
2// form.h - form 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 "lecui.h"
15#else
16#include <liblec/lecui.h>
17#endif
18
19#include <functional>
20
21namespace liblec {
22 namespace lecui {
23#if defined(LECUI_EXPORTS)
24 class page_manager;
25 class widget_manager;
26 class timer_manager;
27 class dimensions;
28 class appearance;
29 class controls;
30 class filesystem;
31 class color_picker;
32 class splash;
33 class instance_manager;
34 class form_menu;
35 class tray_icon;
36
37 namespace containers {
38 class page;
39 class status_pane_builder;
40 class tab_pane_builder;
41 class tab_builder;
42 class pane_builder;
43 class group_builder;
44 }
45
46 namespace widgets {
47 class label_builder;
48 class image_view_builder;
49 class button_builder;
50 class custom_builder;
51 class table_view_builder;
52 class rectangle_builder;
53 class toggle_builder;
54 class progress_indicator_builder;
55 class progress_bar_builder;
56 class checkbox_builder;
57 class text_field_builder;
58 class password_field_builder;
59 class tree_view_builder;
60 class slider_builder;
61 class html_editor_builder;
62 class combobox_builder;
63 class line_builder;
64 class time_builder;
65 class date_builder;
66 class icon_builder;
67 class strength_bar_builder;
68
69 class widget_impl;
70 class combobox_impl;
71 class html_editor_impl;
72 class text_field_impl;
73 class tree_view_impl;
74 class image_view_impl;
75 class table_view_impl;
76 class time_impl;
77 class date_impl;
78 class icon_impl;
79 class pane_impl;
80 class tab_pane_impl;
81 }
82#endif
83
86 enum class form_position {
89
92
95
98
101
104
106 top_right,
107
110
113
116 };
117
122 class lecui_api form {
123 public:
125 struct form_events {
130 std::function<void(const lecui::size&)> size = nullptr;
131
136 std::function<void(const std::string&)> drop_files = nullptr;
137
140 std::function<void(const std::string&)> receive_data = nullptr;
141
145 std::function<void()> caption;
146
152 std::function<bool(std::string&)> initialize;
153
166 std::function<bool(std::string&)> layout;
167
171 std::function<void()> start;
172
177 std::function<void()> close;
178
182 std::function<void()> shutdown;
183 };
184
192 form(const std::string& caption);
193
207 form(const std::string& caption, form& parent);
208 ~form();
209
212 [[nodiscard]]
213 static std::string menu_form_caption();
214
217 [[nodiscard]]
218 static std::string tooltip_form_caption();
219
223 void move(const point& point);
224
228
240
247 [[nodiscard]] bool create(std::string& error);
248
254 void close();
255
261 [[nodiscard]] bool prompt(const std::string& question);
262
267 void message(const std::string& message);
268
274 void update();
275
292 void reload();
293
298 [[nodiscard]]
299 static bool keep_alive();
300
303 [[nodiscard]]
305
309
314 void restore();
315
318 void maximize();
319
324 void hide();
325
328 bool visible();
329
332 void show();
333
336 bool minimized();
337
342
347
351
352 private:
353 class impl;
354 impl& _d;
355
356 // Default constructor and copying an object of this class are not allowed
357 form() = delete;
358 form(const form&) = delete;
359 form& operator=(const form&) = delete;
360
361#if defined(LECUI_EXPORTS)
362 friend class page_manager;
363 friend class widget_manager;
364 friend class timer_manager;
365 friend class dimensions;
366 friend class appearance;
367 friend class controls;
368 friend class filesystem;
369 friend class color_picker;
370 friend class splash;
371 friend class instance_manager;
372 friend class form_menu;
373 friend class tray_icon;
374
375 friend class containers::page;
376 friend class containers::status_pane_builder;
377 friend class containers::tab_pane_builder;
378 friend class containers::tab_builder;
379 friend class containers::pane_builder;
380 friend class containers::group_builder;
381 friend class widgets::label_builder;
382 friend class widgets::image_view_builder;
383 friend class widgets::button_builder;
384 friend class widgets::custom_builder;
385 friend class widgets::table_view_builder;
386 friend class widgets::rectangle_builder;
387 friend class widgets::toggle_builder;
388 friend class widgets::progress_indicator_builder;
389 friend class widgets::progress_bar_builder;
390 friend class widgets::checkbox_builder;
391 friend class widgets::text_field_builder;
392 friend class widgets::tree_view_builder;
393 friend class widgets::slider_builder;
394 friend class widgets::html_editor_builder;
395 friend class widgets::combobox_builder;
396 friend class widgets::line_builder;
397 friend class widgets::time_builder;
398 friend class widgets::date_builder;
399 friend class widgets::icon_builder;
400 friend class widgets::strength_bar_builder;
401
402 friend class widgets::widget_impl;
403 friend class widgets::combobox_impl;
404 friend class widgets::image_view_impl;
405 friend class widgets::tree_view_impl;
406 friend class widgets::time_impl;
407 friend class widgets::date_impl;
408 friend class widgets::html_editor_impl;
409 friend class widgets::icon_impl;
410#endif
411 };
412 }
413}
Manipulate the form's appearance.
Definition: appearance.h:174
Color picker.
Definition: color_picker.h:22
Page container.
Definition: page.h:32
Manipulate a form's controls.
Definition: controls.h:23
Manipulate a form's dimensions.
Definition: controls.h:74
Interact with the OS file system.
Definition: filesystem.h:22
Form menu.
Definition: form_menu.h:49
Form base class. The user must inherit from this class and call one of the two constructors from its ...
Definition: form.h:122
float get_dpi_scale()
Get the current DPI scale.
void update()
Update the form. A low resource refresh of the current page. Typically necessary only after adding a ...
void maximize()
Maximize the form.
form_events & events()
Get or set form events.
bool prompt(const std::string &question)
Prompt the user for confirmation of an action. Displays a small modal message box with yes-no buttons...
void allow_minimize()
Minimize the form.
bool minimized()
Check whether the form is minimized.
bool create(std::string &error)
Create the form.
form(const std::string &caption)
Make a form with no parent.
static bool keep_alive()
Keep UI responsive during lengthy calls.
void force_instance()
Force this instance to run even if an existing instance is found.
void prevent_quit()
Prevent the form from being closed.
void show()
Show the form.
void move(const form_position &form_position)
Move the form.
void hide()
Hide the form. Useful when using a system tray icon.
void close()
Close the form. When this is called all activity is stopped and the form is closed.
form(const std::string &caption, form &parent)
Make a modal form.
bool visible()
Check whether the form is visible.
void move(const point &point)
Move the form.
static std::string menu_form_caption()
A special caption used to make a menu form.
void restore()
Restore the form.
void reload()
Reload the form and all its widgets. A high resource reload of the entire form's graphic resources....
static std::string tooltip_form_caption()
A special caption used to make a tooltip form.
void message(const std::string &message)
Display a message to the user in the form of a small modal message box with an ok button.
void allow_quit()
Allow the form to be closed.
Manage application instances.
Definition: instance.h:22
Page manager class.
Definition: page.h:132
A point.
Definition: lecui.h:76
Size of a rectangular structure.
Definition: lecui.h:117
Splash screen class. Useful for displaying graphics while app is loading.
Definition: splash.h:23
Timer manager class.
Definition: timer.h:22
Tray icon class.
Definition: tray_icon.h:45
Widget manager class.
Definition: widget.h:318
form_position
Form position.
Definition: form.h:86
@ 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_offset
Pin the form to the bottom right corner of the working area, with an offset.
@ bottom_right
Pin the form to the bottom right corner of the working area.
@ center_to_working_area
Center the form to the working area. The working area is the desktop, minus the taskbar (if visible).
@ bottom_left_offset
Pin the form to the bottom left corner of the working area, with an offset.
@ center_to_parent
Center the form to its parent.
@ top_left_offset
Pin the form to the top left corner of the working area, with an offset.
@ top_right_offset
Pin the form to the top right corner of the working area, with an offset.
@ 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
Form events.
Definition: form.h:125
std::function< void()> start
Start event. Happens after the form_events::layout event but just before the form is displayed....
Definition: form.h:171
std::function< bool(std::string &)> layout
Layout event. Happens when the form's layout is being made. All primary layout should be done here.
Definition: form.h:166
std::function< void()> close
Shutdown event. Happens when either the close button on the top right is clicked, or when Alt+F4 is p...
Definition: form.h:177
std::function< void()> caption
Caption event. Happens when the form's caption is clicked.
Definition: form.h:145
std::function< bool(std::string &)> initialize
Initialize event. Happens when the app is being initialized. All all initialization code in this hand...
Definition: form.h:152
std::function< void()> shutdown
Shutdown event. Happens after closing is confirmed but before the form's destructor is called....
Definition: form.h:182