lecui 1.0.0-alpha.20
lecui C++ user interface library
slider.h
1//
2// slider.h - slider 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 {
28 class lecui_api slider : public widget {
29 public:
31 struct slider_range {
33 float minimum = 0.f;
34
36 float maximum = 100.f;
37 };
38
39 private:
40 float _border = 1.f;
41 color _color_border;
42 color _color_knob;
43 color _color_knob_hot;
44 color _color_knob_border;
45 color _color_tick;
46 bool _snap_to_ticks = true;
47 bool _show_tick_marks = true;
48 bool _show_tick_labels = true;
49 slider_range _range;
50 float _knob_radius = 8.f;
51 float _slide_thickness = 6.f;
52 float _major_tick_unit = 25.f;
53 long _minor_tick_count = 4;
54 float _value = 0.f;
55
56 public:
59 _cursor = cursor_type::hand;
60 _rect.size({ 200.f, 35.f });
61 }
62
67 std::function<void(float value)> slider = nullptr;
68 };
69
73 return _slider_events;
74 }
75
80 bool operator==(const slider& param);
81
86 bool operator!=(const slider& param);
87
88 // generic widget
89
92 std::string& text() override;
93
97 slider& text(const std::string& text);
98
101 std::string& tooltip() override;
102
106 slider& tooltip(const std::string& tooltip);
107
111 lecui::rect& rect() override;
112
117
121
125 slider& on_resize(const resize_params& on_resize);
126
129 cursor_type& cursor() override;
130
134 slider& cursor(const cursor_type cursor);
135
138 std::string& font() override;
139
143 slider& font(const std::string& font);
144
147 float& font_size() override;
148
152 slider& font_size(const float& font_size);
153
156 color& color_text() override;
157
161 slider& color_text(const color& color_text);
162
165 color& color_fill() override;
166
170 slider& color_fill(const color& color_fill);
171
174 color& color_hot() override;
175
179 slider& color_hot(const color& color_hot);
180
184
188 slider& color_selected(const color& color_selected);
189
193
197 slider& color_disabled(const color& color_disabled);
198
199 // widget specific widget
200
203 float& border();
204
208 slider& border(const float& border);
209
213
217 slider& color_border(const color& color_border);
218
222
226 slider& color_knob(const color& color_knob);
227
231
235 slider& color_knob_hot(const color& color_knob_hot);
236
240
244 slider& color_knob_border(const color& color_knob_border);
245
249
253 slider& color_tick(const color& color_tick);
254
258
262 slider& snap_to_ticks(const bool& snap_to_ticks);
263
267
271 slider& show_tick_marks(const bool& show_tick_marks);
272
276
280 slider& show_tick_labels(const bool& show_tick_labels);
281
285
289 slider& range(const slider_range& range);
290
293 float& knob_radius();
294
298 slider& knob_radius(const float& knob_radius);
299
303
307 slider& slide_thickness(const float& slide_thickness);
308
312
316 slider& major_tick_unit(const float& major_tick_unit);
317
322
327 slider& minor_tick_count(const long& minor_tick_count);
328
331 float& value();
332
336 slider& value(const float& value);
337
338 public:
345 [[nodiscard]]
346 static slider& add(containers::page& page, const std::string& alias = std::string());
347
354 [[nodiscard]]
355 static slider& get(form& fm, const std::string& path);
356
357 private:
359 slider_events _slider_events;
360 };
361 }
362 }
363}
364
365#if defined(lecui_helper)
367#define get_slider(path) liblec::lecui::widgets::slider::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
Slider widget. To instantiate and add to a container use the add static method.
Definition: slider.h:28
float & font_size() override
Get or set the default widget font size in points, e.g. 9.0f.
resize_params & on_resize() override
Get or set the behaviour of the widget when its container is resized.
slider & range(const slider_range &range)
Set the slider's range.
slider & color_knob_border(const color &color_knob_border)
Set the color of the knob's border.
slider & color_knob(const color &color_knob)
Set the color of the knob.
color & color_knob()
Get or set the color of the knob.
std::string & font() override
Get or set the default widget font, e.g. "Georgia".
slider & color_selected(const color &color_selected)
Set the widget's color when selected.
slider_range & range()
Get or set the slider's range.
slider_events & events()
Get or set slider events.
Definition: slider.h:72
float & major_tick_unit()
Get or set the unit intervals for placing major ticks.
color & color_fill() override
Get or set the fill color of the widget.
slider()
Constructor.
Definition: slider.h:58
slider & text(const std::string &text)
Set the widget's text.
slider & color_text(const color &color_text)
Set the color of the widget's text.
long & minor_tick_count()
Get or set the number of minor ticks to place between successive major ticks.
float & slide_thickness()
Get or set the thickness of the slide.
std::string & tooltip() override
Get or set the widget's tooltip text.
color & color_hot() override
Get or set the widget's color when the mouse is hovered over it.
slider & color_hot(const color &color_hot)
Set the widget's color when the mouse is hovered over it.
slider & color_border(const color &color_border)
Set the color of the border.
color & color_border()
Get or set the color of the border.
float & value()
Get or set the position of the knob along the slide.
bool & show_tick_marks()
Get or set the property for whether to show ticks marks on the slider.
slider & cursor(const cursor_type cursor)
Set the mouse cursor to use when over the widget.
lecui::rect & rect() override
Get or set the position and dimensions of the widget.
slider & snap_to_ticks(const bool &snap_to_ticks)
Set the property for whether to snap slider movements to the ticks.
float & border()
Get or set the thickness of the border.
slider & font_size(const float &font_size)
Set the widget's font size.
slider & color_tick(const color &color_tick)
Set the color of the slider ticks.
color & color_text() override
Get or set the color of the widget's text.
slider & minor_tick_count(const long &minor_tick_count)
Set the number of minor ticks to place between successive major ticks, e.g. 4.
slider & slide_thickness(const float &slide_thickness)
Set the thickness of the slide.
slider & tooltip(const std::string &tooltip)
Set the tooltip text.
bool & snap_to_ticks()
Get or set the property for whether to snap slider movements to the ticks.
slider & rect(const lecui::rect &rect)
Set the position and dimensions of the widget.
slider & major_tick_unit(const float &major_tick_unit)
Set the unit intervals for placing major ticks, e.g. 25.f.
std::string & text() override
Get or set the widget text.
slider & on_resize(const resize_params &on_resize)
Set the behaviour of the widget when its container is resized.
slider & value(const float &value)
Set the position of the knob along the slide, e.g. 63.5f.
bool operator==(const slider &param)
Check whether widget specs are equal. Only those properties that require the widget resources to be r...
slider & color_disabled(const color &color_disabled)
Set the widget's color when it is disabled.
color & color_disabled() override
Get or set the widget's color when it is disabled.
static slider & get(form &fm, const std::string &path)
Get the specifications of a slider.
color & color_knob_border()
Get or set the color of the knob's border.
color & color_tick()
Get or set the color of the slider ticks.
slider & border(const float &border)
Set the thickness of the border.
float & knob_radius()
Get or set the radius of the knob.
bool operator!=(const slider &param)
Check whether widget specs are NOT equal. Only those properties that require the widget resources to ...
slider & show_tick_marks(const bool &show_tick_marks)
Set the property for whether to show ticks marks on the slider.
slider & color_fill(const color &color_fill)
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.
slider & font(const std::string &font)
Set the default widget font.
color & color_knob_hot()
Get or set the color of the knob when the mouse is over the slider.
static slider & add(containers::page &page, const std::string &alias=std::string())
Add a slider to a container.
slider & color_knob_hot(const color &color_knob_hot)
Set the color of the knob when the mouse is over the slider.
slider & knob_radius(const float &knob_radius)
Set the radius of the knob.
slider & show_tick_labels(const bool &show_tick_labels)
Set the property for whether to show tick labels on the slider.
bool & show_tick_labels()
Get or set the property for whether to show tick labels on the slider.
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: slider.h:64
Slider range.
Definition: slider.h:31
Events common to all widgets.
Definition: widget.h:72