Element

Trait Element 

Source
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§

Source

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.

Source

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§

Source

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.

Source

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.

Source

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.

Source

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().

Source

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§

Source

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.

Implementations on Foreign Types§

Source§

impl Element for &'static str

Source§

type RequestLayoutState = TextLayout

Source§

type PrepaintState = ()

Source§

fn id(&self) -> Option<ElementId>

Source§

fn source_location(&self) -> Option<&'static Location<'static>>

Source§

fn request_layout( &mut self, _id: Option<&GlobalElementId>, _inspector_id: Option<&InspectorElementId>, window: &mut Window, cx: &mut App, ) -> (LayoutId, Self::RequestLayoutState)

Source§

fn prepaint( &mut self, _id: Option<&GlobalElementId>, _inspector_id: Option<&InspectorElementId>, bounds: Bounds<Pixels>, text_layout: &mut Self::RequestLayoutState, _window: &mut Window, _cx: &mut App, )

Source§

fn paint( &mut self, _id: Option<&GlobalElementId>, _inspector_id: Option<&InspectorElementId>, _bounds: Bounds<Pixels>, text_layout: &mut TextLayout, _: &mut (), window: &mut Window, cx: &mut App, )

Implementors§

Source§

impl Element for Anchored

Source§

impl Element for AnyElement

Source§

impl Element for AnyView

Source§

impl Element for Deferred

Source§

impl Element for Div

Source§

impl Element for Empty

Source§

impl Element for ImageCacheElement

Source§

impl Element for Img

Source§

impl Element for InteractiveText

Source§

impl Element for List

Source§

impl Element for SharedString

Source§

impl Element for StyledText

Source§

impl Element for Surface

Source§

impl Element for Svg

Source§

impl Element for UniformList

Source§

impl<E> Element for Stateful<E>
where E: Element,

Source§

impl<E: IntoElement + 'static> Element for AnimationElement<E>

Source§

impl<T: 'static> Element for Canvas<T>

Source§

impl<V: Render> Element for Entity<V>