11 const float lo = std::min(
min,
max);
12 const float hi = std::max(
min,
max);
13 value = std::clamp(v, lo, hi);
27 _editing = !adjusts_left_right() && !_editing;
40 const float old = value;
42 if (value != old && on_change) {
49 const float range = max - min;
50 const float width = transform.size.x;
51 if (width <= 0.0F || range == 0.0F) {
55 float v = min + (std::clamp((x - transform.position.x) / width, 0.0F, 1.0F) * range);
56 if (snap && step > 0.0F) {
57 v = min + (std::round((v - min) / step) * step);
90 if (!adjusts_left_right() && !_editing) {
109 const auto& s = get_style(ctx);
110 const float range = max - min;
111 const float t = range == 0.0F ? 0.0F : std::clamp((value - min) / range, 0.0F, 1.0F);
113 const float track_y = transform.position.y + ((transform.size.y - s.track_height) / 2.0F);
115 { transform.size.x, s.track_height } };
118 const asw::Quad<float> fill { track.position, { transform.size.x * t, s.track_height } };
121 const float knob_x = transform.position.x + (transform.size.x * t) - (s.knob_width / 2.0F);
123 { s.knob_width, transform.size.y } };
127 knob_color = s.disabled;
128 }
else if (_editing) {
129 knob_color = s.knob_editing;
130 }
else if (is_highlighted(ctx)) {
131 knob_color = s.knob_hover;
T x
The x component of the vector.
Shared state for the UI system.
bool show_focus
Whether focus is shown. Root turns it on for keyboard and controller navigation and off when the mous...
bool on_event(Context &ctx, const UIEvent &e) override
Handle dragging and left and right while focused.
void draw(Context &ctx) override
Draw the slider.
bool adjusts_left_right() const
Whether left and right change the value right now, without editing.
void set_from_pointer(float x)
void on_focus_changed(Context &ctx, bool focused) override
Leave edit mode when focus moves away.
float value
Current value.
void set_value(float v)
Set the value without calling on_change.
void activate(Context &ctx) override
Enter or leave edit mode when left and right move focus.
Routines for drawing sprites and primitives to the screen.
Layout widgets for the ASW UI module.
void rect_fill(const asw::Quad< float > &position, asw::Color color)
Draw a filled rectangle.
bool in_row_with_focusables(const Widget &w)
Whether a widget sits in a row with other widgets that can take focus: its parent is a horizontal Sta...
Slider widget for the ASW UI module.
RGBA color struct with 8-bit channels.
Event structure for UI interactions.
asw::Vec2< float > pointer_pos
The pointer position.
asw::input::MouseButton mouse_button
The mouse button associated with the event.
asw::input::Key key
The key associated with the event.
Type type
The type of the event.