XU XUv0.13.1
中文

UI / WIDGETS / Actions

Menu

Present actions in a command list

Run the Xu example

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

What to try

Open a menu and choose a command.

Usage notes

Commands, groups, checked items and submenus have different semantics. Use stable item identifiers and execute commands in the application after activation.

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 {
    items := [widgets.menu_item(1,"Save"),widgets.menu_item(2,"Export")]
    id := screen.menu("Actions",&items,widgets.MENU_DROPDOWN,0) or >>
    screen.place(id,24.0,24.0,320.0,80.0) or >>
    << id
}

($&Screen) menu

XuAPI
pub fn (s $&Screen) menu(label string,items &[]MenuItem,mode int,primary_key int) int

Purpose

Create Menu / ContextMenu / SplitButton in Screen and return the component node ID; throw on creation failure.

Parameters

s $&Screen
The Screen instance used by this call (exclusive borrow).
label string
label (string)
items &[]MenuItem
items (read-only borrow; caller keeps the original; type &[]MenuItem)
mode int
mode (int)
primary_key int
primary_key (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.

struct Menu

XuAPI
pub struct Menu {

}

Purpose

Menu context or state structure.

Public fields

This type has no public fields.

(&Menu) id

XuAPI
pub fn (m &Menu) id() int

Purpose

Return the unique integer ID of the element or control.

Parameters

m &Menu
The Menu instance used by this call (borrow).

Returns

int — a value of this type

(&Menu) bounds

XuAPI
pub fn (m &Menu) bounds() layout.Rect

Purpose

Return the bounding Rectangle of the control or geometry.

Parameters

m &Menu
The Menu instance used by this call (borrow).

Returns

layout.Rect — a value of this type

(&Menu) is_enabled

XuAPI
pub fn (m &Menu) is_enabled() bool

Purpose

Return whether the control is currently enabled.

Parameters

m &Menu
The Menu instance used by this call (borrow).

Returns

bool — true or false

(&Menu) is_selectable

XuAPI
pub fn (m &Menu) is_selectable() bool

Purpose

Operation on &Menu: whether it is selectable.

Parameters

m &Menu
The Menu instance used by this call (borrow).

Returns

bool — true or false

($&Menu) set_selectable

XuAPI
pub fn (m $&Menu) set_selectable(selectable bool)

Purpose

Operation on $&Menu: set selectable.

Parameters

m $&Menu
The Menu instance used by this call (exclusive borrow).
selectable bool
selectable (bool)

Returns

This call does not return a value.

(&Menu) is_open

XuAPI
pub fn (m &Menu) is_open() bool

Purpose

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

Parameters

m &Menu
The Menu instance used by this call (borrow).

Returns

bool — true or false

(&Menu) opacity

XuAPI
pub fn (m &Menu) opacity() f64

Purpose

Execute opacity on &Menu.

Parameters

m &Menu
The Menu instance used by this call (borrow).

Returns

f64 — a value of this type

(&Menu) needs_paint

XuAPI
pub fn (m &Menu) needs_paint() bool

Purpose

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

Parameters

m &Menu
The Menu instance used by this call (borrow).

Returns

bool — true or false

($&Menu) painted

XuAPI
pub fn (m $&Menu) painted()

Purpose

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

Parameters

m $&Menu
The Menu instance used by this call (exclusive borrow).

Returns

This call does not return a value.

($&Menu) set_items

XuAPI
pub fn (m $&Menu) set_items(items &[]MenuItem) int

Purpose

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

Parameters

m $&Menu
The Menu instance used by this call (exclusive borrow).
items &[]MenuItem
items (read-only borrow; caller keeps the original; type &[]MenuItem)

Returns

int — a value of this type

($&Menu) set_item_label

XuAPI
pub fn (m $&Menu) set_item_label(key int,label string) int

Purpose

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

Parameters

m $&Menu
The Menu instance used by this call (exclusive borrow).
key int
key (int)
label string
label (string)

Returns

int — a value of this type

($&Menu) set_label

XuAPI
pub fn (m $&Menu) set_label(label string)

Purpose

Operation on $&Menu: set label.

Parameters

m $&Menu
The Menu instance used by this call (exclusive borrow).
label string
label (string)

Returns

This call does not return a value.

(&Menu) checked

XuAPI
pub fn (m &Menu) checked(key int) bool

Purpose

Execute checked on &Menu. Throws on failure; handle the error or propagate it to the caller.

Parameters

m &Menu
The Menu instance used by this call (borrow).
key int
key (int)

Returns

bool — true or false

($&Menu) set_checked

XuAPI
pub fn (m $&Menu) set_checked(key int,value bool) int

Purpose

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

Parameters

m $&Menu
The Menu instance used by this call (exclusive borrow).
key int
key (int)
value bool
value (bool)

Returns

int — a value of this type

($&Menu) set_item_enabled

XuAPI
pub fn (m $&Menu) set_item_enabled(key int,value bool) int

Purpose

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

Parameters

m $&Menu
The Menu instance used by this call (exclusive borrow).
key int
key (int)
value bool
value (bool)

Returns

int — a value of this type

($&Menu) set_appearance

XuAPI
pub fn (m $&Menu) set_appearance(a &MenuAppearance) int

Purpose

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

Parameters

m $&Menu
The Menu instance used by this call (exclusive borrow).
a &MenuAppearance
value (read-only borrow; caller keeps the original; type &MenuAppearance)

Returns

int — a value of this type

($&Menu) close

XuAPI
pub fn (m $&Menu) close() int

Purpose

Operation on $&Menu: close the resource. Throws on failure; handle the error or propagate it to the caller.

Parameters

m $&Menu
The Menu instance used by this call (exclusive borrow).

Returns

int — a value of this type

($&Menu) cancel

XuAPI
pub fn (m $&Menu) cancel()

Purpose

Execute cancel on $&Menu.

Parameters

m $&Menu
The Menu instance used by this call (exclusive borrow).

Returns

This call does not return a value.

($&Menu) set_focus

XuAPI
pub fn (m $&Menu) set_focus(value bool)

Purpose

Operation on $&Menu: set focus.

Parameters

m $&Menu
The Menu instance used by this call (exclusive borrow).
value bool
value (bool)

Returns

This call does not return a value.

($&Menu) set_enabled

XuAPI
pub fn (m $&Menu) set_enabled(value bool)

Purpose

Operation on $&Menu: set enabled.

Parameters

m $&Menu
The Menu instance used by this call (exclusive borrow).
value bool
value (bool)

Returns

This call does not return a value.

($&Menu) set_read_only

XuAPI
pub fn (m $&Menu) set_read_only(value bool)

Purpose

Operation on $&Menu: set read only.

Parameters

m $&Menu
The Menu instance used by this call (exclusive borrow).
value bool
value (bool)

Returns

This call does not return a value.

($&Menu) set_bounds

XuAPI
pub fn (m $&Menu) set_bounds(b &layout.Rect) int

Purpose

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

Parameters

m $&Menu
The Menu instance used by this call (exclusive borrow).
b &layout.Rect
b (read-only borrow; caller keeps the original; type &layout.Rect)

Returns

int — a value of this type

($&Menu) set_style

XuAPI
pub fn (m $&Menu) set_style(style &ControlStyle) int

Purpose

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

Parameters

m $&Menu
The Menu 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

($&Menu) clear_style

XuAPI
pub fn (m $&Menu) clear_style()

Purpose

Operation on $&Menu: clear style.

Parameters

m $&Menu
The Menu instance used by this call (exclusive borrow).

Returns

This call does not return a value.

($&Menu) set_motion

XuAPI
pub fn (m $&Menu) set_motion(spec &MotionSpec) int

Purpose

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

Parameters

m $&Menu
The Menu 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

($&Menu) dispose

XuAPI
pub fn (m $&Menu) dispose()

Purpose

Release and dispose native resources and underlying handles.

Parameters

m $&Menu
The Menu instance used by this call (exclusive borrow).

Returns

This call does not return a value.

(&Menu) popup_bounds

XuAPI
pub fn (m &Menu) popup_bounds() layout.Rect

Purpose

Operation on &Menu: popup bounds.

Parameters

m &Menu
The Menu instance used by this call (borrow).

Returns

layout.Rect — a value of this type

($&Menu) set_viewport

XuAPI
pub fn (m $&Menu) set_viewport(viewport &layout.Rect) int

Purpose

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

Parameters

m $&Menu
The Menu instance used by this call (exclusive borrow).
viewport &layout.Rect
viewport (read-only borrow; caller keeps the original; type &layout.Rect)

Returns

int — a value of this type

($&Menu) apply_styles

XuAPI
pub fn (m $&Menu) 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

m $&Menu
The Menu 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

($&Menu) tick

XuAPI
pub fn (m $&Menu) tick(styles &Styles,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

m $&Menu
The Menu instance used by this call (exclusive borrow).
styles &Styles
styles (read-only borrow; caller keeps the original; type &Styles)
now time.Instant
now (time.Instant)
reduced bool
reduced (bool)

Returns

bool — true or false

(&Menu) next_tick

XuAPI
pub fn (m &Menu) next_tick(now time.Instant) time.Instant

Purpose

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

Parameters

m &Menu
The Menu instance used by this call (borrow).
now time.Instant
now (time.Instant)

Returns

time.Instant — a value of this type

($&Menu) open_at

XuAPI
pub fn (m $&Menu) open_at(x f64,y f64,context bool) int

Purpose

Operation on $&Menu: open at. Throws on failure; handle the error or propagate it to the caller.

Parameters

m $&Menu
The Menu instance used by this call (exclusive borrow).
x f64
value (f64)
y f64
value (f64)
context bool
context (bool)

Returns

int — a value of this type

($&Menu) shortcut

XuAPI
pub fn (m $&Menu) shortcut(event &ui.InputEvent) Action

Purpose

Execute shortcut on $&Menu. Throws on failure; handle the error or propagate it to the caller.

Parameters

m $&Menu
The Menu 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.

($&Menu) input

XuAPI
pub fn (m $&Menu) 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

m $&Menu
The Menu 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.

($&Menu) route

XuAPI
pub fn (m $&Menu) 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

m $&Menu
The Menu 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.

($&Menu) paint_styled

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

Purpose

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

Parameters

m $&Menu
The Menu 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

($&Menu) paint_popup_styled

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

Purpose

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

Parameters

m $&Menu
The Menu 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

Complete native example

Component Workshop · Back to Widgets