UI / WIDGETS / Feedback
Spinner
Indicate work with an unknown duration
Run the Xu example ↗The example executes in the browser using the Xu/WASM runtime.
What to try
Start or pause the loading indicator.
Usage notes
Indicate waiting without promising a completion percentage. Add a description of the work and stop when it completes or is cancelled.
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.spinner() or >>
screen.place(id,24.0,24.0,320.0,80.0) or >>
<< id
}
($&Screen) spinner
pub fn (s $&Screen) spinner() int
Purpose
Create Spinner in Screen and return the component node ID; throw on creation failure.
Parameters
s $&Screen- The
Screen instance used by this call (exclusive borrow).
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.
struct Spinner
Purpose
Spinner context or state structure.
Public fields
This type has no public fields.
(&Spinner) is_running
pub fn (spinner &Spinner) is_running() bool
Purpose
Operation on &Spinner: whether it is running.
Parameters
spinner &Spinner- The
Spinner instance used by this call (borrow).
Returns
bool — true or false
(&Spinner) needs_paint
pub fn (spinner &Spinner) needs_paint() bool
Purpose
Return whether the control needs repainting; call painted after painting to clear the flag.
Parameters
spinner &Spinner- The
Spinner instance used by this call (borrow).
Returns
bool — true or false
(&Spinner) bounds
pub fn (spinner &Spinner) bounds() layout.Rect
Purpose
Return the bounding Rectangle of the control or geometry.
Parameters
spinner &Spinner- The
Spinner instance used by this call (borrow).
Returns
layout.Rect — a value of this type
($&Spinner) set_bounds
pub fn (spinner $&Spinner) set_bounds(bounds &layout.Rect) int
Purpose
Operation on $&Spinner: set bounds. Throws on failure; handle the error or propagate it to the caller.
Parameters
spinner $&Spinner- The
Spinner 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
($&Spinner) set_running
pub fn (spinner $&Spinner) set_running(running bool)
Purpose
Operation on $&Spinner: set running.
Parameters
spinner $&Spinner- The
Spinner instance used by this call (exclusive borrow).
running bool- running (bool)
Returns
This call does not return a value.
($&Spinner) set_enabled
pub fn (spinner $&Spinner) set_enabled(enabled bool)
Purpose
Operation on $&Spinner: set enabled.
Parameters
spinner $&Spinner- The
Spinner instance used by this call (exclusive borrow).
enabled bool- enabled (bool)
Returns
This call does not return a value.
($&Spinner) set_style
pub fn (spinner $&Spinner) set_style(style &ControlStyle) int
Purpose
Operation on $&Spinner: set style. Throws on failure; handle the error or propagate it to the caller.
Parameters
spinner $&Spinner- The
Spinner 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
(&Spinner) style_or
pub fn (spinner &Spinner) style_or(styles &Styles) ControlStyle
Purpose
Operation on &Spinner: style or.
Parameters
spinner &Spinner- The
Spinner 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
($&Spinner) tick
pub fn (spinner $&Spinner) tick(now time.Instant,reduced_motion bool) bool
Purpose
Advance animation clock and state transition step. Throws on failure; handle the error or propagate it to the caller.
Parameters
spinner $&Spinner- The
Spinner instance used by this call (exclusive borrow).
now time.Instant- now (time.Instant)
reduced_motion bool- reduced_motion (bool)
Returns
bool — true or false
(&Spinner) next_tick
pub fn (spinner &Spinner) next_tick(now time.Instant,reduced_motion bool) time.Instant
Purpose
Operation on &Spinner: next tick. Throws on failure; handle the error or propagate it to the caller.
Parameters
spinner &Spinner- The
Spinner instance used by this call (borrow).
now time.Instant- now (time.Instant)
reduced_motion bool- reduced_motion (bool)
Returns
time.Instant — a value of this type
(&Spinner) measure_styled
pub fn (spinner &Spinner) measure_styled(styles &Styles) layout.Size
Purpose
Operation on &Spinner: measure styled. Throws on failure; handle the error or propagate it to the caller.
Parameters
spinner &Spinner- The
Spinner 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
($&Spinner) paint_styled
pub fn (spinner $&Spinner) paint_styled(frame $&draw.Frame,styles &Styles) int
Purpose
Operation on $&Spinner: paint styled. Throws on failure; handle the error or propagate it to the caller.
Parameters
spinner $&Spinner- The
Spinner instance used by this call (exclusive 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
($&Spinner) set_appearance
pub fn (spinner $&Spinner) set_appearance(diameter f64,thickness f64,period time.Duration) int
Purpose
Operation on $&Spinner: set appearance. Throws on failure; handle the error or propagate it to the caller.
Parameters
spinner $&Spinner- The
Spinner instance used by this call (exclusive borrow).
diameter f64- diameter (f64)
thickness f64- thickness (f64)
period time.Duration- period (time.Duration)
Returns
int — a value of this type
Complete native example
Component Workshop · Back to Widgets