lecui 1.0.0-alpha.20
lecui C++ user interface library
lecui.h
1//
2// lecui.h - lecui 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 #define lecui_api __declspec(dllexport)
15#else
16 #define lecui_api __declspec(dllimport)
17
18 // for helper macros, e.g. get_text_field()
19 #define lecui_helper 1
20
21 // for visual styles (message box, open file, save file)
22 #pragma comment(linker, "\"/manifestdependency:type='win32' \
23 name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
24 processorArchitecture='*' publicKeyToken='6595b64144ccf1df' \
25 language='*'\"")
26
27 #if defined(_WIN64)
28 #if defined(_DEBUG)
29 #pragma comment(lib, "lecui64d.lib")
30 #else
31 #pragma comment(lib, "lecui64.lib")
32 #endif
33 #else
34 #if defined(_DEBUG)
35 #pragma comment(lib, "lecui32d.lib")
36 #else
37 #pragma comment(lib, "lecui32.lib")
38 #endif
39 #endif
40#endif
41
42#if defined(_MSC_VER)
43// Turn off annoying "needs to have dll-interface" warning
44#pragma warning(disable:4251)
45#endif
46
47#include <string>
48#include <vector>
49#include <map>
50#include <any>
51
53namespace liblec {
55 namespace lecui {
59 std::string lecui_api version();
60
65 std::string lecui_api unique_string();
66
72 std::string lecui_api unique_string_short();
73
76 class lecui_api point {
77 float _x = 0.f;
78 float _y = 0.f;
79
80 public:
83
87 point(const float x, const float y);
88
91 float& x();
92
95 float get_x() const;
96
100 point& x(const float& x);
101
104 float& y();
105
108 float get_y() const;
109
113 point& y(const float& y);
114 };
115
117 class lecui_api size {
118 float _width = 0.f;
119 float _height = 0.f;
120
121 public:
124
128 size(const float width, const float height);
129
132 float& width();
133
136 float get_width() const;
137
141 size& width(const float& width);
142
145 float& height();
146
149 float get_height() const;
150
154 size& height(const float& height);
155 };
156
158 class lecui_api rect {
159 float _left = 0.f;
160 float _right = 0.f;
161 float _top = 0.f;
162 float _bottom = 0.f;
163
164 public:
167
171
177 rect(const float left, const float right, const float top, const float bottom);
178
181 float& left();
182
185 float get_left() const;
186
190 rect& left(const float& left);
191
194 float& right();
195
198 float get_right() const;
199
203 rect& right(const float& right);
204
207 float& top();
208
211 float get_top() const;
212
216 rect& top(const float& top);
217
220 float& bottom();
221
224 float get_bottom() const;
225
229 rect& bottom(const float& bottom);
230
233 [[nodiscard]] float width() const;
234
237 [[nodiscard]] float height() const;
238
241 [[nodiscard]] size size() const;
242
247 rect& width(float width);
248
253 rect& height(float height);
254
260
266 rect& size(float width, float height);
267
274 rect& set(float x, float y, float cx, float cy);
275
282 rect& move(float x, float y);
283
292 rect& place(const rect& rect_reference, const float& perc_h, const float& perc_v);
293
295 enum class snap_type {
298
300 bottom,
301
304
306 top_left,
307
309 top,
310
312 top_right,
313
315 right_top,
316
318 right,
319
321 right_bottom,
322
324 left_top,
325
327 left,
328
330 left_bottom,
331 };
332
339 rect& snap_to(const rect& rect_reference, snap_type type, const float& clearance);
340
347 rect& clip_to(const rect& rect_reference, const float& clearance);
348
352 bool operator==(const rect& param);
353
357 bool operator!=(const rect& param);
358 };
359
363 class lecui_api resize_params {
364 float _x_rate = 0.f;
365 float _y_rate = 0.f;
366 float _width_rate = 0.f;
367 float _height_rate = 0.f;
368 float _min_x = 0.f;
369 float _min_y = 0.f;
370 float _max_x = 0.f;
371 float _max_y = 0.f;
372 float _min_width = 0.f;
373 float _min_height = 0.f;
374 float _max_width = 0.f;
375 float _max_height = 0.f;
376
377 public:
381
389 resize_params(const float x_rate, const float y_rate, const float width_rate, const float height_rate);
390
395 float& x_rate();
396
401 float get_x_rate() const;
402
408 resize_params& x_rate(const float& x_rate);
409
414 float& y_rate();
415
420 float get_y_rate() const;
421
427 resize_params& y_rate(const float& y_rate);
428
433 float& width_rate();
434
439 float get_width_rate() const;
440
446 resize_params& width_rate(const float& width_rate);
447
452 float& height_rate();
453
458 float get_height_rate() const;
459
465 resize_params& height_rate(const float& height_rate);
466
469 float& min_x();
470
473 const float get_min_x() const;
474
478 resize_params& min_x(const float& min_x);
479
482 float& min_y();
483
486 float get_min_y() const;
487
491 resize_params& min_y(const float& min_y);
492
495 float& max_x();
496
499 float get_max_x() const;
500
504 resize_params& max_x(const float& max_x);
505
508 float& max_y();
509
512 float get_max_y() const;
513
517 resize_params& max_y(const float& max_y);
518
521 float& min_width();
522
525 float get_min_width() const;
526
530 resize_params& min_width(const float& min_width);
531
534 float& min_height();
535
538 float get_min_height() const;
539
543 resize_params& min_height(const float& min_height);
544
547 float& max_width();
548
551 float get_max_width() const;
552
556 resize_params& max_width(const float& max_width);
557
560 float& max_height();
561
564 float get_max_height() const;
565
569 resize_params& max_height(const float& max_height);
570
574 bool operator==(const resize_params& param);
575
579 bool operator!=(const resize_params& param);
580 };
581
583 class lecui_api color {
584 unsigned short _red = 0;
585 unsigned short _green = 0;
586 unsigned short _blue = 0;
587 unsigned short _alpha = 255;
588
589 public:
592
598 color(const unsigned short red,
599 const unsigned short green,
600 const unsigned short blue,
601 const unsigned short alpha);
602
605 unsigned short& red();
606
609 unsigned short get_red() const;
610
614 color& red(const unsigned short& red);
615
618 unsigned short& green();
619
622 unsigned short get_green() const;
623
627 color& green(const unsigned short& green);
628
631 unsigned short& blue();
632
635 unsigned short get_blue() const;
636
640 color& blue(const unsigned short& blue);
641
644 unsigned short& alpha();
645
648 unsigned short get_alpha() const;
649
653 color& alpha(const unsigned short& alpha);
654
658 color& darken(const float& percentage);
659
663 color& lighten(const float& percentage);
664
669 bool operator==(const color& param);
670
675 bool operator!=(const color& param);
676 };
677
679 enum class sort_options {
681 ascending,
682
685
687 none,
688 };
689
691 struct file_type {
693 std::string extension = "png";
694
698 std::string description = "PNG Image";
699 };
700
702 class lecui_api open_file_params {
703 std::string _title = "Open File";
704 std::vector<file_type> _file_types;
705 std::string _default_type;
706 bool _include_all_supported_types = true;
707 bool _allow_multi_select = false;
708
709 public:
712 std::string& title();
713
716 const std::string& get_title() const;
717
721 open_file_params& title(const std::string& title);
722
725 std::vector<file_type>& file_types();
726
729 const std::vector<file_type>& get_file_types() const;
730
734 open_file_params& file_types(const std::vector<file_type>& file_types);
735
740 std::string& default_type();
741
746 const std::string& get_default_type() const;
747
753 open_file_params& default_type(const std::string& default_type);
754
758
762
766 open_file_params& include_all_supported_types(const bool& include_all_supported_types);
767
771
774 const bool& get_allow_multi_select() const;
775
779 open_file_params& allow_multi_select(const bool& allow_multi_select);
780 };
781
783 class lecui_api save_file_params {
784 std::string _title = "Save File";
785 std::vector<file_type> _file_types;
786 std::string _default_type;
787 bool _include_all_files = true;
788
789 public:
792 std::string& title();
793
796 const std::string& get_title() const;
797
801 save_file_params& title(const std::string& title);
802
805 std::vector<file_type>& file_types();
806
809 const std::vector<file_type>& get_file_types() const;
810
814 save_file_params& file_types(const std::vector<file_type>& file_types);
815
820 std::string& default_type();
821
826 const std::string& get_default_type() const;
827
833 save_file_params& default_type(const std::string& default_type);
834
838
841 const bool& get_include_all_files() const;
842
846 save_file_params& include_all_files(const bool& include_all_files);
847 };
848
852 std::string name;
853
855 unsigned short width = 80;
856
858 int precision = 2;
859
863 bool operator==(const table_column& param);
864
868 bool operator!=(const table_column& param);
869 };
870
875 using table_row = std::map<std::string, std::any>;
876
878 class lecui_api time {
879 public:
881 unsigned short hour = 0;
882
884 unsigned short minute = 0;
885
887 unsigned short second = 0;
888
892
896 time(const std::string s);
897
900 std::string to_string();
901 };
902
904 struct date {
906 unsigned short day = 1;
907
909 unsigned short month = 1;
910
912 unsigned short year = 2020;
913 };
914
916 enum class image_quality {
918 low,
919
921 medium,
922
924 high,
925 };
926
932 class lecui_api get {
933 public:
937 static int integer(const std::any& value);
938
942 static double real(const std::any& value);
943
947 static std::string text(const std::any& value);
948 };
949
951 enum class text_alignment {
953 left,
954
956 center,
957
959 right,
960
962 justified,
963 };
964
968 top,
969
971 middle,
972
974 bottom,
975 };
976 }
977}
RGBA color on a standard 0 to 255 scale. For the alpha channel 0 is transparent and 255 is opaque.
Definition: lecui.h:583
unsigned short & green()
Get or set the green property.
color()
Color constructor. Makes opaque black (0, 0, 0, 255).
unsigned short & alpha()
Get or set the alpha property.
unsigned short & blue()
Get or set the blue property.
color & lighten(const float &percentage)
Lighten the color.
unsigned short get_red() const
Get the red property.
color & alpha(const unsigned short &alpha)
Set the alpha property.
color(const unsigned short red, const unsigned short green, const unsigned short blue, const unsigned short alpha)
Color constructor.
unsigned short get_blue() const
Get the blue property.
unsigned short get_green() const
Get the green property.
color & darken(const float &percentage)
Darken the color.
bool operator==(const color &param)
Check whether two colors are equal. All properties are considered.
unsigned short get_alpha() const
Get the alpha property.
unsigned short & red()
Get or set the red property.
color & red(const unsigned short &red)
Set the red property.
color & blue(const unsigned short &blue)
Set the blue property.
color & green(const unsigned short &green)
Set the green property.
bool operator!=(const color &param)
Check whether two colors are NOT equal. All properties are considered.
Helper class for extracting values from a std::any. Strictly added to enable more terse code and make...
Definition: lecui.h:932
static double real(const std::any &value)
Extract double value.
static std::string text(const std::any &value)
Extract text.
static int integer(const std::any &value)
Extract integer value.
Open file parameters.
Definition: lecui.h:702
std::string & title()
Get or set the title of the modal form.
bool & allow_multi_select()
Get or set whether to allow the selection of multiple files.
const bool & get_include_all_supported_types() const
Get whether to include an entry for "all supported file types".
const std::string & get_title() const
Get the title of the modal form.
open_file_params & default_type(const std::string &default_type)
Set the file type to open by default.
open_file_params & allow_multi_select(const bool &allow_multi_select)
Set whether to allow the selection of multiple files.
open_file_params & include_all_supported_types(const bool &include_all_supported_types)
Set whether to include an entry for "all supported file types".
std::vector< file_type > & file_types()
Get or set the file types to open, as defined in file_type.
std::string & default_type()
Get or set the file type to open by default, e.g. "PNG Image".
const bool & get_allow_multi_select() const
Get whether to allow the selection of multiple files.
open_file_params & file_types(const std::vector< file_type > &file_types)
Set the file types to open.
bool & include_all_supported_types()
Get or set whether to include an entry for "all supported file types".
const std::vector< file_type > & get_file_types() const
Get the file types to open, as defined in file_type.
open_file_params & title(const std::string &title)
Set the title of the modal form.
const std::string & get_default_type() const
Get the file type to open by default, e.g. "PNG Image".
A point.
Definition: lecui.h:76
float get_y() const
Get the y-coordinate, in pixels.
float & x()
Get or set the x-coordinate, in pixels.
point(const float x, const float y)
Point constructor.
point & x(const float &x)
Set the x-coordinate, in pixels.
float & y()
Get or set the y-coordinate, in pixels.
float get_x() const
Get the x-coordinate, in pixels.
point()
Point constructor. Initializes at the origin (0.f, 0.f).
point & y(const float &y)
Set the y-coordinate, in pixels.
Rectangle class.
Definition: lecui.h:158
bool operator!=(const rect &param)
Check whether two rectangles are NOT equal. All properties are considered.
float get_left() const
Get the left coordinate.
rect & right(const float &right)
Set the right coordinate.
rect & snap_to(const rect &rect_reference, snap_type type, const float &clearance)
Snap this rectangle to another, for quick positioning.
rect & width(float width)
Set the rectangle's width.
float get_right() const
Get the right coordinate.
snap_type
Snap type, used to position a rectangle next to another (reference) rectangle.
Definition: lecui.h:295
float width() const
Get the rectangle's width.
float & left()
Get or set the left coordinate.
rect & place(const rect &rect_reference, const float &perc_h, const float &perc_v)
Place this rectangle within or over another.
float get_top() const
Get the top coordinate.
rect & height(float height)
Set the rectangle's height.
float & bottom()
Get or set the bottom coordinate.
rect(const lecui::size size)
Rectangle constructor.
float & top()
Get or set the top coordinate.
size size() const
Get the rectangle's size.
rect & set(float x, float y, float cx, float cy)
Set the rectangle dimensions and position.
bool operator==(const rect &param)
Check whether two rectangles are equal. All properties are considered.
rect()
Rectangle constructor. Makes a zero size rectangle with zero width and height.
float & right()
Get or set the right coordinate.
rect & clip_to(const rect &rect_reference, const float &clearance)
Clip a rectangle within another, to prevent a rectangle going beyond stipulated confines.
float height() const
Get the rectangle's height.
rect & size(lecui::size size)
Set the rectangle's size (both width and height).
rect & bottom(const float &bottom)
Set the bottom coordinate.
float get_bottom() const
Get the bottom coordinate.
rect(const float left, const float right, const float top, const float bottom)
Rectangle constructor.
rect & left(const float &left)
Set the left coordinate.
rect & size(float width, float height)
Set the rectangle's size (both width and height).
rect & move(float x, float y)
Move the rectangle using it's top left corner.
rect & top(const float &top)
Set the top coordinate.
Resize parameters.
Definition: lecui.h:363
const float get_min_x() const
Get the minimum x-coordinate permitted as widget moves.
resize_params & y_rate(const float &y_rate)
Set the percentage rate for following the container's bottom border. 0 = doesn't move vertically,...
bool operator==(const resize_params &param)
Check whether two resize parameter objects are equal. All properties are considered.
float get_y_rate() const
Get the percentage rate for following the container's bottom border. 0 = doesn't move vertically,...
float & width_rate()
Get or set the percentage rate for following the container's change in width. 0 = doesn't follow chan...
resize_params & max_y(const float &max_y)
Set the maximum y-coordinate permitted as widget moves.
resize_params(const float x_rate, const float y_rate, const float width_rate, const float height_rate)
Constructor that allows initializing the most important properties.
resize_params & max_x(const float &max_x)
Set the maximum x-coordinate permitted as widget moves.
float get_min_y() const
Get minimum y-coordinate permitted as widget moves.
float & min_height()
Get or set the minimum height permitted as widget is resized.
float & min_width()
Get or set the minimum width permitted as widget is resized.
resize_params & height_rate(const float &height_rate)
Set the percentage rate for following the container's change in height. 0 = doesn't follow change in ...
resize_params & min_y(const float &min_y)
Set the minimum y-coordinate permitted as widget moves.
resize_params & width_rate(const float &width_rate)
Set the percentage rate for following the container's change in width. 0 = doesn't follow change in c...
float get_max_y() const
Get maximum y-coordinate permitted as widget moves.
float & max_height()
Get or set the maximum height permitted as widget is resized.
resize_params & x_rate(const float &x_rate)
Set the percentage rate for following the container's right border. 0 = doesn't move horizontally,...
float get_max_width() const
Get the maximum width permitted as widget is resized.
resize_params & min_x(const float &min_x)
Set the minimum x-coordinate permitted as widget moves.
float get_min_width() const
Get the minimum width permitted as widget is resized.
float & x_rate()
Get or set the percentage rate for following the container's right border. 0 = doesn't move horizonta...
float get_height_rate() const
Get the percentage rate for following the container's change in height. 0 = doesn't follow change in ...
resize_params & min_width(const float &min_width)
Set the minimum width permitted as widget is resized.
float & min_x()
Get or set the minimum x-coordinate permitted as widget moves.
bool operator!=(const resize_params &param)
Check whether two resize parameter objects are NOT equal. All properties are considered.
float get_min_height() const
Get the minimum height permitted as widget is resized.
float get_x_rate() const
Get the percentage rate for following the container's right border. 0 = doesn't move horizontally,...
float & max_width()
Get or set the maximum width permitted as widget is resized.
float & max_y()
Get or set the maximum y-coordinate permitted as widget moves.
float & height_rate()
Get or set the percentage rate for following the container's change in height. 0 = doesn't follow cha...
float get_max_x() const
Get the maximum x-coordinate permitted as widget moves.
resize_params & max_width(const float &max_width)
Set the maximum width permitted as widget is resized.
float get_max_height() const
Get the maximum height permitted as widget is resized.
float & y_rate()
Get or set the percentage rate for following the container's bottom border. 0 = doesn't move vertical...
float & min_y()
Get or set the minimum y-coordinate permitted as widget moves.
resize_params & max_height(const float &max_height)
Set the maximum height permitted as widget is resized.
float & max_x()
Get or set the maximum x-coordinate permitted as widget moves.
resize_params & min_height(const float &min_height)
Set the minimum height permitted as widget is resized.
float get_width_rate() const
Get the percentage rate for following the container's change in width. 0 = doesn't follow change in c...
Save file parameters.
Definition: lecui.h:783
save_file_params & file_types(const std::vector< file_type > &file_types)
Set the file types to open.
bool & include_all_files()
Get or set whether to include and "all files" entry to allow saving files with a custom extension (or...
save_file_params & include_all_files(const bool &include_all_files)
Set whether to include and "all files" entry to allow saving files with a custom extension (or none).
std::string & default_type()
Get or set the file type to open by default, e.g. "PNG Image".
std::vector< file_type > & file_types()
Get or set the file types to save to, as defined in file_type.
const std::vector< file_type > & get_file_types() const
Get the file types to save to, as defined in file_type.
save_file_params & default_type(const std::string &default_type)
Set the file type to open by default.
std::string & title()
Get or set the title of the modal form.
const std::string & get_title() const
Get the title of the modal form.
save_file_params & title(const std::string &title)
Set the title of the modal form.
const std::string & get_default_type() const
Get the file type to open by default, e.g. "PNG Image".
const bool & get_include_all_files() const
Get whether to include and "all files" entry to allow saving files with a custom extension (or none).
Size of a rectangular structure.
Definition: lecui.h:117
size()
Size constructor. Initializes with a size of 0.f x 0.f.
float get_width() const
Get or set the width of the rectangular structure, in pixels.
size & width(const float &width)
Set the width of a rectangular structure, in pixels.
float & width()
Get or set the width of the rectangular structure, in pixels.
size(const float width, const float height)
Size constructor.
float get_height() const
Get or set the height of the rectangular structure, in pixels.
size & height(const float &height)
Set the height of a rectangular structure, in pixels.
float & height()
Get or set the height of the rectangular structure, in pixels.
Time class.
Definition: lecui.h:878
std::string to_string()
Get time in the form of a string.
time(const std::string s)
Constructor.
time()
Constructor.
std::string lecui_api version()
Get the version of the lecui library.
std::map< std::string, std::any > table_row
Table row; a list of (column, value) pairs. The map's "key" is the column name and it's "value" is th...
Definition: lecui.h:875
text_alignment
Text alignment.
Definition: lecui.h:951
@ right
Align text to the right.
@ left
Align text to the left edge.
@ justified
Justify the text.
@ center
Align text to the center.
image_quality
Image render quality. Used when resampling images.
Definition: lecui.h:916
@ medium
Medium image quality, for a balance between quality and rendering speed.
@ low
Low image quality, for faster rendering.
@ high
High image quality, for best image quality possibly at the cost of rendering speed.
std::string lecui_api unique_string()
Make a unique string.
paragraph_alignment
Paragraph alignment.
Definition: lecui.h:966
@ middle
Align paragraph to the middle.
@ bottom
Align paragraph to the bottom.
@ top
Align paragraph to the top.
sort_options
Sort options.
Definition: lecui.h:679
@ none
No sorting order specified.
@ ascending
Sort in ascending order.
@ descending
Sort in descending order.
std::string lecui_api unique_string_short()
Make a short unique string.
@ 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
Date class.
Definition: lecui.h:904
unsigned short month
The month of the year, from 1 to 12 inclusive.
Definition: lecui.h:909
unsigned short year
The year.
Definition: lecui.h:912
unsigned short day
The day of the month.
Definition: lecui.h:906
File type.
Definition: lecui.h:691
std::string description
The description of the file type, e.g. "PNG Image".
Definition: lecui.h:698
std::string extension
The file extension, excluding the dot, e.g. "png".
Definition: lecui.h:693
Table column.
Definition: lecui.h:850
bool operator==(const table_column &param)
Check whether two columns are equal. Only the name and width are considered.
int precision
The number of decimal places to round off the entries in this column to when displaying (if they are ...
Definition: lecui.h:858
unsigned short width
The width of the column, in pixels.
Definition: lecui.h:855
std::string name
The name of the column. Has to be unique.
Definition: lecui.h:852
bool operator!=(const table_column &param)
Check whether two columns are NOT equal. Only the name and width are considered.