XU XUv0.13.1
中文

UI / WIDGETS / Selection

RadioGroup

Manage a related group of choices

Run the Xu example

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

What to try

Switch options and observe the current choice.

Usage notes

Keep options focused on one question. Separate the selected value from its displayed label and choose the initial selection at creation.

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 {
    options := ["Design","Develop","Review"]
    id := screen.radio_group(&options,0) or >>
    screen.place(id,24.0,24.0,320.0,80.0) or >>
    << id
}

($&Screen) radio_group

XuAPI
pub fn (s $&Screen) radio_group(options &[]string,selected int) int

Purpose

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

Parameters

s $&Screen
The Screen instance used by this call (exclusive borrow).
options &[]string
options (read-only borrow; caller keeps the original; type &[]string)
selected int
selected (int)

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 RadioGroup

XuAPI
pub struct RadioGroup {

}

Purpose

One focus stop owns the selection and arrow-key navigation for the group.

Public fields

This type has no public fields.

(&RadioGroup) id

XuAPI
pub fn (g &RadioGroup) id() int

Purpose

Return the unique integer ID of the element or control.

Parameters

g &RadioGroup
The RadioGroup instance used by this call (borrow).

Returns

int — a value of this type

(&RadioGroup) bounds

XuAPI
pub fn (g &RadioGroup) bounds() layout.Rect

Purpose

Return the bounding Rectangle of the control or geometry.

Parameters

g &RadioGroup
The RadioGroup instance used by this call (borrow).

Returns

layout.Rect — a value of this type

(&RadioGroup) count

XuAPI
pub fn (g &RadioGroup) count() int

Purpose

Return the number of items in this control.

Parameters

g &RadioGroup
The RadioGroup instance used by this call (borrow).

Returns

int — a value of this type

(&RadioGroup) selected

XuAPI
pub fn (g &RadioGroup) selected() int

Purpose

Get or test the currently selected index, node, or state.

Parameters

g &RadioGroup
The RadioGroup instance used by this call (borrow).

Returns

int — a value of this type

(&RadioGroup) needs_paint

XuAPI
pub fn (g &RadioGroup) needs_paint() bool

Purpose

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

Parameters

g &RadioGroup
The RadioGroup instance used by this call (borrow).

Returns

bool — true or false

(&RadioGroup) is_enabled

XuAPI
pub fn (g &RadioGroup) is_enabled() bool

Purpose

Return whether the control is currently enabled.

Parameters

g &RadioGroup
The RadioGroup instance used by this call (borrow).

Returns

bool — true or false

(&RadioGroup) is_selectable

XuAPI
pub fn (g &RadioGroup) is_selectable() bool

Purpose

Operation on &RadioGroup: whether it is selectable.

Parameters

g &RadioGroup
The RadioGroup instance used by this call (borrow).

Returns

bool — true or false

($&RadioGroup) set_selectable

XuAPI
pub fn (g $&RadioGroup) set_selectable(selectable bool)

Purpose

Operation on $&RadioGroup: set selectable.

Parameters

g $&RadioGroup
The RadioGroup instance used by this call (exclusive borrow).
selectable bool
selectable (bool)

Returns

This call does not return a value.

(&RadioGroup) is_focused

XuAPI
pub fn (g &RadioGroup) is_focused() bool

Purpose

Return whether the control currently has input focus.

Parameters

g &RadioGroup
The RadioGroup instance used by this call (borrow).

Returns

bool — true or false

($&RadioGroup) set_horizontal

XuAPI
pub fn (g $&RadioGroup) set_horizontal(horizontal bool)

Purpose

Operation on $&RadioGroup: set horizontal.

Parameters

g $&RadioGroup
The RadioGroup instance used by this call (exclusive borrow).
horizontal bool
horizontal (bool)

Returns

This call does not return a value.

($&RadioGroup) set_focus

XuAPI
pub fn (g $&RadioGroup) set_focus(focused bool)

Purpose

Operation on $&RadioGroup: set focus.

Parameters

g $&RadioGroup
The RadioGroup instance used by this call (exclusive borrow).
focused bool
focused (bool)

Returns

This call does not return a value.

($&RadioGroup) set_enabled

XuAPI
pub fn (g $&RadioGroup) set_enabled(enabled bool)

Purpose

Operation on $&RadioGroup: set enabled.

Parameters

g $&RadioGroup
The RadioGroup instance used by this call (exclusive borrow).
enabled bool
enabled (bool)

Returns

This call does not return a value.

($&RadioGroup) set_read_only

XuAPI
pub fn (g $&RadioGroup) set_read_only(value bool)

Purpose

Operation on $&RadioGroup: set read only.

Parameters

g $&RadioGroup
The RadioGroup instance used by this call (exclusive borrow).
value bool
value (bool)

Returns

This call does not return a value.

($&RadioGroup) set_selected

XuAPI
pub fn (g $&RadioGroup) set_selected(index int) int

Purpose

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

Parameters

g $&RadioGroup
The RadioGroup instance used by this call (exclusive borrow).
index int
index (int)

Returns

int — a value of this type

($&RadioGroup) set_bounds

XuAPI
pub fn (g $&RadioGroup) set_bounds(bounds &layout.Rect) int

Purpose

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

Parameters

g $&RadioGroup
The RadioGroup 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

(&RadioGroup) style_or

XuAPI
pub fn (g &RadioGroup) style_or(styles &Styles) ControlStyle

Purpose

Operation on &RadioGroup: style or.

Parameters

g &RadioGroup
The RadioGroup 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

($&RadioGroup) set_style

XuAPI
pub fn (g $&RadioGroup) set_style(style &ControlStyle) int

Purpose

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

Parameters

g $&RadioGroup
The RadioGroup 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

($&RadioGroup) painted

XuAPI
pub fn (g $&RadioGroup) painted()

Purpose

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

Parameters

g $&RadioGroup
The RadioGroup instance used by this call (exclusive borrow).

Returns

This call does not return a value.

($&RadioGroup) cancel

XuAPI
pub fn (g $&RadioGroup) cancel()

Purpose

Execute cancel on $&RadioGroup.

Parameters

g $&RadioGroup
The RadioGroup instance used by this call (exclusive borrow).

Returns

This call does not return a value.

(&RadioGroup) item_bounds

XuAPI
pub fn (g &RadioGroup) item_bounds(index int) layout.Rect

Purpose

Operation on &RadioGroup: item bounds. Throws on failure; handle the error or propagate it to the caller.

Parameters

g &RadioGroup
The RadioGroup instance used by this call (borrow).
index int
index (int)

Returns

layout.Rect — a value of this type

($&RadioGroup) input

XuAPI
pub fn (g $&RadioGroup) input(event &ui.InputEvent) Action

Purpose

Process routed mouse, keyboard, or touch input events. Throws on failure; handle the error or propagate it to the caller.

Parameters

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

Returns

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

($&RadioGroup) route

XuAPI
pub fn (g $&RadioGroup) route(kind int,event &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

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

Returns

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

($&RadioGroup) measure_styled

XuAPI
pub fn (g $&RadioGroup) measure_styled(styles &Styles) layout.Size

Purpose

Operation on $&RadioGroup: measure styled. Throws on failure; handle the error or propagate it to the caller.

Parameters

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

Returns

layout.Size — a value of this type

($&RadioGroup) paint_styled

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

Purpose

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

Parameters

g $&RadioGroup
The RadioGroup 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

($&RadioGroup) dispose

XuAPI
pub fn (g $&RadioGroup) dispose()

Purpose

Release and dispose native resources and underlying handles.

Parameters

g $&RadioGroup
The RadioGroup instance used by this call (exclusive borrow).

Returns

This call does not return a value.

Complete native example

Component Workshop · Back to Widgets