XU XUv0.13.1
中文

UI / WIDGETS / Selection

TimePicker

Choose a time of day

Run the Xu example

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

What to try

Adjust an appointment time.

Usage notes

Choose 12- or 24-hour formatting and whether seconds are shown. The application defines the relationship between displayed time and its business time zone.

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
#time

fn configure(screen $&widgets.Screen) int {
    value := time.date(2026,10,28,14,30,0,0)
    id := screen.time_picker(value) or >>
    screen.place(id,24.0,24.0,320.0,80.0) or >>
    << id
}

($&Screen) time_picker

XuAPI
pub fn (s $&Screen) time_picker(value time.Time) int

Purpose

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

Parameters

s $&Screen
The Screen instance used by this call (exclusive borrow).
value time.Time
value (time.Time)

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.

($&TimePicker) set_locale

XuAPI
pub fn (picker $&TimePicker) set_locale(locale &Locale) int

Purpose

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

Parameters

picker $&TimePicker
The TimePicker instance used by this call (exclusive borrow).
locale &Locale
locale (read-only borrow; caller keeps the original; type &Locale)

Returns

int — a value of this type

($&TimePicker) use_locale_clock

XuAPI
pub fn (picker $&TimePicker) use_locale_clock()

Purpose

Operation on $&TimePicker: use locale clock.

Parameters

picker $&TimePicker
The TimePicker instance used by this call (exclusive borrow).

Returns

This call does not return a value.

struct TimePicker

XuAPI
pub struct TimePicker {

}

Purpose

A 24-hour segmented field. Editing changes the selected clock component, wraps within that component, and preserves the date and subsecond value.

Public fields

This type has no public fields.

(&TimePicker) id

XuAPI
pub fn (picker &TimePicker) id() int

Purpose

Return the unique integer ID of the element or control.

Parameters

picker &TimePicker
The TimePicker instance used by this call (borrow).

Returns

int — a value of this type

(&TimePicker) bounds

XuAPI
pub fn (picker &TimePicker) bounds() layout.Rect

Purpose

Return the bounding Rectangle of the control or geometry.

Parameters

picker &TimePicker
The TimePicker instance used by this call (borrow).

Returns

layout.Rect — a value of this type

(&TimePicker) value

XuAPI
pub fn (picker &TimePicker) value() time.Time

Purpose

Execute value on &TimePicker.

Parameters

picker &TimePicker
The TimePicker instance used by this call (borrow).

Returns

time.Time — a value of this type

(&TimePicker) selected_part

XuAPI
pub fn (picker &TimePicker) selected_part() int

Purpose

Operation on &TimePicker: selected part.

Parameters

picker &TimePicker
The TimePicker instance used by this call (borrow).

Returns

int — a value of this type

(&TimePicker) is_selectable

XuAPI
pub fn (picker &TimePicker) is_selectable() bool

Purpose

Operation on &TimePicker: whether it is selectable.

Parameters

picker &TimePicker
The TimePicker instance used by this call (borrow).

Returns

bool — true or false

($&TimePicker) set_selectable

XuAPI
pub fn (picker $&TimePicker) set_selectable(selectable bool)

Purpose

Operation on $&TimePicker: set selectable.

Parameters

picker $&TimePicker
The TimePicker instance used by this call (exclusive borrow).
selectable bool
selectable (bool)

Returns

This call does not return a value.

(&TimePicker) needs_paint

XuAPI
pub fn (picker &TimePicker) needs_paint() bool

Purpose

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

Parameters

picker &TimePicker
The TimePicker instance used by this call (borrow).

Returns

bool — true or false

(&TimePicker) visual_state

XuAPI
pub fn (picker &TimePicker) visual_state() int

Purpose

Operation on &TimePicker: visual state.

Parameters

picker &TimePicker
The TimePicker instance used by this call (borrow).

Returns

int — a value of this type

(&TimePicker) style_or

XuAPI
pub fn (picker &TimePicker) style_or(styles &Styles) ControlStyle

Purpose

Operation on &TimePicker: style or.

Parameters

picker &TimePicker
The TimePicker 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

($&TimePicker) set_style

XuAPI
pub fn (picker $&TimePicker) set_style(style &ControlStyle) int

Purpose

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

Parameters

picker $&TimePicker
The TimePicker 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

($&TimePicker) set_value

XuAPI
pub fn (picker $&TimePicker) set_value(value time.Time) int

Purpose

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

Parameters

picker $&TimePicker
The TimePicker instance used by this call (exclusive borrow).
value time.Time
value (time.Time)

Returns

int — a value of this type

($&TimePicker) set_show_seconds

XuAPI
pub fn (picker $&TimePicker) set_show_seconds(show bool)

Purpose

Operation on $&TimePicker: set show seconds.

Parameters

picker $&TimePicker
The TimePicker instance used by this call (exclusive borrow).
show bool
show (bool)

Returns

This call does not return a value.

($&TimePicker) set_enabled

XuAPI
pub fn (picker $&TimePicker) set_enabled(enabled bool)

Purpose

Operation on $&TimePicker: set enabled.

Parameters

picker $&TimePicker
The TimePicker instance used by this call (exclusive borrow).
enabled bool
enabled (bool)

Returns

This call does not return a value.

($&TimePicker) set_read_only

XuAPI
pub fn (picker $&TimePicker) set_read_only(read_only bool) int

Purpose

Operation on $&TimePicker: set read only. Throws on failure; handle the error or propagate it to the caller.

Parameters

picker $&TimePicker
The TimePicker instance used by this call (exclusive borrow).
read_only bool
read_only (bool)

Returns

int — a value of this type

($&TimePicker) set_invalid

XuAPI
pub fn (picker $&TimePicker) set_invalid(invalid bool)

Purpose

Operation on $&TimePicker: set invalid.

Parameters

picker $&TimePicker
The TimePicker instance used by this call (exclusive borrow).
invalid bool
invalid (bool)

Returns

This call does not return a value.

($&TimePicker) set_focus

XuAPI
pub fn (picker $&TimePicker) set_focus(focused bool)

Purpose

Operation on $&TimePicker: set focus.

Parameters

picker $&TimePicker
The TimePicker instance used by this call (exclusive borrow).
focused bool
focused (bool)

Returns

This call does not return a value.

($&TimePicker) set_bounds

XuAPI
pub fn (picker $&TimePicker) set_bounds(bounds &layout.Rect) int

Purpose

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

Parameters

picker $&TimePicker
The TimePicker 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

(&TimePicker) part_bounds

XuAPI
pub fn (picker &TimePicker) part_bounds(part int) layout.Rect

Purpose

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

Parameters

picker &TimePicker
The TimePicker instance used by this call (borrow).
part int
part (int)

Returns

layout.Rect — a value of this type

($&TimePicker) input

XuAPI
pub fn (picker $&TimePicker) 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

picker $&TimePicker
The TimePicker 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.

($&TimePicker) route

XuAPI
pub fn (picker $&TimePicker) 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

picker $&TimePicker
The TimePicker 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.

($&TimePicker) measure_styled

XuAPI
pub fn (picker $&TimePicker) measure_styled(styles &Styles) layout.Size

Purpose

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

Parameters

picker $&TimePicker
The TimePicker 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

($&TimePicker) paint_styled

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

Purpose

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

Parameters

picker $&TimePicker
The TimePicker 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

($&TimePicker) dispose

XuAPI
pub fn (picker $&TimePicker) dispose()

Purpose

Release and dispose native resources and underlying handles.

Parameters

picker $&TimePicker
The TimePicker instance used by this call (exclusive borrow).

Returns

This call does not return a value.

($&TimePicker) set_12_hour

XuAPI
pub fn (picker $&TimePicker) set_12_hour(enabled bool)

Purpose

Operation on $&TimePicker: set 12 hour.

Parameters

picker $&TimePicker
The TimePicker instance used by this call (exclusive borrow).
enabled bool
enabled (bool)

Returns

This call does not return a value.

(&TimePicker) period_bounds

XuAPI
pub fn (picker &TimePicker) period_bounds() layout.Rect

Purpose

Operation on &TimePicker: period bounds.

Parameters

picker &TimePicker
The TimePicker instance used by this call (borrow).

Returns

layout.Rect — a value of this type

($&TimePicker) apply_styles

XuAPI
pub fn (picker $&TimePicker) 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

picker $&TimePicker
The TimePicker 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

Complete native example

Component Workshop · Back to Widgets