|
Aegis2D
Modular C++26 2D game engine for networked games
|
A value picked between two bounds, as a widget of a WidgetTree. More...
#include <aegis2d/ui/widgets.hpp>
Public Member Functions | |
| Slider (WidgetTree &tree, render::Rect bounds, const SliderConfig &config, WidgetId group=root) | |
| Adds the slider to a tree. | |
| WidgetId | id () const noexcept |
| The slider's widget in its tree. | |
| const SliderConfig & | config () const noexcept |
| Range, step and starting value. | |
| float | value () const noexcept |
| Value now. | |
| void | set_value (float value) noexcept |
| Moves the value. | |
| bool | update (Navigation &navigation, const WidgetTree &tree) |
| Applies the frame's input to the value. | |
| void | draw (render::IRenderer &renderer, const WidgetTree &tree, const SliderStyle &style={}) const |
| Draws the track, its filled part and the handle at the tree's scale. | |
A value picked between two bounds, as a widget of a WidgetTree.
The slider is a widget of the tree, so it takes the focus like a button. While it is focused, Left and Right move the value by one step (the move is consumed, so the focus stays); the mouse sets the value by pressing or dragging over it. Bounds are given at 100%, and drawing follows the tree's scale.
| aegis2d::ui::Slider::Slider | ( | WidgetTree & | tree, |
| render::Rect | bounds, | ||
| const SliderConfig & | config, | ||
| WidgetId | group = root |
||
| ) |
Adds the slider to a tree.
| tree | Tree it lives in; the slider keeps only the widget's identifier. |
| bounds | Rectangle at 100%, in logical pixels. |
| config | Range, step and starting value. |
| group | Group of the tree to put it in, root by default. |
| std::invalid_argument | if min is not below max, or the step is not above 0, or a bound is not finite; as WidgetTree::add() for group. |
|
noexcept |
Range, step and starting value.
| void aegis2d::ui::Slider::draw | ( | render::IRenderer & | renderer, |
| const WidgetTree & | tree, | ||
| const SliderStyle & | style = {} |
||
| ) | const |
Draws the track, its filled part and the handle at the tree's scale.
| renderer | Renderer in a frame. |
| tree | The tree the slider was added to. |
| style | Colors and layer. |
|
noexcept |
The slider's widget in its tree.
|
noexcept |
Moves the value.
| value | New value, clamped between min and max; NaN is ignored. |
| bool aegis2d::ui::Slider::update | ( | Navigation & | navigation, |
| const WidgetTree & | tree | ||
| ) |
Applies the frame's input to the value.
While the slider is focused, Left or Right moves the value by one step and is consumed (taken out of navigation), so the focus stays on the slider; at an end the move is still consumed. The mouse sets the value from where it presses or drags over the slider. A disabled slider changes nothing.
| navigation | Input of the frame; its direction is consumed when used. |
| tree | The tree the slider was added to. |
true if the value changed.
|
noexcept |
Value now.