Skip to main content

CustomNode

Trait CustomNode 

Source
pub trait CustomNode:
    Debug
    + Send
    + Sync
    + 'static {
Show 21 methods // Required methods fn draw_sized( &self, cmd_buf: &mut Vec<DrawCommand>, text_style: &TextStyle, text_flow_style: &TextFlowStyle, style: &Style, size: ContentSize, ); fn intrinsic_size(&self) -> ContentSize; // Provided methods fn draw( &self, cmd_buf: &mut Vec<DrawCommand>, text_style: &TextStyle, text_flow_style: &TextFlowStyle, ) { ... } fn popup( &self, _text_style: &TextStyle, _text_flow_style: &TextFlowStyle, ) -> Option<Popup> { ... } fn preserves_intrinsic_aspect_ratio(&self) -> bool { ... } fn accepts_text_input(&self) -> bool { ... } fn set_focused(&self, _focused: bool) { ... } fn is_focused(&self) -> bool { ... } fn handle_text_input(&self, _event: InputTextEvent) -> bool { ... } fn is_composing(&self) -> bool { ... } fn on_popup_pointer_event(&self, _event: PointerEvent) -> bool { ... } fn dismiss_popup(&self) { ... } fn on_pointer_event(&self, _event: PointerEvent) -> bool { ... } fn set_hovered(&self, _hovered: bool) { ... } fn is_hovered(&self) -> bool { ... } fn needs_repaint(&self) -> bool { ... } fn composition_rect(&self) -> Option<(f32, f32, f32, f32)> { ... } fn role(&self) -> Option<&'static str> { ... } fn label(&self) -> Option<String> { ... } fn value(&self) -> Option<String> { ... } fn is_disabled(&self) -> bool { ... }
}
Expand description

Trait for custom/replaced elements that produce their own draw commands.

§Coordinate System

Commands must be emitted in the content-box coordinate space: (0, 0) = top-left of the content box. The parent’s transform/clip stack handles positioning.

§Lifecycle

  • draw_sized() is called every frame during generate_draw_commands.
  • Event handling (focus, IME) is dispatched through engine::input.

Required Methods§

Source

fn draw_sized( &self, cmd_buf: &mut Vec<DrawCommand>, text_style: &TextStyle, text_flow_style: &TextFlowStyle, style: &Style, size: ContentSize, )

Emit draw commands fitted to the resolved content-box size.

text_style carries the inherited CSS text properties (color, font-size, font-weight, etc.) resolved for this element. style carries the resolved ui_layout::Style (CSS width/height, box-sizing, etc.) and size is the resolved content-box size.

This is the primary drawing entry point.

Source

fn intrinsic_size(&self) -> ContentSize

Intrinsic (content-box) size in pixels.

The layout engine uses this to size the element when no explicit width/height is set via CSS.

Provided Methods§

Source

fn draw( &self, cmd_buf: &mut Vec<DrawCommand>, text_style: &TextStyle, text_flow_style: &TextFlowStyle, )

Emit draw commands using the intrinsic content-box size.

Defaults to draw_sized with the intrinsic size and a default style. Components that only draw at their intrinsic size may override this instead.

Source

fn popup( &self, _text_style: &TextStyle, _text_flow_style: &TextFlowStyle, ) -> Option<Popup>

Returns the node’s open popup (top-layer overlay), if any.

The popup is re-generated every frame; returning None closes it. Commands use the same content-box coordinate space as draw_sized.

Source

fn preserves_intrinsic_aspect_ratio(&self) -> bool

Whether one resolved dimension should scale the other dimension using the node’s intrinsic aspect ratio.

Source

fn accepts_text_input(&self) -> bool

Whether this node can receive keyboard and IME text input.

Source

fn set_focused(&self, _focused: bool)

Updates keyboard focus for this node.

Source

fn is_focused(&self) -> bool

Returns whether this node currently owns keyboard focus.

Source

fn handle_text_input(&self, _event: InputTextEvent) -> bool

Applies a platform-neutral text editing event.

Source

fn is_composing(&self) -> bool

Returns whether an IME preedit string is active.

Source

fn on_popup_pointer_event(&self, _event: PointerEvent) -> bool

Dispatches a pointer event on the node’s open popup.

Coordinates are relative to the popup’s top-left (the popup.rect origin in content-box coordinates). The engine only dispatches while a popup is open; nodes without a popup can ignore this.

Source

fn dismiss_popup(&self)

Closes this node’s popup, if open (dismiss on an outside click).

Source

fn on_pointer_event(&self, _event: PointerEvent) -> bool

Dispatches a platform-neutral pointer event.

Coordinates are relative to the content box. Returns true when the node consumed the event.

Source

fn set_hovered(&self, _hovered: bool)

Updates the hover state for this node.

Source

fn is_hovered(&self) -> bool

Returns whether this node is currently hovered.

Source

fn needs_repaint(&self) -> bool

Whether this node changed its visual state since the last check.

Consumes the flag: calling it again without an intervening state change returns false. The engine uses this to skip full redraws when no custom node is dirty.

Source

fn composition_rect(&self) -> Option<(f32, f32, f32, f32)>

Screen rectangle of the active IME composition underline, in content-box coordinates (x, y, width, height). None when nothing is composing.

Source

fn role(&self) -> Option<&'static str>

Accessibility role for this node (e.g. "button", "textbox", "img").

Source

fn label(&self) -> Option<String>

Accessibility label (accessible name).

Source

fn value(&self) -> Option<String>

Current value for editable/stateful nodes.

Source

fn is_disabled(&self) -> bool

Whether this node is disabled and must not receive input.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§