What to try
Activate the radio control and observe its selected state.
Usage notes
A Radio represents one item in an exclusive choice. Coordinate its peers through the application or RadioGroup so multiple items cannot stay selected.
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.radio("Stable",1,true) or >>
screen.place(id,24.0,24.0,320.0,80.0) or >>
<< id
}
($&Screen) radio
pub fn (s $&Screen) radio(text string,option int,checked bool) int
Purpose
Create Radio in Screen and return the component node ID; throw on creation failure.
Parameters
s $&Screen- The
Screen instance used by this call (exclusive borrow).
text string- text (string)
option int- option (int)
checked bool- checked (bool)
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.
(&Radio) clone
pub fn (r &Radio) clone() Radio
Purpose
Copy the control or style snapshot into an independent Radio value.
Parameters
r &Radio- The
Radio instance used by this call (borrow).
Returns
Radio — a value of this type
struct Radio
Purpose
Radio context or state structure.
Public fields
This type has no public fields.
See usage example
(&Radio) id
pub fn (r &Radio) id() int
Purpose
Return the unique integer ID of the element or control.
Parameters
r &Radio- The
Radio instance used by this call (borrow).
Returns
int — a value of this type
(&Radio) bounds
pub fn (r &Radio) bounds() layout.Rect
Purpose
Return the bounding Rectangle of the control or geometry.
Parameters
r &Radio- The
Radio instance used by this call (borrow).
Returns
layout.Rect — a value of this type
(&Radio) option
pub fn (r &Radio) option() int
Purpose
Execute option on &Radio.
Parameters
r &Radio- The
Radio instance used by this call (borrow).
Returns
int — a value of this type
(&Radio) value
pub fn (r &Radio) value() bool
Purpose
Execute value on &Radio.
Parameters
r &Radio- The
Radio instance used by this call (borrow).
Returns
bool — true or false
($&Radio) set_value
pub fn (r $&Radio) set_value(selected bool)
Purpose
Operation on $&Radio: set value.
Parameters
r $&Radio- The
Radio instance used by this call (exclusive borrow).
selected bool- selected (bool)
Returns
This call does not return a value.
(&Radio) needs_paint
pub fn (r &Radio) needs_paint() bool
Purpose
Return whether the control needs repainting; call painted after painting to clear the flag.
Parameters
r &Radio- The
Radio instance used by this call (borrow).
Returns
bool — true or false
($&Radio) painted
pub fn (r $&Radio) painted()
Purpose
Acknowledge the painted frame and clear the dirty flag; this is not a query.
Parameters
r $&Radio- The
Radio instance used by this call (exclusive borrow).
Returns
This call does not return a value.
($&Radio) invalidate
pub fn (r $&Radio) invalidate()
Purpose
Invalidate the control area, requesting a repaint on next frame.
Parameters
r $&Radio- The
Radio instance used by this call (exclusive borrow).
Returns
This call does not return a value.
($&Radio) cancel
pub fn (r $&Radio) cancel()
Purpose
Execute cancel on $&Radio.
Parameters
r $&Radio- The
Radio instance used by this call (exclusive borrow).
Returns
This call does not return a value.
(&Radio) is_enabled
pub fn (r &Radio) is_enabled() bool
Purpose
Return whether the control is currently enabled.
Parameters
r &Radio- The
Radio instance used by this call (borrow).
Returns
bool — true or false
(&Radio) is_selectable
pub fn (r &Radio) is_selectable() bool
Purpose
Operation on &Radio: whether it is selectable.
Parameters
r &Radio- The
Radio instance used by this call (borrow).
Returns
bool — true or false
($&Radio) set_selectable
pub fn (r $&Radio) set_selectable(selectable bool)
Purpose
Operation on $&Radio: set selectable.
Parameters
r $&Radio- The
Radio instance used by this call (exclusive borrow).
selectable bool- selectable (bool)
Returns
This call does not return a value.
($&Radio) set_enabled
pub fn (r $&Radio) set_enabled(enabled bool)
Purpose
Operation on $&Radio: set enabled.
Parameters
r $&Radio- The
Radio instance used by this call (exclusive borrow).
enabled bool- enabled (bool)
Returns
This call does not return a value.
(&Radio) is_focused
pub fn (r &Radio) is_focused() bool
Purpose
Return whether the control currently has input focus.
Parameters
r &Radio- The
Radio instance used by this call (borrow).
Returns
bool — true or false
($&Radio) set_focus
pub fn (r $&Radio) set_focus(focused bool)
Purpose
Operation on $&Radio: set focus.
Parameters
r $&Radio- The
Radio instance used by this call (exclusive borrow).
focused bool- focused (bool)
Returns
This call does not return a value.
(&Radio) is_hovered
pub fn (r &Radio) is_hovered() bool
Purpose
Operation on &Radio: whether it is hovered.
Parameters
r &Radio- The
Radio instance used by this call (borrow).
Returns
bool — true or false
(&Radio) is_pressed
pub fn (r &Radio) is_pressed() bool
Purpose
Operation on &Radio: whether it is pressed.
Parameters
r &Radio- The
Radio instance used by this call (borrow).
Returns
bool — true or false
(&Radio) is_invalid
pub fn (r &Radio) is_invalid() bool
Purpose
Operation on &Radio: whether it is invalid.
Parameters
r &Radio- The
Radio instance used by this call (borrow).
Returns
bool — true or false
($&Radio) set_invalid
pub fn (r $&Radio) set_invalid(invalid bool)
Purpose
Operation on $&Radio: set invalid.
Parameters
r $&Radio- The
Radio instance used by this call (exclusive borrow).
invalid bool- invalid (bool)
Returns
This call does not return a value.
(&Radio) is_read_only
pub fn (r &Radio) is_read_only() bool
Purpose
Operation on &Radio: whether it is read only.
Parameters
r &Radio- The
Radio instance used by this call (borrow).
Returns
bool — true or false
($&Radio) set_read_only
pub fn (r $&Radio) set_read_only(read_only bool)
Purpose
Operation on $&Radio: set read only.
Parameters
r $&Radio- The
Radio instance used by this call (exclusive borrow).
read_only bool- read_only (bool)
Returns
This call does not return a value.
($&Radio) set_bounds
pub fn (r $&Radio) set_bounds(bounds &layout.Rect) int
Purpose
Operation on $&Radio: set bounds. Throws on failure; handle the error or propagate it to the caller.
Parameters
r $&Radio- The
Radio 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
(&Radio) visual_state
pub fn (r &Radio) visual_state() int
Purpose
Operation on &Radio: visual state.
Parameters
r &Radio- The
Radio instance used by this call (borrow).
Returns
int — a value of this type
(&Radio) has_style
pub fn (r &Radio) has_style() bool
Purpose
Operation on &Radio: whether it has style.
Parameters
r &Radio- The
Radio instance used by this call (borrow).
Returns
bool — true or false
(&Radio) style_or
pub fn (r &Radio) style_or(styles &Styles) ControlStyle
Purpose
Operation on &Radio: style or.
Parameters
r &Radio- The
Radio 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
($&Radio) set_style
pub fn (r $&Radio) set_style(style &ControlStyle) int
Purpose
Operation on $&Radio: set style. Throws on failure; handle the error or propagate it to the caller.
Parameters
r $&Radio- The
Radio 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
($&Radio) clear_style
pub fn (r $&Radio) clear_style()
Purpose
Operation on $&Radio: clear style.
Parameters
r $&Radio- The
Radio instance used by this call (exclusive borrow).
Returns
This call does not return a value.
($&Radio) input
pub fn (r $&Radio) input(input &ui.InputEvent) Action
Purpose
Process routed mouse, keyboard, or touch input events.
Parameters
r $&Radio- The
Radio instance used by this call (exclusive borrow).
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.
($&Radio) event
pub fn (r $&Radio) 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
r $&Radio- The
Radio 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.
(&Radio) paint
pub fn (r &Radio) paint(frame $&draw.Frame,label &draw.TextLayout,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
r &Radio- The
Radio instance used by this call (borrow).
frame $&draw.Frame- frame (exclusive borrow; may modify the original; type $&draw.Frame)
label &draw.TextLayout- label (read-only borrow; caller keeps the original; type &draw.TextLayout)
theme &Theme- theme (read-only borrow; caller keeps the original; type &Theme)
Returns
int — a value of this type
(&Radio) measure_styled
pub fn (r &Radio) measure_styled(label $&StyledLabel,styles &Styles) layout.Size
Purpose
Operation on &Radio: measure styled. Throws on failure; handle the error or propagate it to the caller.
Parameters
r &Radio- The
Radio instance used by this call (borrow).
label $&StyledLabel- label (exclusive borrow; may modify the original; type $&StyledLabel)
styles &Styles- styles (read-only borrow; caller keeps the original; type &Styles)
Returns
layout.Size — a value of this type
(&Radio) paint_styled
pub fn (r &Radio) paint_styled(frame $&draw.Frame,label $&StyledLabel,styles &Styles) int
Purpose
Operation on &Radio: paint styled. Throws on failure; handle the error or propagate it to the caller.
Parameters
r &Radio- The
Radio 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
($&Radio) set_motion
pub fn (control $&Radio) set_motion(spec &MotionSpec) int
Purpose
Operation on $&Radio: set motion. Throws on failure; handle the error or propagate it to the caller.
Parameters
control $&Radio- The
Radio instance used by this call (exclusive borrow).
spec &MotionSpec- spec (read-only borrow; caller keeps the original; type &MotionSpec)
Returns
int — a value of this type
($&Radio) tick
pub fn (control $&Radio) tick(now time.Instant,reduced bool) bool
Purpose
Advance animation clock and state transition step. Throws on failure; handle the error or propagate it to the caller.
Parameters
control $&Radio- The
Radio instance used by this call (exclusive borrow).
now time.Instant- now (time.Instant)
reduced bool- reduced (bool)
Returns
bool — true or false
(&Radio) next_tick
pub fn (control &Radio) next_tick(now time.Instant) time.Instant
Purpose
Operation on &Radio: next tick. Throws on failure; handle the error or propagate it to the caller.
Parameters
control &Radio- The
Radio instance used by this call (borrow).
now time.Instant- now (time.Instant)
Returns
time.Instant — a value of this type
($&Radio) route
pub fn (r $&Radio) 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
r $&Radio- The
Radio 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