XU XUv0.13.1
中文

UI / WIDGETS / Selection

Slider

Adjust a value within a range

Run the Xu example

The example executes in the browser using the Xu/WASM runtime.

What to try

Drag the slider, or use arrow keys after focusing it, to change the value.

Usage notes

Provide minimum, maximum and current values. Choose a useful step and decide whether changes apply during dragging or only on commit.

Create through Screen

The Screen constructor returns a node ID. Pass that ID to Screen layout, state and event APIs. It is separate from the standalone control object documented below.

Native Xu setup fragment: call configure during initialization of an existing Screen. See the complete example for window creation, event dispatch and cleanup.

#ui/widgets

fn configure(screen $&widgets.Screen) int {
    id := screen.slider(0.0,100.0,40.0) or >>
    screen.place(id,24.0,24.0,320.0,80.0) or >>
    << id
}

($&Screen) slider

XuAPI
pub fn (s $&Screen) slider(minimum f64,maximum f64,value f64) int

Purpose

Create Slider in Screen and return the component node ID; throw on creation failure.

Parameters

s $&Screen
The Screen instance used by this call (exclusive borrow).
minimum f64
minimum (f64)
maximum f64
maximum (f64)
value f64
value (f64)

Returns

int — component node ID for place and other Screen methods.

Placement, state and events

The application owns the component. Screen.place positions nodes; Screen.set_enabled and Screen.set_visible control availability and visibility. Present again after state changes, handle or errors, and keep topology changes outside paint callbacks. ToastHost uses its own queue API.

Action · Styles · UI lifecycle and styling guide

Screen.place · Screen.set_enabled · Screen.set_visible

Standalone control object API

These types and methods support applications that manage control objects, input and painting directly. Their receiver is a control object, not a Screen node ID. For Screen usage, use the constructor above and the Screen methods in the Widgets module.

(&Slider) clone

XuAPI
pub fn (value &Slider) clone() Slider

Purpose

Copy the control or style snapshot into an independent Slider value.

Parameters

value &Slider
The Slider instance used by this call (borrow).

Returns

Slider — a value of this type

($&Slider) set_locale

XuAPI
pub fn (slider $&Slider) set_locale(locale &Locale) int

Purpose

Operation on $&Slider: set locale. Throws on failure; handle the error or propagate it to the caller.

Parameters

slider $&Slider
The Slider instance used by this call (exclusive borrow).
locale &Locale
locale (read-only borrow; caller keeps the original; type &Locale)

Returns

int — a value of this type

struct Slider

XuAPI
pub struct Slider {

}

Purpose

Slider context or state structure.

Public fields

This type has no public fields.

See usage example

(&Slider) id

XuAPI
pub fn (s &Slider) id() int

Purpose

Return the unique integer ID of the element or control.

Parameters

s &Slider
The Slider instance used by this call (borrow).

Returns

int — a value of this type

(&Slider) is_selectable

XuAPI
pub fn (s &Slider) is_selectable() bool

Purpose

Operation on &Slider: whether it is selectable.

Parameters

s &Slider
The Slider instance used by this call (borrow).

Returns

bool — true or false

($&Slider) set_selectable

XuAPI
pub fn (s $&Slider) set_selectable(selectable bool)

Purpose

Operation on $&Slider: set selectable.

Parameters

s $&Slider
The Slider instance used by this call (exclusive borrow).
selectable bool
selectable (bool)

Returns

This call does not return a value.

(&Slider) bounds

XuAPI
pub fn (s &Slider) bounds() layout.Rect

Purpose

Return the bounding Rectangle of the control or geometry.

Parameters

s &Slider
The Slider instance used by this call (borrow).

Returns

layout.Rect — a value of this type

(&Slider) value

XuAPI
pub fn (s &Slider) value() f64

Purpose

Execute value on &Slider.

Parameters

s &Slider
The Slider instance used by this call (borrow).

Returns

f64 — a value of this type

(&Slider) min

XuAPI
pub fn (s &Slider) min() f64

Purpose

Operation on &Slider: return the smaller of two numeric values.

Parameters

s &Slider
The Slider instance used by this call (borrow).

Returns

f64 — a value of this type

(&Slider) max

XuAPI
pub fn (s &Slider) max() f64

Purpose

Operation on &Slider: return the larger of two numeric values.

Parameters

s &Slider
The Slider instance used by this call (borrow).

Returns

f64 — a value of this type

(&Slider) step

XuAPI
pub fn (s &Slider) step() f64

Purpose

Execute step on &Slider.

Parameters

s &Slider
The Slider instance used by this call (borrow).

Returns

f64 — a value of this type

(&Slider) ratio

XuAPI
pub fn (s &Slider) ratio() f64

Purpose

Execute ratio on &Slider.

Parameters

s &Slider
The Slider instance used by this call (borrow).

Returns

f64 — a value of this type

(&Slider) needs_paint

XuAPI
pub fn (s &Slider) needs_paint() bool

Purpose

Return whether the control needs repainting; call painted after painting to clear the flag.

Parameters

s &Slider
The Slider instance used by this call (borrow).

Returns

bool — true or false

($&Slider) painted

XuAPI
pub fn (s $&Slider) painted()

Purpose

Acknowledge the painted frame and clear the dirty flag; this is not a query.

Parameters

s $&Slider
The Slider instance used by this call (exclusive borrow).

Returns

This call does not return a value.

($&Slider) invalidate

XuAPI
pub fn (s $&Slider) invalidate()

Purpose

Invalidate the control area, requesting a repaint on next frame.

Parameters

s $&Slider
The Slider instance used by this call (exclusive borrow).

Returns

This call does not return a value.

($&Slider) cancel

XuAPI
pub fn (s $&Slider) cancel()

Purpose

Execute cancel on $&Slider.

Parameters

s $&Slider
The Slider instance used by this call (exclusive borrow).

Returns

This call does not return a value.

(&Slider) is_enabled

XuAPI
pub fn (s &Slider) is_enabled() bool

Purpose

Return whether the control is currently enabled.

Parameters

s &Slider
The Slider instance used by this call (borrow).

Returns

bool — true or false

($&Slider) set_enabled

XuAPI
pub fn (s $&Slider) set_enabled(enabled bool)

Purpose

Operation on $&Slider: set enabled.

Parameters

s $&Slider
The Slider instance used by this call (exclusive borrow).
enabled bool
enabled (bool)

Returns

This call does not return a value.

(&Slider) is_focused

XuAPI
pub fn (s &Slider) is_focused() bool

Purpose

Return whether the control currently has input focus.

Parameters

s &Slider
The Slider instance used by this call (borrow).

Returns

bool — true or false

($&Slider) set_focus

XuAPI
pub fn (s $&Slider) set_focus(focused bool)

Purpose

Operation on $&Slider: set focus.

Parameters

s $&Slider
The Slider instance used by this call (exclusive borrow).
focused bool
focused (bool)

Returns

This call does not return a value.

(&Slider) is_hovered

XuAPI
pub fn (s &Slider) is_hovered() bool

Purpose

Operation on &Slider: whether it is hovered.

Parameters

s &Slider
The Slider instance used by this call (borrow).

Returns

bool — true or false

(&Slider) is_dragging

XuAPI
pub fn (s &Slider) is_dragging() bool

Purpose

Operation on &Slider: whether it is dragging.

Parameters

s &Slider
The Slider instance used by this call (borrow).

Returns

bool — true or false

(&Slider) is_invalid

XuAPI
pub fn (s &Slider) is_invalid() bool

Purpose

Operation on &Slider: whether it is invalid.

Parameters

s &Slider
The Slider instance used by this call (borrow).

Returns

bool — true or false

($&Slider) set_invalid

XuAPI
pub fn (s $&Slider) set_invalid(invalid bool)

Purpose

Operation on $&Slider: set invalid.

Parameters

s $&Slider
The Slider instance used by this call (exclusive borrow).
invalid bool
invalid (bool)

Returns

This call does not return a value.

(&Slider) is_read_only

XuAPI
pub fn (s &Slider) is_read_only() bool

Purpose

Operation on &Slider: whether it is read only.

Parameters

s &Slider
The Slider instance used by this call (borrow).

Returns

bool — true or false

($&Slider) set_read_only

XuAPI
pub fn (s $&Slider) set_read_only(read_only bool)

Purpose

Operation on $&Slider: set read only.

Parameters

s $&Slider
The Slider instance used by this call (exclusive borrow).
read_only bool
read_only (bool)

Returns

This call does not return a value.

($&Slider) set_value

XuAPI
pub fn (s $&Slider) set_value(value f64) int

Purpose

Set a slider value, constrained by its configured range and step.

Parameters

s $&Slider
The Slider instance used by this call (exclusive borrow).
value f64
Finite value; it is clamped to the range and snapped to the configured step.

Returns

Returns 0 on success; failure throws rather than returning a nonzero status.

Error handling

  • NaN or infinity throws widgets: invalid slider value.

($&Slider) set_range

XuAPI
pub fn (s $&Slider) set_range(min f64,max f64) int

Purpose

Operation on $&Slider: set range. Throws on failure; handle the error or propagate it to the caller.

Parameters

s $&Slider
The Slider instance used by this call (exclusive borrow).
min f64
minimum (f64)
max f64
maximum (f64)

Returns

int — a value of this type

($&Slider) set_step

XuAPI
pub fn (s $&Slider) set_step(step f64) int

Purpose

Operation on $&Slider: set step. Throws on failure; handle the error or propagate it to the caller.

Parameters

s $&Slider
The Slider instance used by this call (exclusive borrow).
step f64
step (f64)

Returns

int — a value of this type

($&Slider) set_bounds

XuAPI
pub fn (s $&Slider) set_bounds(bounds &layout.Rect) int

Purpose

Operation on $&Slider: set bounds. Throws on failure; handle the error or propagate it to the caller.

Parameters

s $&Slider
The Slider instance used by this call (exclusive borrow).
bounds &layout.Rect
bounds (read-only borrow; caller keeps the original; type &layout.Rect)

Returns

int — a value of this type

(&Slider) visual_state

XuAPI
pub fn (s &Slider) visual_state() int

Purpose

Operation on &Slider: visual state.

Parameters

s &Slider
The Slider instance used by this call (borrow).

Returns

int — a value of this type

(&Slider) has_style

XuAPI
pub fn (s &Slider) has_style() bool

Purpose

Operation on &Slider: whether it has style.

Parameters

s &Slider
The Slider instance used by this call (borrow).

Returns

bool — true or false

(&Slider) style_or

XuAPI
pub fn (s &Slider) style_or(styles &Styles) ControlStyle

Purpose

Operation on &Slider: style or.

Parameters

s &Slider
The Slider instance used by this call (borrow).
styles &Styles
styles (read-only borrow; caller keeps the original; type &Styles)

Returns

ControlStyle — a value of this type

($&Slider) set_style

XuAPI
pub fn (s $&Slider) set_style(style &ControlStyle) int

Purpose

Operation on $&Slider: set style. Throws on failure; handle the error or propagate it to the caller.

Parameters

s $&Slider
The Slider instance used by this call (exclusive borrow).
style &ControlStyle
style (read-only borrow; caller keeps the original; type &ControlStyle)

Returns

int — a value of this type

($&Slider) clear_style

XuAPI
pub fn (s $&Slider) clear_style()

Purpose

Operation on $&Slider: clear style.

Parameters

s $&Slider
The Slider instance used by this call (exclusive borrow).

Returns

This call does not return a value.

($&Slider) input

XuAPI
pub fn (s $&Slider) input(input &ui.InputEvent) Action

Purpose

Handle dragging and keyboard adjustments, distinguishing live changes from a final commit.

Parameters

s $&Slider
The Slider instance used by this call (exclusive borrow).
input &ui.InputEvent
Input event for the same window, canvas and generation, with coordinates in the control's canvas space.

Returns

An Action: kind identifies the action, consumed marks a handled event, request_focus requests focus, and needs_paint requests repainting.

Usage notes

  • ACTION_CHANGE reports live changes; ACTION_COMMIT completes an interaction that changed the value. value is current; set_commit_only suppresses live change actions.

($&Slider) event

XuAPI
pub fn (s $&Slider) event(event &ui.Event) Action

Purpose

Handle and respond to window or system lifecycle and interaction events. Throws on failure; handle the error or propagate it to the caller.

Parameters

s $&Slider
The Slider instance used by this call (exclusive borrow).
event &ui.Event
event (read-only borrow; caller keeps the original; type &ui.Event)

Returns

Action — input result with kind, id, repaint and focus requests.

(&Slider) paint

XuAPI
pub fn (s &Slider) paint(frame $&draw.Frame,theme &Theme) int

Purpose

Paint the control visually onto the target canvas. Throws on failure; handle the error or propagate it to the caller.

Parameters

s &Slider
The Slider instance used by this call (borrow).
frame $&draw.Frame
frame (exclusive borrow; may modify the original; type $&draw.Frame)
theme &Theme
theme (read-only borrow; caller keeps the original; type &Theme)

Returns

int — a value of this type

(&Slider) measure_styled

XuAPI
pub fn (s &Slider) measure_styled(styles &Styles) layout.Size

Purpose

Operation on &Slider: measure styled.

Parameters

s &Slider
The Slider instance used by this call (borrow).
styles &Styles
styles (read-only borrow; caller keeps the original; type &Styles)

Returns

layout.Size — a value of this type

(&Slider) paint_styled

XuAPI
pub fn (s &Slider) paint_styled(frame $&draw.Frame,styles &Styles) int

Purpose

Operation on &Slider: paint styled. Throws on failure; handle the error or propagate it to the caller.

Parameters

s &Slider
The Slider instance used by this call (borrow).
frame $&draw.Frame
frame (exclusive borrow; may modify the original; type $&draw.Frame)
styles &Styles
styles (read-only borrow; caller keeps the original; type &Styles)

Returns

int — a value of this type

($&Slider) set_commit_only

XuAPI
pub fn (s $&Slider) set_commit_only(enabled bool)

Purpose

Emit only final commit actions when applying changes is expensive.

Parameters

s $&Slider
The Slider instance used by this call (exclusive borrow).
enabled bool
true suppresses live ACTION_CHANGE while retaining the final ACTION_COMMIT.

Returns

No return value; setting this clears the current pending-commit flag.

Usage notes

  • The displayed value still updates during dragging; apply expensive work when handling the commit action.

($&Slider) apply_styles

XuAPI
pub fn (s $&Slider) apply_styles(styles &Styles) int

Purpose

Resolve and apply theme metrics to the control. Throws on failure; handle the error or propagate it to the caller.

Parameters

s $&Slider
The Slider instance used by this call (exclusive borrow).
styles &Styles
styles (read-only borrow; caller keeps the original; type &Styles)

Returns

int — a value of this type

($&Slider) set_appearance

XuAPI
pub fn (s $&Slider) set_appearance(appearance &SliderAppearance) int

Purpose

Operation on $&Slider: set appearance. Throws on failure; handle the error or propagate it to the caller.

Parameters

s $&Slider
The Slider instance used by this call (exclusive borrow).
appearance &SliderAppearance
appearance (read-only borrow; caller keeps the original; type &SliderAppearance)

Returns

int — a value of this type

(&Slider) shows_value

XuAPI
pub fn (s &Slider) shows_value() bool

Purpose

Operation on &Slider: shows value.

Parameters

s &Slider
The Slider instance used by this call (borrow).

Returns

bool — true or false

(&Slider) value_text

XuAPI
pub fn (s &Slider) value_text() string

Purpose

Operation on &Slider: value text. Throws on failure; handle the error or propagate it to the caller.

Parameters

s &Slider
The Slider instance used by this call (borrow).

Returns

string — result string

(&Slider) paint_value_styled

XuAPI
pub fn (s &Slider) paint_value_styled(frame $&draw.Frame,label $&StyledLabel,styles &Styles) int

Purpose

Operation on &Slider: paint value styled. Throws on failure; handle the error or propagate it to the caller.

Parameters

s &Slider
The Slider instance used by this call (borrow).
frame $&draw.Frame
frame (exclusive borrow; may modify the original; type $&draw.Frame)
label $&StyledLabel
label (exclusive borrow; may modify the original; type $&StyledLabel)
styles &Styles
styles (read-only borrow; caller keeps the original; type &Styles)

Returns

int — a value of this type

($&Slider) route

XuAPI
pub fn (s $&Slider) route(kind int,input &ui.InputEvent) Action

Purpose

Route and dispatch the input event to matching targets. Throws on failure; handle the error or propagate it to the caller.

Parameters

s $&Slider
The Slider instance used by this call (exclusive borrow).
kind int
kind tag (int)
input &ui.InputEvent
input (read-only borrow; caller keeps the original; type &ui.InputEvent)

Returns

Action — input result with kind, id, repaint and focus requests.

Complete native example

Component Workshop · Back to Widgets