pub trait Element: 'static + IntoElement {
type RequestLayoutState: 'static;
type PrepaintState: 'static;
// Required methods
fn id(&self) -> Option<ElementId>;
fn source_location(&self) -> Option<&'static Location<'static>>;
fn request_layout(
&mut self,
id: Option<&GlobalElementId>,
inspector_id: Option<&InspectorElementId>,
window: &mut Window,
cx: &mut App,
) -> (LayoutId, Self::RequestLayoutState);
fn prepaint(
&mut self,
id: Option<&GlobalElementId>,
inspector_id: Option<&InspectorElementId>,
bounds: Bounds<Pixels>,
request_layout: &mut Self::RequestLayoutState,
window: &mut Window,
cx: &mut App,
) -> Self::PrepaintState;
fn paint(
&mut self,
id: Option<&GlobalElementId>,
inspector_id: Option<&InspectorElementId>,
bounds: Bounds<Pixels>,
request_layout: &mut Self::RequestLayoutState,
prepaint: &mut Self::PrepaintState,
window: &mut Window,
cx: &mut App,
);
// Provided method
fn into_any(self) -> AnyElement { ... }
}Expand description
Implemented by types that participate in laying out and painting the contents of a window. Elements form a tree and are laid out according to web-based layout rules, as implemented by Taffy. You can create custom elements by implementing this trait, see the module-level documentation for more details.
Required Associated Types§
Sourcetype RequestLayoutState: 'static
type RequestLayoutState: 'static
The type of state returned from Element::request_layout. A mutable reference to this state is subsequently
provided to Element::prepaint and Element::paint.
Sourcetype PrepaintState: 'static
type PrepaintState: 'static
The type of state returned from Element::prepaint. A mutable reference to this state is subsequently
provided to Element::paint.
Required Methods§
Sourcefn id(&self) -> Option<ElementId>
fn id(&self) -> Option<ElementId>
If this element has a unique identifier, return it here. This is used to track elements across frames, and will cause a GlobalElementId to be passed to the request_layout, prepaint, and paint methods.
The global id can in turn be used to access state that’s connected to an element with the same id across frames. This id must be unique among children of the first containing element with an id.
Sourcefn source_location(&self) -> Option<&'static Location<'static>>
fn source_location(&self) -> Option<&'static Location<'static>>
Source location where this element was constructed, used to disambiguate elements in the inspector and navigate to their source code.
Sourcefn request_layout(
&mut self,
id: Option<&GlobalElementId>,
inspector_id: Option<&InspectorElementId>,
window: &mut Window,
cx: &mut App,
) -> (LayoutId, Self::RequestLayoutState)
fn request_layout( &mut self, id: Option<&GlobalElementId>, inspector_id: Option<&InspectorElementId>, window: &mut Window, cx: &mut App, ) -> (LayoutId, Self::RequestLayoutState)
Before an element can be painted, we need to know where it’s going to be and how big it is. Use this method to request a layout from Taffy and initialize the element’s state.
Sourcefn prepaint(
&mut self,
id: Option<&GlobalElementId>,
inspector_id: Option<&InspectorElementId>,
bounds: Bounds<Pixels>,
request_layout: &mut Self::RequestLayoutState,
window: &mut Window,
cx: &mut App,
) -> Self::PrepaintState
fn prepaint( &mut self, id: Option<&GlobalElementId>, inspector_id: Option<&InspectorElementId>, bounds: Bounds<Pixels>, request_layout: &mut Self::RequestLayoutState, window: &mut Window, cx: &mut App, ) -> Self::PrepaintState
After laying out an element, we need to commit its bounds to the current frame for hitbox
purposes. The state argument is the same state that was returned from Element::request_layout().
Sourcefn paint(
&mut self,
id: Option<&GlobalElementId>,
inspector_id: Option<&InspectorElementId>,
bounds: Bounds<Pixels>,
request_layout: &mut Self::RequestLayoutState,
prepaint: &mut Self::PrepaintState,
window: &mut Window,
cx: &mut App,
)
fn paint( &mut self, id: Option<&GlobalElementId>, inspector_id: Option<&InspectorElementId>, bounds: Bounds<Pixels>, request_layout: &mut Self::RequestLayoutState, prepaint: &mut Self::PrepaintState, window: &mut Window, cx: &mut App, )
Once layout has been completed, this method will be called to paint the element to the screen.
The state argument is the same state that was returned from Element::request_layout().
Provided Methods§
Sourcefn into_any(self) -> AnyElement
fn into_any(self) -> AnyElement
Convert this element into a dynamically-typed AnyElement.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.