lecui 1.0.0-alpha.20
lecui C++ user interface library
icon.h
1//
2// icon.h - icon 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 {
24 class lecui_api icon : public widget, public badge_widget {
25 public:
27 enum class icon_text_position {
28 right,
29 left,
30 top,
31 bottom,
32 };
33
34 private:
35 float _border = .5f;
36 color _color_border;
37 float _corner_radius_x = 3.f;
38 float _corner_radius_y = 3.f;
39 float _max_image_size = 48.f;
40 color _color_text_description;
41 float _font_size_description = 8.5f;
42 int _png_resource = 0;
43 std::string _file;
45 std::string _description;
46 icon_text_position _text_position = icon_text_position::right;
47 float _gap = 5.f;
48 float _padding = 5.f;
49 float _opacity = 100.f;
50 void* _p_special_pane_specs = nullptr;
51 void* _p_image_specs = nullptr;
52
53 public:
55 icon() {
56 _rect.size({ 160.f, 58.f });
57 _font_size = 11.f;
58 };
59
64 bool operator==(const icon& param);
65
70 bool operator!=(const icon& param);
71
72 // generic widget
73
76 std::string& text() override;
77
81 icon& text(const std::string& text);
82
85 std::string& tooltip() override;
86
90 icon& tooltip(const std::string& tooltip);
91
94 badge_specs& badge() override;
95
99 icon& badge(const badge_specs& badge);
100
104 lecui::rect& rect() override;
105
110
114
118 icon& on_resize(const resize_params& on_resize);
119
122 cursor_type& cursor() override;
123
127 icon& cursor(const cursor_type cursor);
128
131 std::string& font() override;
132
136 icon& font(const std::string& font);
137
140 float& font_size() override;
141
145 icon& font_size(const float& font_size);
146
149 color& color_text() override;
150
154 icon& color_text(const color& color_text);
155
158 color& color_fill() override;
159
163 icon& color_fill(const color& color_fill);
164
167 color& color_hot() override;
168
172 icon& color_hot(const color& color_hot);
173
177
181 icon& color_selected(const color& color_selected);
182
186
190 icon& color_disabled(const color& color_disabled);
191
192 // widget specific widget
193
196 float& border();
197
201 icon& border(const float& border);
202
206
210 icon& color_border(const color& color_border);
211
215
219 icon& corner_radius_x(const float& corner_radius_x);
220
224
228 icon& corner_radius_y(const float& corner_radius_y);
229
234
239 icon& max_image_size(const float& max_image_size);
240
244
248 icon& color_text_description(const color& color_text_description);
249
253
257 icon& font_size_description(const float& font_size_description);
258
263
268 icon& png_resource(const int& png_resource);
269
273 std::string& file();
274
279 icon& file(const std::string& file);
280
285
290 icon& quality(const image_quality& quality);
291
294 std::string& description();
295
299 icon& description(const std::string& description);
300
304
308 icon& text_position(const icon_text_position& text_position);
309
312 float& gap();
313
317 icon& gap(const float& gap);
318
321 float& padding();
322
326 icon& padding(const float& padding);
327
330 float& opacity();
331
335 icon& opacity(const float& opacity);
336
337 public:
344 [[nodiscard]]
345 static icon& add(containers::page& page, const std::string& alias = std::string());
346
353 [[nodiscard]]
354 static icon& get(form& fm, const std::string& path);
355
356 private:
357#if defined(LECUI_EXPORTS)
358 friend class form;
359#endif
360 };
361 }
362 }
363}
364
365#if defined(lecui_helper)
367#define get_icon(path) liblec::lecui::widgets::icon::get(*this, path)
368#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
Badge specifications.
Definition: widget.h:177
Base class for all widgets with badges.
Definition: widget.h:292
Icon widget. To instantiate and add to a container use the add static method.
Definition: icon.h:24
icon & color_fill(const color &color_fill)
Set the fill color of the widget.
color & color_disabled() override
Get or set the widget's color when it is disabled.
color & color_border()
Get or set the color of the border.
float & corner_radius_x()
Get or set the horizontal radius of the corners.
std::string & description()
Get or set the description text.
icon & tooltip(const std::string &tooltip)
Set the tooltip text.
icon & color_border(const color &color_border)
Set the color of the border.
icon & font_size_description(const float &font_size_description)
Set the size of the description text.
float & font_size_description()
Get or set the size of the description text.
color & color_fill() override
Get or set the fill color of the widget.
icon()
Constructor.
Definition: icon.h:55
icon & color_text_description(const color &color_text_description)
Set the color of the description text.
icon & font(const std::string &font)
Set the default widget font.
color & color_hot() override
Get or set the widget's color when the mouse is hovered over it.
icon & description(const std::string &description)
Set the description text.
icon & quality(const image_quality &quality)
Set the quality of the image in the icon.
std::string & font() override
Get or set the default widget font, e.g. "Georgia".
bool operator==(const icon &param)
Check whether widget specs are equal. Only those properties that require the widget resources to be r...
bool operator!=(const icon &param)
Check whether widget specs are NOT equal. Only those properties that require the widget resources to ...
float & max_image_size()
Get or set the maximum size of the image square's side.
icon & color_text(const color &color_text)
Set the color of the widget's text.
icon & text_position(const icon_text_position &text_position)
Set the position of the text.
icon & padding(const float &padding)
Set the padding to use around the icon.
std::string & file()
Get or set the path to the icon's image file.
icon & file(const std::string &file)
Set the path to the icon's image file.
icon_text_position & text_position()
Get or set the position of the text.
static icon & add(containers::page &page, const std::string &alias=std::string())
Add an icon to a container.
icon & rect(const lecui::rect &rect)
Set the position and dimensions of the widget.
badge_specs & badge() override
Get or set the badge specs.
icon & border(const float &border)
Set the thickness of the border.
color & color_text() override
Get or set the color of the widget's text.
icon & png_resource(const int &png_resource)
Set the icon's PNG resource.
int & png_resource()
Get or set the icon's PNG resource.
icon & color_disabled(const color &color_disabled)
Set the widget's color when it is disabled.
float & border()
Get or set the thickness of the border.
std::string & text() override
Get or set the widget text.
icon_text_position
Text position in icon.
Definition: icon.h:27
float & gap()
Get or set the gap between the text and the image and the text.
std::string & tooltip() override
Get or set the widget's tooltip text.
icon & color_selected(const color &color_selected)
Set the widget's color when selected.
icon & corner_radius_x(const float &corner_radius_x)
Set the horizontal radius of the corners.
icon & opacity(const float &opacity)
Set the opacity of the image.
color & color_selected() override
Get or set the widget's color when selected.
color & color_text_description()
Get or set the color of the description text.
float & opacity()
Get or set the opacity of the image.
float & font_size() override
Get or set the default widget font size in points, e.g. 9.0f.
icon & color_hot(const color &color_hot)
Set the widget's color when the mouse is hovered over it.
icon & corner_radius_y(const float &corner_radius_y)
Set the vertical radius of the corners.
icon & badge(const badge_specs &badge)
Set the badge specs.
resize_params & on_resize() override
Get or set the behaviour of the widget when its container is resized.
static icon & get(form &fm, const std::string &path)
Get the specifications of an icon.
icon & text(const std::string &text)
Set the widget's text.
image_quality & quality()
Get or set the quality of the image in the icon.
icon & cursor(const cursor_type cursor)
Set the mouse cursor to use when over the widget.
icon & gap(const float &gap)
Set the gap between the text and the image and the text.
icon & 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.
lecui::rect & rect() override
Get or set the position and dimensions of the widget.
icon & max_image_size(const float &max_image_size)
Set the maximum size of the image square's side.
float & padding()
Get or set the padding to use around the icon.
float & corner_radius_y()
Get or set the vertical radius of the corners.
icon & font_size(const float &font_size)
Set the widget's font size.
Base class for all widgets.
Definition: widget.h:24
cursor_type
Mouse cursor type.
Definition: widget.h:27
@ right
Align text to the right.
@ left
Align text to the left edge.
image_quality
Image render quality. Used when resampling images.
Definition: lecui.h:916
@ high
High image quality, for best image quality possibly at the cost of rendering speed.
@ bottom
Align paragraph to the bottom.
@ top
Align paragraph to the top.
Top level namespace for the liblec libraries.
Definition: appearance.h:19