XU XUv0.13.1
中文

UI / WIDGETS / Navigation

Tabs

Switch between related content panels

Run the Xu example

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

What to try

Switch between Overview, Activity and Settings and observe the selected index.

Usage notes

Each tab corresponds to a content panel. Update panel visibility on selection while retaining independent keyboard focus behavior.

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

($&Screen) tabs

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

Purpose

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

(&Tabs) clone

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

Purpose

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

Parameters

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

Returns

Tabs — a value of this type

struct Tabs

XuAPI
pub struct Tabs {

}

Purpose

Tabs context or state structure.

Public fields

This type has no public fields.

See usage example

(&Tabs) is_selectable

XuAPI
pub fn (t &Tabs) is_selectable() bool

Purpose

Operation on &Tabs: whether it is selectable.

Parameters

t &Tabs
The Tabs instance used by this call (borrow).

Returns

bool — true or false

($&Tabs) set_selectable

XuAPI
pub fn (t $&Tabs) set_selectable(selectable bool)

Purpose

Operation on $&Tabs: set selectable.

Parameters

t $&Tabs
The Tabs instance used by this call (exclusive borrow).
selectable bool
selectable (bool)

Returns

This call does not return a value.

(&Tabs) id

XuAPI
pub fn (t &Tabs) id() int

Purpose

Return the unique integer ID of the element or control.

Parameters

t &Tabs
The Tabs instance used by this call (borrow).

Returns

int — a value of this type

(&Tabs) bounds

XuAPI
pub fn (t &Tabs) bounds() layout.Rect

Purpose

Return the bounding Rectangle of the control or geometry.

Parameters

t &Tabs
The Tabs instance used by this call (borrow).

Returns

layout.Rect — a value of this type

(&Tabs) count

XuAPI
pub fn (t &Tabs) count() int

Purpose

Return the number of items in this control.

Parameters

t &Tabs
The Tabs instance used by this call (borrow).

Returns

int — a value of this type

(&Tabs) selected

XuAPI
pub fn (t &Tabs) selected() int

Purpose

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

Parameters

t &Tabs
The Tabs instance used by this call (borrow).

Returns

int — a value of this type

(&Tabs) hovered_item

XuAPI
pub fn (t &Tabs) hovered_item() int

Purpose

Operation on &Tabs: hovered item.

Parameters

t &Tabs
The Tabs instance used by this call (borrow).

Returns

int — a value of this type

(&Tabs) needs_paint

XuAPI
pub fn (t &Tabs) needs_paint() bool

Purpose

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

Parameters

t &Tabs
The Tabs instance used by this call (borrow).

Returns

bool — true or false

($&Tabs) painted

XuAPI
pub fn (t $&Tabs) painted()

Purpose

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

Parameters

t $&Tabs
The Tabs instance used by this call (exclusive borrow).

Returns

This call does not return a value.

($&Tabs) invalidate

XuAPI
pub fn (t $&Tabs) invalidate()

Purpose

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

Parameters

t $&Tabs
The Tabs instance used by this call (exclusive borrow).

Returns

This call does not return a value.

($&Tabs) cancel

XuAPI
pub fn (t $&Tabs) cancel()

Purpose

Execute cancel on $&Tabs.

Parameters

t $&Tabs
The Tabs instance used by this call (exclusive borrow).

Returns

This call does not return a value.

(&Tabs) is_enabled

XuAPI
pub fn (t &Tabs) is_enabled() bool

Purpose

Return whether the control is currently enabled.

Parameters

t &Tabs
The Tabs instance used by this call (borrow).

Returns

bool — true or false

($&Tabs) set_enabled

XuAPI
pub fn (t $&Tabs) set_enabled(enabled bool)

Purpose

Operation on $&Tabs: set enabled.

Parameters

t $&Tabs
The Tabs instance used by this call (exclusive borrow).
enabled bool
enabled (bool)

Returns

This call does not return a value.

(&Tabs) is_focused

XuAPI
pub fn (t &Tabs) is_focused() bool

Purpose

Return whether the control currently has input focus.

Parameters

t &Tabs
The Tabs instance used by this call (borrow).

Returns

bool — true or false

($&Tabs) set_focus

XuAPI
pub fn (t $&Tabs) set_focus(focused bool)

Purpose

Operation on $&Tabs: set focus.

Parameters

t $&Tabs
The Tabs instance used by this call (exclusive borrow).
focused bool
focused (bool)

Returns

This call does not return a value.

(&Tabs) is_hovered

XuAPI
pub fn (t &Tabs) is_hovered() bool

Purpose

Operation on &Tabs: whether it is hovered.

Parameters

t &Tabs
The Tabs instance used by this call (borrow).

Returns

bool — true or false

(&Tabs) is_invalid

XuAPI
pub fn (t &Tabs) is_invalid() bool

Purpose

Operation on &Tabs: whether it is invalid.

Parameters

t &Tabs
The Tabs instance used by this call (borrow).

Returns

bool — true or false

($&Tabs) set_invalid

XuAPI
pub fn (t $&Tabs) set_invalid(invalid bool)

Purpose

Operation on $&Tabs: set invalid.

Parameters

t $&Tabs
The Tabs instance used by this call (exclusive borrow).
invalid bool
invalid (bool)

Returns

This call does not return a value.

(&Tabs) is_read_only

XuAPI
pub fn (t &Tabs) is_read_only() bool

Purpose

Operation on &Tabs: whether it is read only.

Parameters

t &Tabs
The Tabs instance used by this call (borrow).

Returns

bool — true or false

($&Tabs) set_read_only

XuAPI
pub fn (t $&Tabs) set_read_only(read_only bool)

Purpose

Operation on $&Tabs: set read only.

Parameters

t $&Tabs
The Tabs instance used by this call (exclusive borrow).
read_only bool
read_only (bool)

Returns

This call does not return a value.

($&Tabs) set_count

XuAPI
pub fn (t $&Tabs) set_count(count int) int

Purpose

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

Parameters

t $&Tabs
The Tabs instance used by this call (exclusive borrow).
count int
count (int)

Returns

int — a value of this type

($&Tabs) set_selected

XuAPI
pub fn (t $&Tabs) set_selected(index int) int

Purpose

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

Parameters

t $&Tabs
The Tabs instance used by this call (exclusive borrow).
index int
index (int)

Returns

int — a value of this type

($&Tabs) set_bounds

XuAPI
pub fn (t $&Tabs) set_bounds(bounds &layout.Rect) int

Purpose

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

Parameters

t $&Tabs
The Tabs 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

(&Tabs) visual_state

XuAPI
pub fn (t &Tabs) visual_state() int

Purpose

Operation on &Tabs: visual state.

Parameters

t &Tabs
The Tabs instance used by this call (borrow).

Returns

int — a value of this type

(&Tabs) item_visual_state

XuAPI
pub fn (t &Tabs) item_visual_state(index int) int

Purpose

Operation on &Tabs: item visual state.

Parameters

t &Tabs
The Tabs instance used by this call (borrow).
index int
index (int)

Returns

int — a value of this type

(&Tabs) has_style

XuAPI
pub fn (t &Tabs) has_style() bool

Purpose

Operation on &Tabs: whether it has style.

Parameters

t &Tabs
The Tabs instance used by this call (borrow).

Returns

bool — true or false

(&Tabs) style_or

XuAPI
pub fn (t &Tabs) style_or(styles &Styles) ControlStyle

Purpose

Operation on &Tabs: style or.

Parameters

t &Tabs
The Tabs 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

($&Tabs) set_style

XuAPI
pub fn (t $&Tabs) set_style(style &ControlStyle) int

Purpose

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

Parameters

t $&Tabs
The Tabs 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

($&Tabs) clear_style

XuAPI
pub fn (t $&Tabs) clear_style()

Purpose

Operation on $&Tabs: clear style.

Parameters

t $&Tabs
The Tabs instance used by this call (exclusive borrow).

Returns

This call does not return a value.

(&Tabs) item_bounds

XuAPI
pub fn (t &Tabs) item_bounds(index int,styles &Styles) layout.Rect

Purpose

Operation on &Tabs: item bounds.

Parameters

t &Tabs
The Tabs 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

($&Tabs) apply_styles

XuAPI
pub fn (t $&Tabs) 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

t $&Tabs
The Tabs 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

($&Tabs) set_item_widths

XuAPI
pub fn (t $&Tabs) set_item_widths(widths &[]f64) int

Purpose

Operation on $&Tabs: set item widths. Throws on failure; handle the error or propagate it to the caller.

Parameters

t $&Tabs
The Tabs instance used by this call (exclusive borrow).
widths &[]f64
widths (read-only borrow; caller keeps the original; type &[]f64)

Returns

int — a value of this type

($&Tabs) set_automatic_activation

XuAPI
pub fn (t $&Tabs) set_automatic_activation(automatic bool)

Purpose

Operation on $&Tabs: set automatic activation.

Parameters

t $&Tabs
The Tabs instance used by this call (exclusive borrow).
automatic bool
automatic (bool)

Returns

This call does not return a value.

($&Tabs) input

XuAPI
pub fn (t $&Tabs) input(input &ui.InputEvent) Action

Purpose

Process routed mouse, keyboard, or touch input events.

Parameters

t $&Tabs
The Tabs 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.

($&Tabs) event

XuAPI
pub fn (t $&Tabs) 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

t $&Tabs
The Tabs 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.

(&Tabs) paint

XuAPI
pub fn (t &Tabs) 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

t &Tabs
The Tabs 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

(&Tabs) measure_styled

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

Purpose

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

Parameters

t &Tabs
The Tabs 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

(&Tabs) paint_box_styled

XuAPI
pub fn (t &Tabs) paint_box_styled(frame $&draw.Frame,styles &Styles) int

Purpose

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

Parameters

t &Tabs
The Tabs 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

(&Tabs) paint_tab_styled

XuAPI
pub fn (t &Tabs) paint_tab_styled(frame $&draw.Frame,index int,label $&StyledLabel,styles &Styles) int

Purpose

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

Parameters

t &Tabs
The Tabs 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

(&Tabs) paint_styled

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

Purpose

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

Parameters

t &Tabs
The Tabs 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

(&Tabs) is_automatic

XuAPI
pub fn (t &Tabs) is_automatic() bool

Purpose

Operation on &Tabs: whether it is automatic.

Parameters

t &Tabs
The Tabs instance used by this call (borrow).

Returns

bool — true or false

($&Tabs) route

XuAPI
pub fn (t $&Tabs) 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

t $&Tabs
The Tabs 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