pub trait ElementExt: Any {
Show 21 methods
// Provided methods
fn into_element(self) -> Element
where Self: Sized + Into<Element> { ... }
fn changed(&self, _other: &Rc<dyn ElementExt>) -> bool { ... }
fn diff(&self, _other: &Rc<dyn ElementExt>) -> DiffModifies { ... }
fn layout(&self) -> Cow<'_, LayoutData> { ... }
fn accessibility(&self) -> Cow<'_, AccessibilityData> { ... }
fn effect(&self) -> Option<Cow<'_, EffectData>> { ... }
fn style(&self) -> Cow<'_, StyleState> { ... }
fn is_transparent(&self) -> bool { ... }
fn text_style(&self) -> Cow<'_, TextStyleData> { ... }
fn layer(&self) -> Layer { ... }
fn events_handlers(&self) -> Option<Cow<'_, EventHandlers>> { ... }
fn measure(
&self,
_context: LayoutContext<'_>,
) -> Option<(Size2D, Rc<dyn Any>)> { ... }
fn should_hook_measurement(&self) -> bool { ... }
fn should_measure_inner_children(&self) -> bool { ... }
fn needs_post_measure(&self) -> bool { ... }
fn post_measure(
&self,
_context: PostMeasureContext<'_>,
) -> PostMeasure<NodeId> { ... }
fn is_point_inside(&self, context: EventMeasurementContext<'_>) -> bool { ... }
fn clip(&self, _context: ClipContext<'_>) { ... }
fn render(&self, _context: RenderContext<'_>) { ... }
fn render_rect(&self, area: &Area, scale_factor: f32) -> SkRRect { ... }
fn finish_accessibility(&self, _builder: &mut Node) { ... }
}Expand description
Tells Freya how to lay out, handle events for, describe accessibility and draw an element.
To make your own element, implement this trait and override what you need. For example,
render draws it, layout supplies its layout,
measure gives it a custom size, and is_point_inside
changes how pointer hits are detected. Everything has a default, so you can start with just
the methods your element needs. Override changed and diff
when changes to its data need to update the UI.
To put it in the UI tree, implement From<YourElement> for Element (or otherwise make it
convertible into Element). You can also implement builder traits like LayoutExt to let
callers set its properties. Freya stores elements as Rc<dyn ElementExt>, so they must be
'static through the Any.
See feature_element.rs
for a full example.
Provided Methods§
Sourcefn into_element(self) -> Element
fn into_element(self) -> Element
Converts this value into an Element if it implements Into<Element>.
Sourcefn changed(&self, _other: &Rc<dyn ElementExt>) -> bool
fn changed(&self, _other: &Rc<dyn ElementExt>) -> bool
Returns whether this element has changed compared to another one.
Sourcefn diff(&self, _other: &Rc<dyn ElementExt>) -> DiffModifies
fn diff(&self, _other: &Rc<dyn ElementExt>) -> DiffModifies
Tells Freya what needs updating when this element changes.
Sourcefn layout(&self) -> Cow<'_, LayoutData>
fn layout(&self) -> Cow<'_, LayoutData>
Returns layout properties used to position and size this element.
Sourcefn accessibility(&self) -> Cow<'_, AccessibilityData>
fn accessibility(&self) -> Cow<'_, AccessibilityData>
Returns accessibility properties for this element.
Sourcefn effect(&self) -> Option<Cow<'_, EffectData>>
fn effect(&self) -> Option<Cow<'_, EffectData>>
Returns optional effect properties for this element.
Sourcefn style(&self) -> Cow<'_, StyleState>
fn style(&self) -> Cow<'_, StyleState>
Returns visual style properties for this element.
Sourcefn is_transparent(&self) -> bool
fn is_transparent(&self) -> bool
Whether the element paints nothing, letting events fall through to non-ancestor elements behind it.
Sourcefn text_style(&self) -> Cow<'_, TextStyleData>
fn text_style(&self) -> Cow<'_, TextStyleData>
Returns text styling inherited by text content in this element.
Sourcefn events_handlers(&self) -> Option<Cow<'_, EventHandlers>>
fn events_handlers(&self) -> Option<Cow<'_, EventHandlers>>
Returns event handlers registered on this element.
Sourcefn measure(&self, _context: LayoutContext<'_>) -> Option<(Size2D, Rc<dyn Any>)>
fn measure(&self, _context: LayoutContext<'_>) -> Option<(Size2D, Rc<dyn Any>)>
Measures the element and optionally returns measurement data for later layout stages.
Sourcefn should_hook_measurement(&self) -> bool
fn should_hook_measurement(&self) -> bool
Returns whether this element hooks into layout measurement.
Sourcefn should_measure_inner_children(&self) -> bool
fn should_measure_inner_children(&self) -> bool
Returns whether to measure this element’s children.
Sourcefn needs_post_measure(&self) -> bool
fn needs_post_measure(&self) -> bool
Whether this element needs a ElementExt::post_measure step after the layout pass.
Sourcefn post_measure(&self, _context: PostMeasureContext<'_>) -> PostMeasure<NodeId>
fn post_measure(&self, _context: PostMeasureContext<'_>) -> PostMeasure<NodeId>
Runs after this element and its children are measured.
Sourcefn is_point_inside(&self, context: EventMeasurementContext<'_>) -> bool
fn is_point_inside(&self, context: EventMeasurementContext<'_>) -> bool
Tests whether the pointer position is inside this element’s hit area.
Sourcefn clip(&self, _context: ClipContext<'_>)
fn clip(&self, _context: ClipContext<'_>)
Applies clipping for this element before it and its children are rendered.
Sourcefn render(&self, _context: RenderContext<'_>)
fn render(&self, _context: RenderContext<'_>)
Renders this element using the supplied canvas and layout context.
Sourcefn render_rect(&self, area: &Area, scale_factor: f32) -> SkRRect
fn render_rect(&self, area: &Area, scale_factor: f32) -> SkRRect
Creates a rounded rectangle from an area using this element’s corner radius.
Sourcefn finish_accessibility(&self, _builder: &mut Node)
fn finish_accessibility(&self, _builder: &mut Node)
Mutates the accessibility node immediately before it enters the accessibility tree.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".