Slider - Horizon-NTH/HorizonGUI GitHub Wiki
The Slider
class in the hgui::kernel
namespace is designed to provide a graphical slider within your
graphical application. Sliders are interactive controls that allow users to select a value from a specified range.
This class extends the Widget
class and includes features for setting and managing the slider's range,
appearance, and behavior. The class can be found in the header file Slider.h
.
The Ranges
structure represents the range of values the slider can take,
including minimum and maximum values, step size, and precision.
-
HGUI_PRECISION min
: Minimum value of the slider. -
HGUI_PRECISION max
: Maximum value of the slider. -
unsigned int step
: Step size between values (default is 0). -
unsigned int precision
: Precision of the values (default is 2).
-
HGUI_PRECISION round(HGUI_PRECISION value) const
: Rounds the given value based on the precision. -
void sort()
: Sorts the minimum and maximum values.
-
Slider(const Ranges& range, const size& size, const point& position, const std::tuple<color, color, color>& colors, Function function)
: Constructs aSlider
object with the specified range, colors (ball, inactive bar, active bar), size, position and function.
-
HGUI_PRECISION get_value() const
: Retrieves the current value of the slider. -
const Ranges& get_range() const
: Retrieves the range of the slider. -
const point& get_slider_position() const
: Retrieves the position of the slider. -
const Function& get_function() const
: Retrieves the function associated with the slider. -
const std::tuple<color, color, color>& get_colors() const
: Retrieves the colors (ball, inactive bar, active bar) of the slider. -
void set_colors(const std::tuple<color, color, color>& newColors)
: Sets the colors (ball, inactive bar, active bar) of the slider. -
void set_value(HGUI_PRECISION newValue)
: Sets the value of the slider. -
void set_range(const Ranges& newRange)
: Sets the range of the slider. -
void set_slider_position(point newPosition)
: Sets the position of the slider cursor. -
void set_function(const Function& newFunction)
: Sets the function associated with the slider.
#include <hgui/header/Slider.h>
// Example Usage of Slider class
hgui::kernel::Ranges range{ 0.0, 100.0, 1, 2 };
hgui::kernel::color inactiveColor(0.2f, 0.2f, 0.2f);
hgui::kernel::color activeColor(0.6f, 0.6f, 0.6f);
std::function<void()> sliderFunction = /* initialize function */;
hgui::kernel::Slider slider(range, inactiveColor, activeColor, { 200, 20 }, { 100, 100 }, hgui::kernel::color(1.0f, 1.0f, 1.0f), sliderFunction, 0.0);
// Get current slider value
hgui::kernel::HGUI_PRECISION sliderValue = slider.get_value();
// Change slider value
slider.set_value(50.0);
// Get slider range
const hgui::kernel::Ranges& sliderRange = slider.get_range();
// Change slider range
hgui::kernel::Ranges newRange{ 0.0, 200.0, 2, 1 };
slider.set_range(newRange);
// Set slider position
slider.set_position({ 200, 150 });
// Set slider function
std::function<void(hgui::kernel::HGUI_PRECISION)> newFunction = /* initialize new function */;
slider.set_function(newFunction);
// Draw the slider
slider.draw();
Note: In the "Example Usage" section, we demonstrate how to create a
Slider
object with specific range, colors, size, position, color, function, and angular rotation settings. You can get and set the slider's value, range, position, and associated function. The slider can be interacted with by the user and can trigger the associated function when manipulated. This class is suitable for implementing interactive sliders in your user interface.