XU XUv0.13.1
中文

UI / WIDGETS / Layout

Card

Group related content into one region

Run the Xu example

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

What to try

Inspect the card container, then edit its dimensions and rerun.

Usage notes

Cards group related content and can separate heading, body and actions. Set child parents correctly and keep spacing consistent with layout and theme.

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

($&Screen) card

XuAPI
pub fn (s $&Screen) card() int

Purpose

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

Parameters

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

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.

(&Card) regions

XuAPI
pub fn (card &Card) regions(styles &Styles,header_height f64,footer_height f64) CardRegions

Purpose

Execute regions on &Card. Throws on failure; handle the error or propagate it to the caller.

Parameters

card &Card
The Card instance used by this call (borrow).
styles &Styles
styles (read-only borrow; caller keeps the original; type &Styles)
header_height f64
header_height (f64)
footer_height f64
footer_height (f64)

Returns

CardRegions — a value of this type

(&Card) clone

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

Purpose

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

Parameters

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

Returns

Card — a value of this type

struct Card

XuAPI
pub struct Card {

}

Purpose

Card context or state structure.

Public fields

This type has no public fields.

See usage example

(&Card) is_selectable

XuAPI
pub fn (cd &Card) is_selectable() bool

Purpose

Operation on &Card: whether it is selectable.

Parameters

cd &Card
The Card instance used by this call (borrow).

Returns

bool — true or false

($&Card) set_selectable

XuAPI
pub fn (cd $&Card) set_selectable(selectable bool)

Purpose

Operation on $&Card: set selectable.

Parameters

cd $&Card
The Card instance used by this call (exclusive borrow).
selectable bool
selectable (bool)

Returns

This call does not return a value.

(&Card) bounds

XuAPI
pub fn (cd &Card) bounds() layout.Rect

Purpose

Return the bounding Rectangle of the control or geometry.

Parameters

cd &Card
The Card instance used by this call (borrow).

Returns

layout.Rect — a value of this type

($&Card) set_bounds

XuAPI
pub fn (cd $&Card) set_bounds(bounds &layout.Rect) int

Purpose

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

Parameters

cd $&Card
The Card 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

(&Card) content_bounds

XuAPI
pub fn (cd &Card) content_bounds(styles &Styles) layout.Rect

Purpose

Operation on &Card: content bounds.

Parameters

cd &Card
The Card instance used by this call (borrow).
styles &Styles
styles (read-only borrow; caller keeps the original; type &Styles)

Returns

layout.Rect — a value of this type

(&Card) needs_paint

XuAPI
pub fn (cd &Card) needs_paint() bool

Purpose

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

Parameters

cd &Card
The Card instance used by this call (borrow).

Returns

bool — true or false

($&Card) painted

XuAPI
pub fn (cd $&Card) painted()

Purpose

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

Parameters

cd $&Card
The Card instance used by this call (exclusive borrow).

Returns

This call does not return a value.

($&Card) invalidate

XuAPI
pub fn (cd $&Card) invalidate()

Purpose

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

Parameters

cd $&Card
The Card instance used by this call (exclusive borrow).

Returns

This call does not return a value.

(&Card) is_enabled

XuAPI
pub fn (cd &Card) is_enabled() bool

Purpose

Return whether the control is currently enabled.

Parameters

cd &Card
The Card instance used by this call (borrow).

Returns

bool — true or false

($&Card) set_enabled

XuAPI
pub fn (cd $&Card) set_enabled(enabled bool)

Purpose

Operation on $&Card: set enabled.

Parameters

cd $&Card
The Card instance used by this call (exclusive borrow).
enabled bool
enabled (bool)

Returns

This call does not return a value.

(&Card) is_selected

XuAPI
pub fn (cd &Card) is_selected() bool

Purpose

Operation on &Card: whether it is selected.

Parameters

cd &Card
The Card instance used by this call (borrow).

Returns

bool — true or false

($&Card) set_selected

XuAPI
pub fn (cd $&Card) set_selected(selected bool)

Purpose

Operation on $&Card: set selected.

Parameters

cd $&Card
The Card instance used by this call (exclusive borrow).
selected bool
selected (bool)

Returns

This call does not return a value.

(&Card) is_invalid

XuAPI
pub fn (cd &Card) is_invalid() bool

Purpose

Operation on &Card: whether it is invalid.

Parameters

cd &Card
The Card instance used by this call (borrow).

Returns

bool — true or false

($&Card) set_invalid

XuAPI
pub fn (cd $&Card) set_invalid(invalid bool)

Purpose

Operation on $&Card: set invalid.

Parameters

cd $&Card
The Card instance used by this call (exclusive borrow).
invalid bool
invalid (bool)

Returns

This call does not return a value.

(&Card) is_focused

XuAPI
pub fn (cd &Card) is_focused() bool

Purpose

Return whether the control currently has input focus.

Parameters

cd &Card
The Card instance used by this call (borrow).

Returns

bool — true or false

($&Card) set_focus

XuAPI
pub fn (cd $&Card) set_focus(focused bool)

Purpose

Operation on $&Card: set focus.

Parameters

cd $&Card
The Card instance used by this call (exclusive borrow).
focused bool
focused (bool)

Returns

This call does not return a value.

(&Card) is_hovered

XuAPI
pub fn (cd &Card) is_hovered() bool

Purpose

Operation on &Card: whether it is hovered.

Parameters

cd &Card
The Card instance used by this call (borrow).

Returns

bool — true or false

($&Card) set_hovered

XuAPI
pub fn (cd $&Card) set_hovered(hovered bool)

Purpose

Operation on $&Card: set hovered.

Parameters

cd $&Card
The Card instance used by this call (exclusive borrow).
hovered bool
hovered (bool)

Returns

This call does not return a value.

(&Card) visual_state

XuAPI
pub fn (cd &Card) visual_state() int

Purpose

Operation on &Card: visual state.

Parameters

cd &Card
The Card instance used by this call (borrow).

Returns

int — a value of this type

(&Card) has_style

XuAPI
pub fn (cd &Card) has_style() bool

Purpose

Operation on &Card: whether it has style.

Parameters

cd &Card
The Card instance used by this call (borrow).

Returns

bool — true or false

(&Card) style_or

XuAPI
pub fn (cd &Card) style_or(styles &Styles) ControlStyle

Purpose

Operation on &Card: style or.

Parameters

cd &Card
The Card 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

($&Card) set_style

XuAPI
pub fn (cd $&Card) set_style(style &ControlStyle) int

Purpose

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

Parameters

cd $&Card
The Card 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

($&Card) clear_style

XuAPI
pub fn (cd $&Card) clear_style()

Purpose

Operation on $&Card: clear style.

Parameters

cd $&Card
The Card instance used by this call (exclusive borrow).

Returns

This call does not return a value.

(&Card) paint

XuAPI
pub fn (cd &Card) paint(frame $&draw.Frame,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

cd &Card
The Card instance used by this call (borrow).
frame $&draw.Frame
frame (exclusive borrow; may modify the original; type $&draw.Frame)
theme &Theme
theme (read-only borrow; caller keeps the original; type &Theme)

Returns

int — a value of this type

(&Card) measure_styled

XuAPI
pub fn (cd &Card) measure_styled(styles &Styles) layout.Size

Purpose

Operation on &Card: measure styled.

Parameters

cd &Card
The Card instance used by this call (borrow).
styles &Styles
styles (read-only borrow; caller keeps the original; type &Styles)

Returns

layout.Size — a value of this type

(&Card) measure_header_styled

XuAPI
pub fn (cd &Card) measure_header_styled(title $&StyledLabel,styles &Styles) layout.Size

Purpose

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

Parameters

cd &Card
The Card instance used by this call (borrow).
title $&StyledLabel
title (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

(&Card) paint_styled

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

Purpose

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

Parameters

cd &Card
The Card 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

(&Card) paint_header_styled

XuAPI
pub fn (cd &Card) paint_header_styled(frame $&draw.Frame,title $&StyledLabel,styles &Styles) int

Purpose

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

Parameters

cd &Card
The Card instance used by this call (borrow).
frame $&draw.Frame
frame (exclusive borrow; may modify the original; type $&draw.Frame)
title $&StyledLabel
title (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

Complete native example

Component Workshop · Back to Widgets