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 duringgenerate_draw_commands.- Event handling (focus, IME) is dispatched through
engine::input.
Required Methods§
Sourcefn draw_sized(
&self,
cmd_buf: &mut Vec<DrawCommand>,
text_style: &TextStyle,
text_flow_style: &TextFlowStyle,
style: &Style,
size: ContentSize,
)
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.
Sourcefn intrinsic_size(&self) -> ContentSize
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§
Sourcefn draw(
&self,
cmd_buf: &mut Vec<DrawCommand>,
text_style: &TextStyle,
text_flow_style: &TextFlowStyle,
)
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.
Sourcefn popup(
&self,
_text_style: &TextStyle,
_text_flow_style: &TextFlowStyle,
) -> Option<Popup>
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.
Sourcefn preserves_intrinsic_aspect_ratio(&self) -> bool
fn preserves_intrinsic_aspect_ratio(&self) -> bool
Whether one resolved dimension should scale the other dimension using the node’s intrinsic aspect ratio.
Sourcefn accepts_text_input(&self) -> bool
fn accepts_text_input(&self) -> bool
Whether this node can receive keyboard and IME text input.
Sourcefn set_focused(&self, _focused: bool)
fn set_focused(&self, _focused: bool)
Updates keyboard focus for this node.
Sourcefn is_focused(&self) -> bool
fn is_focused(&self) -> bool
Returns whether this node currently owns keyboard focus.
Sourcefn handle_text_input(&self, _event: InputTextEvent) -> bool
fn handle_text_input(&self, _event: InputTextEvent) -> bool
Applies a platform-neutral text editing event.
Sourcefn is_composing(&self) -> bool
fn is_composing(&self) -> bool
Returns whether an IME preedit string is active.
Sourcefn on_popup_pointer_event(&self, _event: PointerEvent) -> bool
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.
Sourcefn dismiss_popup(&self)
fn dismiss_popup(&self)
Closes this node’s popup, if open (dismiss on an outside click).
Sourcefn on_pointer_event(&self, _event: PointerEvent) -> bool
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.
Sourcefn set_hovered(&self, _hovered: bool)
fn set_hovered(&self, _hovered: bool)
Updates the hover state for this node.
Sourcefn is_hovered(&self) -> bool
fn is_hovered(&self) -> bool
Returns whether this node is currently hovered.
Sourcefn needs_repaint(&self) -> bool
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.
Sourcefn composition_rect(&self) -> Option<(f32, f32, f32, f32)>
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.
Sourcefn role(&self) -> Option<&'static str>
fn role(&self) -> Option<&'static str>
Accessibility role for this node (e.g. "button", "textbox", "img").
Sourcefn is_disabled(&self) -> bool
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".