XU XUv0.13.1
中文

UI / WIDGETS / Selection

Checkbox

Toggle an independent option

Run the Xu example

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

What to try

Toggle the checkbox and observe the boolean value.

Usage notes

Use for independent boolean options, optionally with an indeterminate state. A value change differs from action activation; use RadioGroup for exclusive choices.

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.checkbox("Receive updates",false) or >>
    screen.place(id,24.0,24.0,320.0,80.0) or >>
    << id
}

($&Screen) checkbox

XuAPI
pub fn (s $&Screen) checkbox(text string,checked bool) int

Purpose

Create Checkbox 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)
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.

struct Checkbox

XuAPI
pub struct Checkbox {

}

Purpose

Checkbox context or state structure.

Public fields

This type has no public fields.

See usage example

($&Checkbox) set_focus

XuAPI
pub fn (checkbox $&Checkbox) set_focus(focused bool)

Purpose

Operation on $&Checkbox: set focus.

Parameters

checkbox $&Checkbox
The Checkbox instance used by this call (exclusive borrow).
focused bool
focused (bool)

Returns

This call does not return a value.

($&Checkbox) set_enabled

XuAPI
pub fn (checkbox $&Checkbox) set_enabled(enabled bool)

Purpose

Operation on $&Checkbox: set enabled.

Parameters

checkbox $&Checkbox
The Checkbox instance used by this call (exclusive borrow).
enabled bool
enabled (bool)

Returns

This call does not return a value.

($&Checkbox) set_bounds

XuAPI
pub fn (checkbox $&Checkbox) set_bounds(bounds &layout.Rect) int

Purpose

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

Parameters

checkbox $&Checkbox
The Checkbox 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

(&Checkbox) needs_paint

XuAPI
pub fn (checkbox &Checkbox) needs_paint() bool

Purpose

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

Parameters

checkbox &Checkbox
The Checkbox instance used by this call (borrow).

Returns

bool — true or false

($&Checkbox) painted

XuAPI
pub fn (checkbox $&Checkbox) painted()

Purpose

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

Parameters

checkbox $&Checkbox
The Checkbox instance used by this call (exclusive borrow).

Returns

This call does not return a value.

(&Checkbox) is_selectable

XuAPI
pub fn (checkbox &Checkbox) is_selectable() bool

Purpose

Operation on &Checkbox: whether it is selectable.

Parameters

checkbox &Checkbox
The Checkbox instance used by this call (borrow).

Returns

bool — true or false

($&Checkbox) set_selectable

XuAPI
pub fn (checkbox $&Checkbox) set_selectable(selectable bool)

Purpose

Operation on $&Checkbox: set selectable.

Parameters

checkbox $&Checkbox
The Checkbox instance used by this call (exclusive borrow).
selectable bool
selectable (bool)

Returns

This call does not return a value.

(&Checkbox) value

XuAPI
pub fn (checkbox &Checkbox) value() bool

Purpose

Execute value on &Checkbox.

Parameters

checkbox &Checkbox
The Checkbox instance used by this call (borrow).

Returns

bool — true or false

(&Checkbox) is_indeterminate

XuAPI
pub fn (checkbox &Checkbox) is_indeterminate() bool

Purpose

Operation on &Checkbox: whether it is indeterminate.

Parameters

checkbox &Checkbox
The Checkbox instance used by this call (borrow).

Returns

bool — true or false

($&Checkbox) set_indeterminate

XuAPI
pub fn (checkbox $&Checkbox) set_indeterminate(mixed bool)

Purpose

Operation on $&Checkbox: set indeterminate.

Parameters

checkbox $&Checkbox
The Checkbox instance used by this call (exclusive borrow).
mixed bool
mixed (bool)

Returns

This call does not return a value.

($&Checkbox) set_value

XuAPI
pub fn (checkbox $&Checkbox) set_value(checked bool)

Purpose

Set a checkbox's checked state and clear indeterminate state from application data.

Parameters

checkbox $&Checkbox
The Checkbox instance used by this call (exclusive borrow).
checked bool
Checked state to display.

Returns

No return value; a state change marks repainting without generating a user input action.

($&Checkbox) input

XuAPI
pub fn (checkbox $&Checkbox) input(input &ui.InputEvent) Action

Purpose

Process checkbox interaction and update its checked state when activated.

Parameters

checkbox $&Checkbox
The Checkbox instance used by this call (exclusive borrow).
input &ui.InputEvent
Input event for the same window, canvas and generation, with coordinates in the control's canvas space.

Returns

An Action: kind identifies the action, consumed marks a handled event, request_focus requests focus, and needs_paint requests repainting.

Usage notes

  • A change yields ACTION_CHANGE, with value 1.0 for checked or 0.0 for unchecked; activating an indeterminate box checks it.

($&Checkbox) event

XuAPI
pub fn (checkbox $&Checkbox) 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

checkbox $&Checkbox
The Checkbox 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.

(&Checkbox) paint

XuAPI
pub fn (checkbox &Checkbox) 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

checkbox &Checkbox
The Checkbox 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

(&Checkbox) clone

XuAPI
pub fn (c &Checkbox) clone() Checkbox

Purpose

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

Parameters

c &Checkbox
The Checkbox instance used by this call (borrow).

Returns

Checkbox — a value of this type

($&Checkbox) set_motion

XuAPI
pub fn (control $&Checkbox) set_motion(spec &MotionSpec) int

Purpose

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

Parameters

control $&Checkbox
The Checkbox 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

($&Checkbox) tick

XuAPI
pub fn (control $&Checkbox) 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 $&Checkbox
The Checkbox instance used by this call (exclusive borrow).
now time.Instant
now (time.Instant)
reduced bool
reduced (bool)

Returns

bool — true or false

(&Checkbox) next_tick

XuAPI
pub fn (control &Checkbox) next_tick(now time.Instant) time.Instant

Purpose

Operation on &Checkbox: next tick. Throws on failure; handle the error or propagate it to the caller.

Parameters

control &Checkbox
The Checkbox instance used by this call (borrow).
now time.Instant
now (time.Instant)

Returns

time.Instant — a value of this type

(&Checkbox) id

XuAPI
pub fn (checkbox &Checkbox) id() int

Purpose

Return the unique integer ID of the element or control.

Parameters

checkbox &Checkbox
The Checkbox instance used by this call (borrow).

Returns

int — a value of this type

(&Checkbox) bounds

XuAPI
pub fn (checkbox &Checkbox) bounds() layout.Rect

Purpose

Return the bounding Rectangle of the control or geometry.

Parameters

checkbox &Checkbox
The Checkbox instance used by this call (borrow).

Returns

layout.Rect — a value of this type

(&Checkbox) is_focused

XuAPI
pub fn (checkbox &Checkbox) is_focused() bool

Purpose

Return whether the control currently has input focus.

Parameters

checkbox &Checkbox
The Checkbox instance used by this call (borrow).

Returns

bool — true or false

(&Checkbox) is_enabled

XuAPI
pub fn (checkbox &Checkbox) is_enabled() bool

Purpose

Return whether the control is currently enabled.

Parameters

checkbox &Checkbox
The Checkbox instance used by this call (borrow).

Returns

bool — true or false

(&Checkbox) is_invalid

XuAPI
pub fn (checkbox &Checkbox) is_invalid() bool

Purpose

Operation on &Checkbox: whether it is invalid.

Parameters

checkbox &Checkbox
The Checkbox instance used by this call (borrow).

Returns

bool — true or false

(&Checkbox) is_read_only

XuAPI
pub fn (checkbox &Checkbox) is_read_only() bool

Purpose

Operation on &Checkbox: whether it is read only.

Parameters

checkbox &Checkbox
The Checkbox instance used by this call (borrow).

Returns

bool — true or false

($&Checkbox) set_read_only

XuAPI
pub fn (checkbox $&Checkbox) set_read_only(read_only bool)

Purpose

Operation on $&Checkbox: set read only.

Parameters

checkbox $&Checkbox
The Checkbox instance used by this call (exclusive borrow).
read_only bool
read_only (bool)

Returns

This call does not return a value.

(&Checkbox) visual_state

XuAPI
pub fn (checkbox &Checkbox) visual_state() int

Purpose

Operation on &Checkbox: visual state.

Parameters

checkbox &Checkbox
The Checkbox instance used by this call (borrow).

Returns

int — a value of this type

(&Checkbox) has_style

XuAPI
pub fn (checkbox &Checkbox) has_style() bool

Purpose

Operation on &Checkbox: whether it has style.

Parameters

checkbox &Checkbox
The Checkbox instance used by this call (borrow).

Returns

bool — true or false

(&Checkbox) style_or

XuAPI
pub fn (checkbox &Checkbox) style_or(styles &Styles) ControlStyle

Purpose

Operation on &Checkbox: style or.

Parameters

checkbox &Checkbox
The Checkbox 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

($&Checkbox) set_style

XuAPI
pub fn (checkbox $&Checkbox) set_style(style &ControlStyle) int

Purpose

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

Parameters

checkbox $&Checkbox
The Checkbox 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

($&Checkbox) clear_style

XuAPI
pub fn (checkbox $&Checkbox) clear_style()

Purpose

Operation on $&Checkbox: clear style.

Parameters

checkbox $&Checkbox
The Checkbox instance used by this call (exclusive borrow).

Returns

This call does not return a value.

(&Checkbox) measure_styled

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

Purpose

Measure Checkbox with the effective font, density, content and minimum size.

Parameters

checkbox &Checkbox
The Checkbox 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

intrinsic logical size; throws if native shaping fails

(&Checkbox) paint_styled

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

Purpose

Paint Checkbox using the complete theme; control bounds and Frame use the same local coordinates.

Parameters

checkbox &Checkbox
The Checkbox 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

0 on success; throws on failure

($&Checkbox) set_invalid

XuAPI
pub fn (checkbox $&Checkbox) set_invalid(invalid bool)

Purpose

Operation on $&Checkbox: set invalid.

Parameters

checkbox $&Checkbox
The Checkbox instance used by this call (exclusive borrow).
invalid bool
invalid (bool)

Returns

This call does not return a value.

($&Checkbox) route

XuAPI
pub fn (checkbox $&Checkbox) 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

checkbox $&Checkbox
The Checkbox 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