XU XUv0.13.1
中文

UI / WIDGETS / Selection

DatePicker

Choose a calendar date

Run the Xu example

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

What to try

Change an appointment date.

Usage notes

Separate date values from their display format. Configure locale, week start and selectable ranges; do not rely only on placeholder text.

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.date_picker(value) or >>
    screen.place(id,24.0,24.0,320.0,80.0) or >>
    << id
}

($&Screen) date_picker

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

Purpose

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

($&DatePicker) set_locale

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

Purpose

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

Parameters

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

(&DatePicker) display_text

XuAPI
pub fn (picker &DatePicker) display_text() string

Purpose

Operation on &DatePicker: display text. Throws on failure; handle the error or propagate it to the caller.

Parameters

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

Returns

string — result string

struct DatePicker

XuAPI
pub struct DatePicker {

}

Purpose

A date field with an overlay calendar. Time and nanoseconds are preserved dates are interpreted in UTC, matching time.Time's calendar accessors.

Public fields

This type has no public fields.

(&DatePicker) id

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

Purpose

Return the unique integer ID of the element or control.

Parameters

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

Returns

int — a value of this type

(&DatePicker) bounds

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

Purpose

Return the bounding Rectangle of the control or geometry.

Parameters

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

Returns

layout.Rect — a value of this type

(&DatePicker) value

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

Purpose

Execute value on &DatePicker.

Parameters

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

Returns

time.Time — a value of this type

(&DatePicker) is_open

XuAPI
pub fn (picker &DatePicker) is_open() bool

Purpose

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

Parameters

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

Returns

bool — true or false

(&DatePicker) is_selectable

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

Purpose

Operation on &DatePicker: whether it is selectable.

Parameters

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

Returns

bool — true or false

($&DatePicker) set_selectable

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

Purpose

Operation on $&DatePicker: set selectable.

Parameters

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

Returns

This call does not return a value.

(&DatePicker) needs_paint

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

Purpose

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

Parameters

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

Returns

bool — true or false

(&DatePicker) visual_state

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

Purpose

Operation on &DatePicker: visual state.

Parameters

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

Returns

int — a value of this type

(&DatePicker) style_or

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

Purpose

Operation on &DatePicker: style or.

Parameters

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

($&DatePicker) set_style

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

Purpose

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

Parameters

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

($&DatePicker) set_enabled

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

Purpose

Operation on $&DatePicker: set enabled.

Parameters

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

Returns

This call does not return a value.

($&DatePicker) set_read_only

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

Purpose

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

Parameters

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

Returns

int — a value of this type

($&DatePicker) set_invalid

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

Purpose

Operation on $&DatePicker: set invalid.

Parameters

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

Returns

This call does not return a value.

($&DatePicker) set_focus

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

Purpose

Operation on $&DatePicker: set focus.

Parameters

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

Returns

This call does not return a value.

($&DatePicker) set_bounds

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

Purpose

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

Parameters

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

($&DatePicker) set_value

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

Purpose

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

Parameters

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

Returns

int — a value of this type

($&DatePicker) set_range

XuAPI
pub fn (picker $&DatePicker) set_range(minimum time.Time,maximum time.Time) int

Purpose

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

Parameters

picker $&DatePicker
The DatePicker instance used by this call (exclusive borrow).
minimum time.Time
minimum (time.Time)
maximum time.Time
maximum (time.Time)

Returns

int — a value of this type

($&DatePicker) set_open

XuAPI
pub fn (picker $&DatePicker) set_open(open bool)

Purpose

Operation on $&DatePicker: set open.

Parameters

picker $&DatePicker
The DatePicker instance used by this call (exclusive borrow).
open bool
open (bool)

Returns

This call does not return a value.

($&DatePicker) set_popup_above

XuAPI
pub fn (picker $&DatePicker) set_popup_above(above bool)

Purpose

Operation on $&DatePicker: set popup above.

Parameters

picker $&DatePicker
The DatePicker instance used by this call (exclusive borrow).
above bool
above (bool)

Returns

This call does not return a value.

($&DatePicker) apply_styles

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

(&DatePicker) popup_bounds

XuAPI
pub fn (picker &DatePicker) popup_bounds() layout.Rect

Purpose

Operation on &DatePicker: popup bounds.

Parameters

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

Returns

layout.Rect — a value of this type

(&DatePicker) calendar_cell

XuAPI
pub fn (picker &DatePicker) calendar_cell(index int) layout.Rect

Purpose

0..41 follow the configured first weekday; 42/43 are previous/next month. Throws on failure; handle the error or propagate it to the caller.

Parameters

picker &DatePicker
The DatePicker instance used by this call (borrow).
index int
index (int)

Returns

layout.Rect — a value of this type

(&DatePicker) calendar_date

XuAPI
pub fn (picker &DatePicker) calendar_date(index int) time.Time

Purpose

Operation on &DatePicker: calendar date. Throws on failure; handle the error or propagate it to the caller.

Parameters

picker &DatePicker
The DatePicker instance used by this call (borrow).
index int
index (int)

Returns

time.Time — a value of this type

($&DatePicker) input

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

($&DatePicker) route

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

($&DatePicker) measure_styled

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

Purpose

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

Parameters

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

($&DatePicker) paint_styled

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

Purpose

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

Parameters

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

($&DatePicker) paint_popup_styled

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

Purpose

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

Parameters

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

($&DatePicker) dispose

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

Purpose

Release and dispose native resources and underlying handles.

Parameters

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

Returns

This call does not return a value.

(&DatePicker) has_value

XuAPI
pub fn (picker &DatePicker) has_value() bool

Purpose

Operation on &DatePicker: whether it has value.

Parameters

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

Returns

bool — true or false

($&DatePicker) set_clearable

XuAPI
pub fn (picker $&DatePicker) set_clearable(enabled bool)

Purpose

Operation on $&DatePicker: set clearable.

Parameters

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

Returns

This call does not return a value.

($&DatePicker) clear

XuAPI
pub fn (picker $&DatePicker) clear() int

Purpose

Clear all buffered or stored entries and internal state. Throws on failure; handle the error or propagate it to the caller.

Parameters

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

Returns

int — a value of this type

($&DatePicker) set_today

XuAPI
pub fn (picker $&DatePicker) set_today(today time.Time) int

Purpose

The application supplies today in its intended timezone. Throws on failure; handle the error or propagate it to the caller.

Parameters

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

Returns

int — a value of this type

Complete native example

Component Workshop · Back to Widgets