Skip to main content

Widget

Trait Widget 

Source
pub trait Widget {
    // Provided methods
    fn connected(&mut self) { ... }
    fn disconnected(&mut self) { ... }
    fn attribute_changed(
        &mut self,
        name: &str,
        old_value: Option<&str>,
        new_value: Option<&str>,
    ) { ... }
    fn can_create_surfaces(&mut self, render_ctx: &mut dyn RenderContext) { ... }
    fn destroy_surfaces(&mut self) { ... }
    fn handle_event(&mut self, event: &UiEvent) { ... }
    fn paint(
        &mut self,
        render_ctx: &mut dyn RenderContext,
        styles: &ComputedStyles,
        width: u32,
        height: u32,
        scale: f64,
    ) -> Scene { ... }
}

Provided Methods§

Source

fn connected(&mut self)

The widget was attached to the DOM

Source

fn disconnected(&mut self)

The widget was removed from the DOM

Source

fn attribute_changed( &mut self, name: &str, old_value: Option<&str>, new_value: Option<&str>, )

One of the widget’s attributes changed

Source

fn can_create_surfaces(&mut self, render_ctx: &mut dyn RenderContext)

The renderer is active

ctx parameter can be downcast to get access to renderer-specific contexts (e.g. the WGPU Device and Queue)

Source

fn destroy_surfaces(&mut self)

The renderer is no longer active (destroy textures here)

Source

fn handle_event(&mut self, event: &UiEvent)

Handle input events (mouse, keyboard, etc)

Source

fn paint( &mut self, render_ctx: &mut dyn RenderContext, styles: &ComputedStyles, width: u32, height: u32, scale: f64, ) -> Scene

Callback for the widget to paint it’s content.

Output is recorded to an AnyRender Scene. If the widget wants to render to a WGPU texture or similar then it should:

  • Get a handle to the Device and Queue in can_create_surfaces
  • Create it’s own texture
  • Pass the ResourceId of the paint for an Image in the AnyRender Scene

Implementors§