XU XUv0.13.1
中文

UI / WIDGETS / Selection

Select

Pick one option from a fixed set

Run the Xu example

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

What to try

Open the options, or use arrow keys after focusing the control, to change the selection.

Usage notes

Options come from a fixed set. Use option metadata for groups and disabled items; group headings are not selectable values.

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.select_box(&options,0) or >>
    screen.place(id,24.0,24.0,320.0,80.0) or >>
    << id
}

($&Screen) select_box

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

Purpose

Create Select 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.

(&Select) clone

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

Purpose

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

Parameters

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

Returns

Select — a value of this type

struct Select

XuAPI
pub struct Select {

}

Purpose

Select context or state structure.

Public fields

This type has no public fields.

See usage example

(&Select) is_selectable

XuAPI
pub fn (sel &Select) is_selectable() bool

Purpose

Operation on &Select: whether it is selectable.

Parameters

sel &Select
The Select instance used by this call (borrow).

Returns

bool — true or false

($&Select) set_selectable

XuAPI
pub fn (sel $&Select) set_selectable(selectable bool)

Purpose

Operation on $&Select: set selectable.

Parameters

sel $&Select
The Select instance used by this call (exclusive borrow).
selectable bool
selectable (bool)

Returns

This call does not return a value.

(&Select) id

XuAPI
pub fn (sel &Select) id() int

Purpose

Return the unique integer ID of the element or control.

Parameters

sel &Select
The Select instance used by this call (borrow).

Returns

int — a value of this type

(&Select) bounds

XuAPI
pub fn (sel &Select) bounds() layout.Rect

Purpose

Return the bounding Rectangle of the control or geometry.

Parameters

sel &Select
The Select instance used by this call (borrow).

Returns

layout.Rect — a value of this type

(&Select) count

XuAPI
pub fn (sel &Select) count() int

Purpose

Return the number of items in this control.

Parameters

sel &Select
The Select instance used by this call (borrow).

Returns

int — a value of this type

(&Select) selected

XuAPI
pub fn (sel &Select) selected() int

Purpose

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

Parameters

sel &Select
The Select instance used by this call (borrow).

Returns

int — a value of this type

(&Select) is_open

XuAPI
pub fn (sel &Select) is_open() bool

Purpose

Return whether the overlay, menu or dialog is currently open.

Parameters

sel &Select
The Select instance used by this call (borrow).

Returns

bool — true or false

(&Select) hovered_option

XuAPI
pub fn (sel &Select) hovered_option() int

Purpose

Return the hovered option index, or -1 when no option is hovered.

Parameters

sel &Select
The Select instance used by this call (borrow).

Returns

int — a value of this type

(&Select) needs_paint

XuAPI
pub fn (sel &Select) needs_paint() bool

Purpose

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

Parameters

sel &Select
The Select instance used by this call (borrow).

Returns

bool — true or false

($&Select) painted

XuAPI
pub fn (sel $&Select) painted()

Purpose

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

Parameters

sel $&Select
The Select instance used by this call (exclusive borrow).

Returns

This call does not return a value.

($&Select) invalidate

XuAPI
pub fn (sel $&Select) invalidate()

Purpose

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

Parameters

sel $&Select
The Select instance used by this call (exclusive borrow).

Returns

This call does not return a value.

($&Select) cancel

XuAPI
pub fn (sel $&Select) cancel()

Purpose

Execute cancel on $&Select.

Parameters

sel $&Select
The Select instance used by this call (exclusive borrow).

Returns

This call does not return a value.

(&Select) is_enabled

XuAPI
pub fn (sel &Select) is_enabled() bool

Purpose

Return whether the control is currently enabled.

Parameters

sel &Select
The Select instance used by this call (borrow).

Returns

bool — true or false

($&Select) set_enabled

XuAPI
pub fn (sel $&Select) set_enabled(enabled bool)

Purpose

Operation on $&Select: set enabled.

Parameters

sel $&Select
The Select instance used by this call (exclusive borrow).
enabled bool
enabled (bool)

Returns

This call does not return a value.

(&Select) is_focused

XuAPI
pub fn (sel &Select) is_focused() bool

Purpose

Return whether the control currently has input focus.

Parameters

sel &Select
The Select instance used by this call (borrow).

Returns

bool — true or false

($&Select) set_focus

XuAPI
pub fn (sel $&Select) set_focus(focused bool)

Purpose

Operation on $&Select: set focus.

Parameters

sel $&Select
The Select instance used by this call (exclusive borrow).
focused bool
focused (bool)

Returns

This call does not return a value.

(&Select) is_hovered

XuAPI
pub fn (sel &Select) is_hovered() bool

Purpose

Operation on &Select: whether it is hovered.

Parameters

sel &Select
The Select instance used by this call (borrow).

Returns

bool — true or false

(&Select) is_invalid

XuAPI
pub fn (sel &Select) is_invalid() bool

Purpose

Operation on &Select: whether it is invalid.

Parameters

sel &Select
The Select instance used by this call (borrow).

Returns

bool — true or false

($&Select) set_invalid

XuAPI
pub fn (sel $&Select) set_invalid(invalid bool)

Purpose

Operation on $&Select: set invalid.

Parameters

sel $&Select
The Select instance used by this call (exclusive borrow).
invalid bool
invalid (bool)

Returns

This call does not return a value.

(&Select) is_read_only

XuAPI
pub fn (sel &Select) is_read_only() bool

Purpose

Operation on &Select: whether it is read only.

Parameters

sel &Select
The Select instance used by this call (borrow).

Returns

bool — true or false

($&Select) set_read_only

XuAPI
pub fn (sel $&Select) set_read_only(read_only bool)

Purpose

Operation on $&Select: set read only.

Parameters

sel $&Select
The Select instance used by this call (exclusive borrow).
read_only bool
read_only (bool)

Returns

This call does not return a value.

($&Select) set_open

XuAPI
pub fn (sel $&Select) set_open(open bool)

Purpose

Operation on $&Select: set open.

Parameters

sel $&Select
The Select instance used by this call (exclusive borrow).
open bool
open (bool)

Returns

This call does not return a value.

($&Select) set_count

XuAPI
pub fn (sel $&Select) set_count(count int) int

Purpose

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

Parameters

sel $&Select
The Select instance used by this call (exclusive borrow).
count int
count (int)

Returns

int — a value of this type

($&Select) set_selected

XuAPI
pub fn (sel $&Select) set_selected(index int) int

Purpose

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

Parameters

sel $&Select
The Select instance used by this call (exclusive borrow).
index int
index (int)

Returns

int — a value of this type

($&Select) set_bounds

XuAPI
pub fn (sel $&Select) set_bounds(bounds &layout.Rect) int

Purpose

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

Parameters

sel $&Select
The Select 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

(&Select) visual_state

XuAPI
pub fn (sel &Select) visual_state() int

Purpose

Operation on &Select: visual state.

Parameters

sel &Select
The Select instance used by this call (borrow).

Returns

int — a value of this type

(&Select) has_style

XuAPI
pub fn (sel &Select) has_style() bool

Purpose

Operation on &Select: whether it has style.

Parameters

sel &Select
The Select instance used by this call (borrow).

Returns

bool — true or false

(&Select) style_or

XuAPI
pub fn (sel &Select) style_or(styles &Styles) ControlStyle

Purpose

Operation on &Select: style or.

Parameters

sel &Select
The Select 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

($&Select) set_style

XuAPI
pub fn (sel $&Select) set_style(style &ControlStyle) int

Purpose

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

Parameters

sel $&Select
The Select 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

($&Select) clear_style

XuAPI
pub fn (sel $&Select) clear_style()

Purpose

Operation on $&Select: clear style.

Parameters

sel $&Select
The Select instance used by this call (exclusive borrow).

Returns

This call does not return a value.

(&Select) popup_bounds

XuAPI
pub fn (sel &Select) popup_bounds(styles &Styles) layout.Rect

Purpose

Operation on &Select: popup bounds.

Parameters

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

Returns

layout.Rect — a value of this type

($&Select) set_popup_above

XuAPI
pub fn (sel $&Select) set_popup_above(above bool)

Purpose

Operation on $&Select: set popup above.

Parameters

sel $&Select
The Select instance used by this call (exclusive borrow).
above bool
above (bool)

Returns

This call does not return a value.

($&Select) apply_styles

XuAPI
pub fn (sel $&Select) apply_styles(styles &Styles) int

Purpose

Keep the input geometry synchronized with popup_bounds/option_bounds. Throws on failure; handle the error or propagate it to the caller.

Parameters

sel $&Select
The Select 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

(&Select) option_bounds

XuAPI
pub fn (sel &Select) option_bounds(index int,styles &Styles) layout.Rect

Purpose

Operation on &Select: option bounds.

Parameters

sel &Select
The Select instance used by this call (borrow).
index int
index (int)
styles &Styles
styles (read-only borrow; caller keeps the original; type &Styles)

Returns

layout.Rect — a value of this type

($&Select) input

XuAPI
pub fn (sel $&Select) input(input &ui.InputEvent) Action

Purpose

Process routed mouse, keyboard, or touch input events.

Parameters

sel $&Select
The Select 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.

($&Select) event

XuAPI
pub fn (sel $&Select) 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

sel $&Select
The Select 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.

(&Select) paint

XuAPI
pub fn (sel &Select) paint(frame $&draw.Frame,labels &[]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

sel &Select
The Select instance used by this call (borrow).
frame $&draw.Frame
frame (exclusive borrow; may modify the original; type $&draw.Frame)
labels &[]draw.TextLayout
labels (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

(&Select) measure_styled

XuAPI
pub fn (sel &Select) measure_styled(label $&StyledLabel,styles &Styles) layout.Size

Purpose

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

Parameters

sel &Select
The Select 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

(&Select) paint_styled

XuAPI
pub fn (sel &Select) paint_styled(frame $&draw.Frame,label $&StyledLabel,styles &Styles) int

Purpose

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

Parameters

sel &Select
The Select 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

(&Select) paint_popup_box_styled

XuAPI
pub fn (sel &Select) paint_popup_box_styled(frame $&draw.Frame,styles &Styles) int

Purpose

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

Parameters

sel &Select
The Select 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

(&Select) paint_option_styled

XuAPI
pub fn (sel &Select) paint_option_styled(frame $&draw.Frame,index int,label $&StyledLabel,styles &Styles) int

Purpose

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

Parameters

sel &Select
The Select instance used by this call (borrow).
frame $&draw.Frame
frame (exclusive borrow; may modify the original; type $&draw.Frame)
index int
index (int)
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

(&Select) paint_popup_styled

XuAPI
pub fn (sel &Select) paint_popup_styled(frame $&draw.Frame,label $&StyledLabel,styles &Styles) int

Purpose

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

Parameters

sel &Select
The Select 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

($&Select) set_option_enabled

XuAPI
pub fn (sel $&Select) set_option_enabled(index int,enabled bool) int

Purpose

Operation on $&Select: set option enabled. Throws on failure; handle the error or propagate it to the caller.

Parameters

sel $&Select
The Select instance used by this call (exclusive borrow).
index int
index (int)
enabled bool
enabled (bool)

Returns

int — a value of this type

($&Select) set_popup_rows

XuAPI
pub fn (sel $&Select) set_popup_rows(rows int) int

Purpose

Operation on $&Select: set popup rows. Throws on failure; handle the error or propagate it to the caller.

Parameters

sel $&Select
The Select instance used by this call (exclusive borrow).
rows int
rows (int)

Returns

int — a value of this type

($&Select) set_option_group

XuAPI
pub fn (sel $&Select) set_option_group(index int,group bool) int

Purpose

Operation on $&Select: set option group. Throws on failure; handle the error or propagate it to the caller.

Parameters

sel $&Select
The Select instance used by this call (exclusive borrow).
index int
index (int)
group bool
group (bool)

Returns

int — a value of this type

(&Select) is_group

XuAPI
pub fn (sel &Select) is_group(index int) bool

Purpose

Operation on &Select: whether it is group.

Parameters

sel &Select
The Select instance used by this call (borrow).
index int
index (int)

Returns

bool — true or false

($&Select) route

XuAPI
pub fn (sel $&Select) 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

sel $&Select
The Select 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