lecui 1.0.0-alpha.20
lecui C++ user interface library
checkbox.h
1//
2// checkbox.h - checkbox 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 checkbox : public widget {
25 public:
27 enum class checkbox_status {
28 checked,
29 unchecked,
30 indeterminate,
31 };
32
33 private:
34 float _border = .5f;
35 color _color_border;
36 std::string _text_unchecked;
37 std::string _text_indeterminate;
38 color _color_check;
39 checkbox_status _status = checkbox_status::indeterminate;
40
41 public:
44 _cursor = cursor_type::hand;
45 _rect.size({ 20.f, 20.f });
46 }
47
52 std::function<void(checkbox_status checked)> check = nullptr;
53 };
54
58 return _checkbox_events;
59 }
60
65 bool operator==(const checkbox& param);
66
71 bool operator!=(const checkbox& param);
72
73 // generic widget
74
77 std::string& text() override;
78
82 checkbox& text(const std::string& text);
83
86 std::string& tooltip() override;
87
91 checkbox& tooltip(const std::string& tooltip);
92
96 lecui::rect& rect() override;
97
102
106
110 checkbox& on_resize(const resize_params& on_resize);
111
114 cursor_type& cursor() override;
115
120
123 std::string& font() override;
124
128 checkbox& font(const std::string& font);
129
132 float& font_size() override;
133
137 checkbox& font_size(const float& font_size);
138
141 color& color_text() override;
142
146 checkbox& color_text(const color& color_text);
147
150 color& color_fill() override;
151
155 checkbox& color_fill(const color& color_fill);
156
159 color& color_hot() override;
160
164 checkbox& color_hot(const color& color_hot);
165
169
173 checkbox& color_selected(const color& color_selected);
174
178
182 checkbox& color_disabled(const color& color_disabled);
183
184 // widget specific widget
185
188 float& border();
189
193 checkbox& border(const float& border);
194
198
202 checkbox& color_border(const color& color_border);
203
206 std::string& text_unchecked();
207
211 checkbox& text_unchecked(const std::string& text_unchecked);
212
215 std::string& text_indeterminate();
216
220 checkbox& text_indeterminate(const std::string& text_indeterminate);
221
225
229 checkbox& color_check(const color& color_check);
230
234
239
240 public:
247 [[nodiscard]]
248 static checkbox& add(containers::page& page, const std::string& alias = std::string());
249
256 [[nodiscard]]
257 static checkbox& get(form& fm, const std::string& path);
258
259 private:
261 checkbox_events _checkbox_events;
262 };
263 }
264 }
265}
266
267#if defined(lecui_helper)
269#define get_checkbox(path) liblec::lecui::widgets::checkbox::get(*this, path)
270#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
Checkbox widget. To instantiate and add to a container use the add static method.
Definition: checkbox.h:24
cursor_type & cursor() override
Get or set the mouse cursor to use then over the widget.
checkbox & color_disabled(const color &color_disabled)
Set the widget's color when it is disabled.
checkbox & cursor(const cursor_type cursor)
Set the mouse cursor to use when over the widget.
checkbox & rect(const lecui::rect &rect)
Set the position and dimensions of the widget.
checkbox & text_indeterminate(const std::string &text_indeterminate)
Set the text to display when the widget's check status has not been explicitly set.
bool operator==(const checkbox &param)
Check whether widget specs are equal. Only those properties that require the widget resources to be r...
std::string & font() override
Get or set the default widget font, e.g. "Georgia".
checkbox & font(const std::string &font)
Set the default widget font.
checkbox & text_unchecked(const std::string &text_unchecked)
Set the text to display when the widget is unchecked.
color & color_disabled() override
Get or set the widget's color when it is disabled.
float & border()
Get or set the thickness of the border.
checkbox & color_text(const color &color_text)
Set the color of the widget's text.
checkbox & status(const checkbox_status &status)
Set the status of the checkbox widget.
color & color_border()
Get or set the color of the border.
checkbox_events & events()
Get or set checkbox events.
Definition: checkbox.h:57
std::string & text_indeterminate()
Get or set the text to display when the widget's check status has not been explicitly set.
static checkbox & get(form &fm, const std::string &path)
Get the specifications of a checkbox.
lecui::rect & rect() override
Get or set the position and dimensions of the widget.
std::string & tooltip() override
Get or set the widget's tooltip text.
checkbox & on_resize(const resize_params &on_resize)
Set the behaviour of the widget when its container is resized.
checkbox_status & status()
Get or set the status of the checkbox widget.
checkbox & color_check(const color &color_check)
Set the color to use for the check symbol.
checkbox & color_selected(const color &color_selected)
Set the widget's color when selected.
color & color_text() override
Get or set the color of the widget's text.
color & color_check()
Get or set the color to use for the check symbol.
checkbox & color_fill(const color &color_fill)
Set the fill color of the widget.
std::string & text_unchecked()
Get or set the text to display when the widget is unchecked.
std::string & text() override
Get or set the widget text.
checkbox & font_size(const float &font_size)
Set the widget's font size.
checkbox & border(const float &border)
Set the thickness of the border.
color & color_hot() override
Get or set the widget's color when the mouse is hovered over it.
bool operator!=(const checkbox &param)
Check whether widget specs are NOT equal. Only those properties that require the widget resources to ...
color & color_selected() override
Get or set the widget's color when selected.
checkbox & color_hot(const color &color_hot)
Set the widget's color when the mouse is hovered over it.
checkbox_status
Checkbox status.
Definition: checkbox.h:27
checkbox & color_border(const color &color_border)
Set the color of the border.
checkbox & text(const std::string &text)
Set the widget's text.
checkbox & tooltip(const std::string &tooltip)
Set the tooltip text.
color & color_fill() override
Get or set the fill color of the widget.
static checkbox & add(containers::page &page, const std::string &alias=std::string())
Add a checkbox to a container.
float & font_size() override
Get or set the default widget font size in points, e.g. 9.0f.
checkbox()
Constructor.
Definition: checkbox.h:43
resize_params & on_resize() override
Get or set the behaviour of the widget when its container is resized.
Base class for all widgets.
Definition: widget.h:24
cursor_type
Mouse cursor type.
Definition: widget.h:27
Top level namespace for the liblec libraries.
Definition: appearance.h:19
Events specific to this widget.
Definition: checkbox.h:49
Events common to all widgets.
Definition: widget.h:72