Skip to main content

CustomRenderObject

Trait CustomRenderObject 

Source
pub trait CustomRenderObject:
    Send
    + Sync
    + Debug {
    // Provided methods
    fn is_runtime_dynamic(&self) -> bool { ... }
    fn accepts_text_input(&self) -> bool { ... }
    fn hit_test(
        &self,
        local_point: LayoutPoint,
        node_rect: LayoutRect,
    ) -> CustomHitResult { ... }
    fn handle_event(
        &self,
        node_id: NodeId,
        event: &InputEvent,
        node_rect: LayoutRect,
    ) -> CustomEventResult { ... }
    fn ime_cursor_area(&self, _node_rect: LayoutRect) -> Option<LayoutRect> { ... }
    fn blur_actions(&self, _node_id: NodeId) -> Vec<(NodeId, ActionEnvelope)> { ... }
    fn paint(&self, node_rect: LayoutRect) -> Vec<PaintOp> { ... }
}
Expand description

Extension point for custom nodes that need to participate in rendering, hit-testing, and event handling.

Implementors are stored behind Arc<dyn CustomRenderObject> so they must be Send + Sync. The trait is object-safe.

Provided Methods§

Source

fn is_runtime_dynamic(&self) -> bool

Whether this render object should be treated as runtime-dynamic by the retained pipeline even when the surrounding widget tree is otherwise static.

Source

fn accepts_text_input(&self) -> bool

Whether this custom render object participates in text input / IME.

Source

fn hit_test( &self, local_point: LayoutPoint, node_rect: LayoutRect, ) -> CustomHitResult

Hit-test the custom content.

local_point is relative to the top-left corner of the node’s layout rect. node_rect is the absolute layout rect for reference.

The default implementation returns a hit whenever the point is inside node_rect.

Source

fn handle_event( &self, node_id: NodeId, event: &InputEvent, node_rect: LayoutRect, ) -> CustomEventResult

Handle an input event targeted at (or bubbling through) this node.

node_id is the IR node that owns this render object. event is the original input event.

Returning CustomEventResult { handled: true, .. } prevents further propagation through the standard controller chain.

Source

fn ime_cursor_area(&self, _node_rect: LayoutRect) -> Option<LayoutRect>

Platform IME cursor area for this render object, in absolute layout coordinates.

Source

fn blur_actions(&self, _node_id: NodeId) -> Vec<(NodeId, ActionEnvelope)>

Actions to dispatch if this render object loses focus.

Source

fn paint(&self, node_rect: LayoutRect) -> Vec<PaintOp>

Produce paint operations for this custom content.

The returned PaintOps are appended to the display list at the position corresponding to this node. An empty vec means the node paints nothing extra (it might still have children that paint).

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§