lecui 1.0.0-alpha.20
lecui C++ user interface library
image_view.h
1//
2// image_view.h - image view 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 image_view : public widget, public badge_widget {
25 float _border = .5f;
26 color _color_border;
27 float _corner_radius_x = .0f;
28 float _corner_radius_y = .0f;
29 int _png_resource = 0;
30 std::string _file;
32 bool _enlarge_if_smaller = false;
33 bool _keep_aspect_ratio = true;
34 float _opacity = 100.f;
35
36 public:
39 _cursor = cursor_type::hand;
40 _rect.size({ 200.f, 200.f });
41 }
42
47 bool operator==(const image_view& param);
48
53 bool operator!=(const image_view& param);
54
55 // generic widget
56
59 std::string& text() override;
60
64 image_view& text(const std::string& text);
65
68 std::string& tooltip() override;
69
73 image_view& tooltip(const std::string& tooltip);
74
77 badge_specs& badge() override;
78
83
87 lecui::rect& rect() override;
88
93
97
102
105 cursor_type& cursor() override;
106
111
114 std::string& font() override;
115
119 image_view& font(const std::string& font);
120
123 float& font_size() override;
124
128 image_view& font_size(const float& font_size);
129
132 color& color_text() override;
133
137 image_view& color_text(const color& color_text);
138
141 color& color_fill() override;
142
146 image_view& color_fill(const color& color_fill);
147
150 color& color_hot() override;
151
155 image_view& color_hot(const color& color_hot);
156
160
164 image_view& color_selected(const color& color_selected);
165
169
173 image_view& color_disabled(const color& color_disabled);
174
175 // widget specific widget
176
179 float& border();
180
184 image_view& border(const float& border);
185
189
193 image_view& color_border(const color& color_border);
194
198
202 image_view& corner_radius_x(const float& corner_radius_x);
203
207
211 image_view& corner_radius_y(const float& corner_radius_y);
212
217
222 image_view& png_resource(const int& png_resource);
223
227 std::string& file();
228
233 image_view& file(const std::string& file);
234
239
245
250
256 image_view& enlarge_if_smaller(const bool& enlarge_if_smaller);
257
261
265 image_view& keep_aspect_ratio(const bool& keep_aspect_ratio);
266
269 float& opacity();
270
274 image_view& opacity(const float& opacity);
275
276 public:
283 [[nodiscard]]
284 static image_view& add(containers::page& page, const std::string& alias = std::string());
285
292 [[nodiscard]]
293 static image_view& get(form& fm, const std::string& path);
294 };
295 }
296 }
297}
298
299#if defined(lecui_helper)
301#define get_image_view(path) liblec::lecui::widgets::image_view::get(*this, path)
302#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
Image view widget. To instantiate and add to a container use the add static method.
Definition: image_view.h:24
int & png_resource()
Get or set the icon's PNG resource.
image_view & border(const float &border)
Set the thickness of the border.
color & color_text() override
Get or set the color of the widget's text.
image_view & file(const std::string &file)
Set the path to the icon's image file.
static image_view & add(containers::page &page, const std::string &alias=std::string())
Add an image view to a container.
float & border()
Get or set the thickness of the border.
image_view & png_resource(const int &png_resource)
Set the icon's PNG resource.
image_quality & quality()
Get or set the quality of the image in the icon.
float & corner_radius_y()
Get or set the vertical radius of the corners.
lecui::rect & rect() override
Get or set the position and dimensions of the widget.
image_view & text(const std::string &text)
Set the widget's text.
image_view & on_resize(const resize_params &on_resize)
Set the behaviour of the widget when its container is resized.
color & color_border()
Get or set the color of the border.
std::string & tooltip() override
Get or set the widget's tooltip text.
color & color_fill() override
Get or set the fill color of the widget.
cursor_type & cursor() override
Get or set the mouse cursor to use then over the widget.
color & color_selected() override
Get or set the widget's color when selected.
image_view & color_border(const color &color_border)
Set the color of the border.
bool operator!=(const image_view &param)
Check whether widget specs are NOT equal. Only those properties that require the widget resources to ...
bool & keep_aspect_ratio()
Get or set the property for whether to keep the image aspect ratio.
image_view & color_hot(const color &color_hot)
Set the widget's color when the mouse is hovered over it.
image_view & color_selected(const color &color_selected)
Set the widget's color when selected.
image_view()
Constructor.
Definition: image_view.h:38
image_view & corner_radius_y(const float &corner_radius_y)
Set the vertical radius of the corners.
image_view & font_size(const float &font_size)
Set the widget's font size.
bool & enlarge_if_smaller()
Get or set the property for enlarging the image to fill up the rect if the image is smaller than the ...
image_view & cursor(const cursor_type cursor)
Set the mouse cursor to use when over the widget.
image_view & tooltip(const std::string &tooltip)
Set the tooltip text.
image_view & font(const std::string &font)
Set the default widget font.
resize_params & on_resize() override
Get or set the behaviour of the widget when its container is resized.
std::string & file()
Get or set the path to the icon's image file.
image_view & color_fill(const color &color_fill)
Set the fill color of the widget.
image_view & badge(const badge_specs &badge)
Set the badge specs.
image_view & enlarge_if_smaller(const bool &enlarge_if_smaller)
Set the property for enlarging the image to fill up the rect if the image is smaller than the rectang...
image_view & quality(const image_quality &quality)
Set the quality of the image in the icon.
std::string & text() override
Get or set the widget text.
bool operator==(const image_view &param)
Check whether widget specs are equal. Only those properties that require the widget resources to be r...
image_view & color_disabled(const color &color_disabled)
Set the widget's color when it is disabled.
image_view & corner_radius_x(const float &corner_radius_x)
Set the horizontal radius of the corners.
float & opacity()
Get or set the opacity of the image.
image_view & opacity(const float &opacity)
Set the opacity of the image.
image_view & keep_aspect_ratio(const bool &keep_aspect_ratio)
Set the property for whether to keep the image aspect ratio.
color & color_hot() override
Get or set the widget's color when the mouse is hovered over it.
std::string & font() override
Get or set the default widget font, e.g. "Georgia".
badge_specs & badge() override
Get or set the badge specs.
float & font_size() override
Get or set the default widget font size in points, e.g. 9.0f.
float & corner_radius_x()
Get or set the horizontal radius of the corners.
image_view & color_text(const color &color_text)
Set the color of the widget's text.
color & color_disabled() override
Get or set the widget's color when it is disabled.
image_view & rect(const lecui::rect &rect)
Set the position and dimensions of the widget.
static image_view & get(form &fm, const std::string &path)
Get the specifications of an image view.
Base class for all widgets.
Definition: widget.h:24
cursor_type
Mouse cursor type.
Definition: widget.h:27
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.
Top level namespace for the liblec libraries.
Definition: appearance.h:19