Slider
Slider edits a controlled floating-point value.
Its default range is 0.0F through 1.0F.
Control value and range
Section titled “Control value and range”Row { Slider(volume) .Range(0.0F, 100.0F) .Step(1.0F) .OnChanged([volume](float next) { volume = next; }), Text::Format("{}%", static_cast<int>(volume)),}.With( Spacing(12.0F), CrossAlign(CrossAxisAlignment::Center)).Range(minimum, maximum) defines the legal interval.
.Step(step) snaps requested values to discrete increments.
The caller must feed accepted values back into the next composition.
Interaction and accessibility
Section titled “Interaction and accessibility”Pointer dragging, keyboard range adjustment, focus, and accessibility increment or decrement actions share the same controlled output path.
The slider exposes role, current range, optional step, enabled state, and focus semantics automatically.
Theme behavior
Section titled “Theme behavior”SliderStyle lets a theme vary track gaps, tick treatment, stop indicators, thumb geometry, colors, focus treatment, and motion without changing the controlled value contract.
- Constructors:
Slider(float)andSlider(State<float>). - Fluent methods:
.Range(float minimum, float maximum),.Step(float). - Event:
.OnChanged(function)withfloat. - Theme style:
SliderStyle.
Use ProgressBar when the value is display-only.
Validation and exact proposal behavior
Section titled “Validation and exact proposal behavior”The constructors in <huxerui/view.h> require a finite value. Range requires finite endpoints with minimum < maximum; Step requires a finite number greater than zero. Invalid input throws std::invalid_argument. Use the parameterless range defaults only for normalized values; a 0–100 slider should declare its range on every composition.
Requests clamp to the interval. With a step, interior values round to increments measured from the minimum; the endpoints remain reachable even when the step does not divide the interval evenly. This constrains interaction proposals rather than rewriting application-owned State.
Left/Down decrease and Right/Up increase by the step, or by one percent of the range without a step. Home and End request the endpoints. Accessibility range adjustment uses the same normalization. Add a semantic label such as “Volume”; the numeric value alone does not identify the setting.
SliderStyle fields
Section titled “SliderStyle fields”| Fields | Effect |
|---|---|
width, height, track_height |
Preferred control and track size. |
inactive_track, active_track, thumb |
Main enabled colors. |
stop_indicator, active_tick, inactive_tick |
Endpoint and step-mark colors. |
disabled_inactive_track, disabled_active_track, disabled_thumb, disabled_stop_indicator, disabled_active_tick, disabled_inactive_tick |
Matching disabled colors. |
thumb_width, thumb_height, hovered_thumb_width, hovered_thumb_height, pressed_thumb_width, pressed_thumb_height |
Handle geometry for each interaction state. |
thumb_track_gap, track_inside_corner_radius |
Track separation beside the handle. |
stop_indicator_size, tick_size |
Zero hides the corresponding marks. Ticks also require a step. |
focus_ring |
Optional ring override; empty inherits the theme. |
animation_duration |
Handle/state transition duration in seconds. |
Material uses a handle-and-gap treatment with endpoint/tick details; Flat uses a compact round thumb. Width remains constrained by the parent. In a Row with a trailing value label, use Grow on the slider when it should receive the remaining width.
Adjustment lifecycle
Section titled “Adjustment lifecycle”OnStarted(float) begins an adjustment at the displayed controlled value. OnChanged(float) proposes each new value; keep writing that value back. OnCommitted(float) ends an adjustment with its final proposal, not confirmation that the owner accepted it. OnCanceled() ends active pointer adjustment without rolling back earlier writes.
Use live Changed events for preview and Committed for expensive application work. Each effective keyboard press/repeat or accessibility adjustment commits independently. Unmount does not guarantee a terminal event, so do not make cleanup depend on Canceled.
#include <huxerui/huxerui.h>
using namespace huxerui;
[[huxerui::composable]]View VolumeAdjustment() { auto volume = UseState(0.5F); auto status = UseState(std::string{"Ready"}); return Column { Slider(volume) .OnStarted([status](float) { status = "Adjusting"; }) .OnCommitted([status](float value) { status = "Requested volume: " + std::to_string(value); }) .OnCanceled([status] { status = "Adjustment canceled"; }), Text(status), };}The State constructor handles Changed writeback. The final proposal may differ from a value transformed or rejected by an explicit owner handler.

