lecui 1.0.0-alpha.20
lecui C++ user interface library
toggle.h
1//
2// toggle.h - toggle 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 {
25 class lecui_api toggle : public widget {
26 std::string _text_off = "Off";
27 color _color_on;
28 color _color_off;
29 bool _on = false;
30
31 public:
34 _cursor = cursor_type::hand;
35 _rect.size({ 200.f, 20.f });
36 _text = "On";
37 }
38
43 std::function<void(bool on)> toggle = nullptr;
44 };
45
49 return _toggle_events;
50 }
51
56 bool operator==(const toggle& param);
57
62 bool operator!=(const toggle& param);
63
64 // generic widget
65
68 std::string& text() override;
69
73 toggle& text(const std::string& text);
74
77 std::string& tooltip() override;
78
82 toggle& tooltip(const std::string& tooltip);
83
87 lecui::rect& rect() override;
88
93
97
101 toggle& on_resize(const resize_params& on_resize);
102
105 cursor_type& cursor() override;
106
110 toggle& cursor(const cursor_type cursor);
111
114 std::string& font() override;
115
119 toggle& font(const std::string& font);
120
123 float& font_size() override;
124
128 toggle& font_size(const float& font_size);
129
132 color& color_text() override;
133
137 toggle& color_text(const color& color_text);
138
141 color& color_fill() override;
142
146 toggle& color_fill(const color& color_fill);
147
150 color& color_hot() override;
151
155 toggle& color_hot(const color& color_hot);
156
160
164 toggle& color_selected(const color& color_selected);
165
169
173 toggle& color_disabled(const color& color_disabled);
174
175 // widget specific widget
176
179 std::string& text_off();
180
184 toggle& text_off(const std::string& text_off);
185
189
193 toggle& color_on(const color& color_on);
194
198
202 toggle& color_off(const color& color_off);
203
206 bool& on();
207
211 toggle& on(const bool& on);
212
213 public:
220 [[nodiscard]]
221 static toggle& add(containers::page& page, const std::string& alias = std::string());
222
229 [[nodiscard]]
230 static toggle& get(form& fm, const std::string& path);
231
232 private:
234 toggle_events _toggle_events;
235 };
236 }
237 }
238}
239
240#if defined(lecui_helper)
242#define get_toggle(path) liblec::lecui::widgets::toggle::get(*this, path)
243#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
Toggle widget. To instantiate and add to a container use the add static method.
Definition: toggle.h:25
std::string & tooltip() override
Get or set the widget's tooltip text.
toggle()
Constructor.
Definition: toggle.h:33
lecui::rect & rect() override
Get or set the position and dimensions of the widget.
static toggle & get(form &fm, const std::string &path)
Get the specifications of a toggle.
toggle & color_on(const color &color_on)
Set the background color to use when the toggle is on.
toggle & on_resize(const resize_params &on_resize)
Set the behaviour of the widget when its container is resized.
static toggle & add(containers::page &page, const std::string &alias=std::string())
Add a toggle to a container.
toggle & font_size(const float &font_size)
Set the widget's font size.
std::string & text() override
Get or set the widget text.
toggle_events & events()
Get or set toggle widget events.
Definition: toggle.h:48
std::string & font() override
Get or set the default widget font, e.g. "Georgia".
bool & on()
Get or set the toggle status.
toggle & color_hot(const color &color_hot)
Set the widget's color when the mouse is hovered over it.
toggle & color_text(const color &color_text)
Set the color of the widget's text.
resize_params & on_resize() override
Get or set the behaviour of the widget when its container is resized.
color & color_off()
Get or set the background color to use when the toggle is off.
color & color_on()
Get or set the background color to use when the toggle is on.
cursor_type & cursor() override
Get or set the mouse cursor to use then over the widget.
toggle & rect(const lecui::rect &rect)
Set the position and dimensions of the widget.
bool operator==(const toggle &param)
Check whether widget specs are equal. Only those properties that require the widget resources to be r...
toggle & color_fill(const color &color_fill)
Set the fill color of the widget.
toggle & color_off(const color &color_off)
Set the background color to use when the toggle is off.
std::string & text_off()
Get or set the text to show when the toggle is off.
toggle & cursor(const cursor_type cursor)
Set the mouse cursor to use when over the widget.
toggle & color_disabled(const color &color_disabled)
Set the widget's color when it is disabled.
color & color_fill() override
Get or set the fill color of the widget.
toggle & text_off(const std::string &text_off)
Set the text to show when the toggle is off.
toggle & tooltip(const std::string &tooltip)
Set the tooltip text.
color & color_text() override
Get or set the color of the widget's text.
color & color_selected() override
Get or set the widget's color when selected.
toggle & text(const std::string &text)
Set the widget's text.
color & color_disabled() override
Get or set the widget's color when it is disabled.
toggle & on(const bool &on)
Set the toggle status.
bool operator!=(const toggle &param)
Check whether widget specs are NOT equal. Only those properties that require the widget resources to ...
toggle & color_selected(const color &color_selected)
Set the widget's color when selected.
toggle & 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.
float & font_size() override
Get or set the default widget font size in points, e.g. 9.0f.
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: toggle.h:40
Events common to all widgets.
Definition: widget.h:72