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 requires_redraw(&self) -> bool { ... }
fn handle_event(&mut self, event: &UiEvent) { ... }
fn paint(
&mut self,
render_ctx: &mut dyn RenderContext,
styles: &ComputedValues,
width: u32,
height: u32,
scale: f64,
) -> Scene { ... }
}Provided Methods§
Sourcefn disconnected(&mut self)
fn disconnected(&mut self)
The widget was removed from the DOM
Sourcefn attribute_changed(
&mut self,
name: &str,
old_value: Option<&str>,
new_value: Option<&str>,
)
fn attribute_changed( &mut self, name: &str, old_value: Option<&str>, new_value: Option<&str>, )
One of the widget’s attributes changed
Sourcefn can_create_surfaces(&mut self, render_ctx: &mut dyn RenderContext)
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)
Sourcefn destroy_surfaces(&mut self)
fn destroy_surfaces(&mut self)
The renderer is no longer active (destroy textures here)
Sourcefn requires_redraw(&self) -> bool
fn requires_redraw(&self) -> bool
Whether the widget currently requires redraws (e.g. because it is animating).
Returning true causes the document to continuously schedule redraws
(and hence repaints of the widget). Static widgets should return false.
Sourcefn handle_event(&mut self, event: &UiEvent)
fn handle_event(&mut self, event: &UiEvent)
Handle input events (mouse, keyboard, etc)
Sourcefn paint(
&mut self,
render_ctx: &mut dyn RenderContext,
styles: &ComputedValues,
width: u32,
height: u32,
scale: f64,
) -> Scene
fn paint( &mut self, render_ctx: &mut dyn RenderContext, styles: &ComputedValues, 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
ResourceIdof the paint for an Image in the AnyRenderScene
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".