lecui 1.0.0-alpha.20
lecui C++ user interface library
label.h
1//
2// label.h - label 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
19namespace liblec {
20 namespace lecui {
21 namespace widgets {
22 // This widget supports two kinds of formatting:
23 //
24 // 1. HTML formatting with CSS style tags
25 //
26 // e.g. "<html>This is <span style='font-size: 16.5pt; font-style: italic; color: 0x0000FFFF;'>good</span>.</html>";
27 //
28 // The supported tags are as follows:
29 //
30 // strong Bold text
31 // em Italic text
32 // u Underline text
33 // s Strikethrough text
34 // span Use CSS style tags
35 //
36 // The span tag supports the style attribute and the following properties:
37 //
38 // font-family The font name
39 // font-size The font size, either in pt or in px
40 // font-weight The font weight, either 'none' or 'bold'
41 // font-style The font style, either 'none' or 'italic'
42 // text-decoration The text decoration, either 'none' or 'underline' or 'line-through'
43 // color The text color, either in the form rgb(255, 0, 0) or 0xFF0000FF or #FF0000FF
44 //
45 // Note: the strong, em and u html tags are automatically converted to CSS style tags internally.
46 //
47 // 2. Custom formatting
48 //
49 // Start and end of XML formatting is marked by the 'text' tag: <text></text>
50 //
51 // The supported attributes of the text are:
52 //
53 // font The font name
54 // size The font size, in points
55 // bold 'true' or 'false'
56 // italic 'true' or 'false'
57 // underline 'true' or 'false'
58 // strikethrough 'true' or 'false'
59 // color 0xAABBCCDD where r = AA, g = BB, b=CC, a=DD
60 //
61 // e.g. "This is <text size='16.5' italic='true' color='0x0000FFFF'>good</text>.";
62 //
63 // Both of the above two methods of formatting will display a label with the sentence:
64 //
65 // This is good.
66 //
67 // The word 'good' will be of size 16.5, italic and blue, while the rest
68 // of the text will use the widget specifications.
69 //
70
73 class lecui_api label : public widget {
74 color _color_hot_pressed;
75 bool _multiline = false;
77 paragraph_alignment _paragraph_alignment = paragraph_alignment::top;
78
79 public:
82 _rect.size({ 200.f, 20.f });
83 };
84
89 bool operator==(const label& param);
90
95 bool operator!=(const label& param);
96
97 // generic widget
98
101 std::string& text() override;
102
106 label& text(const std::string& text);
107
110 std::string& tooltip() override;
111
115 label& tooltip(const std::string& tooltip);
116
120 lecui::rect& rect() override;
121
126
130
134 label& on_resize(const resize_params& on_resize);
135
138 cursor_type& cursor() override;
139
143 label& cursor(const cursor_type cursor);
144
147 std::string& font() override;
148
152 label& font(const std::string& font);
153
156 float& font_size() override;
157
161 label& font_size(const float& font_size);
162
165 color& color_text() override;
166
170 label& color_text(const color& color_text);
171
174 color& color_fill() override;
175
179 label& color_fill(const color& color_fill);
180
183 color& color_hot() override;
184
188 label& color_hot(const color& color_hot);
189
193
197 label& color_selected(const color& color_selected);
198
202
206 label& color_disabled(const color& color_disabled);
207
208 // widget specific widget
209
213
217 label& color_hot_pressed(const color& color_hot_pressed);
218
221 bool& multiline();
222
226 label& multiline(const bool& multiline);
227
231
235 label& alignment(const text_alignment& alignment);
236
240
245
246 public:
253 [[nodiscard]]
254 static label& add(containers::page& page, const std::string& alias = std::string());
255
262 [[nodiscard]]
263 static label& get(form& fm, const std::string& path);
264 };
265 }
266 }
267}
268
269#if defined(lecui_helper)
271#define get_label(path) liblec::lecui::widgets::label::get(*this, path)
272#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
Label widget. To instantiate and add to a container use the add static method.
Definition: label.h:73
cursor_type & cursor() override
Get or set the mouse cursor to use then over the widget.
label & color_hot_pressed(const color &color_hot_pressed)
Set the color used when the label is pressed and the mouse is over it.
static label & add(containers::page &page, const std::string &alias=std::string())
Add a label to a container.
color & color_disabled() override
Get or set the widget's color when it is disabled.
label & on_resize(const resize_params &on_resize)
Set the behaviour of the widget when its container is resized.
std::string & text() override
Get or set the widget text.
label & paragraph_alignment(const lecui::paragraph_alignment &paragraph_alignment)
Set the paragraph alignment.
label & rect(const lecui::rect &rect)
Set the position and dimensions of the widget.
label & multiline(const bool &multiline)
Set the property for whether to allow multiple lines.
static label & get(form &fm, const std::string &path)
Get the specifications of a label.
color & color_hot() override
Get or set the widget's color when the mouse is hovered over it.
label & font_size(const float &font_size)
Set the widget's font size.
label & font(const std::string &font)
Set the default widget font.
label & color_hot(const color &color_hot)
Set the widget's color when the mouse is hovered over it.
color & color_hot_pressed()
Get or set the color used when the label is pressed and the mouse is over it.
label & alignment(const text_alignment &alignment)
Set the text alignment.
label & color_text(const color &color_text)
Set the color of the widget's text.
color & color_fill() override
Get or set the fill color of the widget.
lecui::paragraph_alignment & paragraph_alignment()
Get or set the paragraph alignment.
bool operator!=(const label &param)
Check whether widget specs are NOT equal. Only those properties that require the widget resources to ...
label & color_selected(const color &color_selected)
Set the widget's color when selected.
bool & multiline()
Get or set the property for whether to allow multiple lines.
resize_params & on_resize() override
Get or set the behaviour of the widget when its container is resized.
label & tooltip(const std::string &tooltip)
Set the tooltip text.
color & color_text() override
Get or set the color of the widget's text.
label()
Constructor.
Definition: label.h:81
lecui::rect & rect() override
Get or set the position and dimensions of the widget.
label & color_disabled(const color &color_disabled)
Set the widget's color when it is disabled.
text_alignment & alignment()
Get or set the text alignment.
label & cursor(const cursor_type cursor)
Set the mouse cursor to use when over the widget.
label & text(const std::string &text)
Set the widget's text.
std::string & font() override
Get or set the default widget font, e.g. "Georgia".
color & color_selected() override
Get or set the widget's color when selected.
label & color_fill(const color &color_fill)
Set the fill color of the widget.
float & font_size() override
Get or set the default widget font size in points, e.g. 9.0f.
std::string & tooltip() override
Get or set the widget's tooltip text.
bool operator==(const label &param)
Check whether widget specs are equal. Only those properties that require the widget resources to be r...
Base class for all widgets.
Definition: widget.h:24
cursor_type
Mouse cursor type.
Definition: widget.h:27
text_alignment
Text alignment.
Definition: lecui.h:951
@ left
Align text to the left edge.
paragraph_alignment
Paragraph alignment.
Definition: lecui.h:966
@ top
Align paragraph to the top.
Top level namespace for the liblec libraries.
Definition: appearance.h:19