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 methods
fn a11y_role(&self) -> Option<Role> { ... }
fn write_a11y_info(&self, _node: &mut Node) { ... }
fn a11y_synthetic_children(
&mut self,
_prepaint: &mut Self::PrepaintState,
_builder: &mut A11ySubtreeBuilder<'_>,
) { ... }
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 a11y_role(&self) -> Option<Role>
fn a11y_role(&self) -> Option<Role>
Returns the accessible role for this element, if any.
Elements that return None are not included in the accessibility tree.
Note: inclusion in accessibility tree requires non-None id.
See the accessibility guide for an overview.
Sourcefn write_a11y_info(&self, _node: &mut Node)
fn write_a11y_info(&self, _node: &mut Node)
Write accessibility properties to the given node.
Called only when a11y_role() returns Some.
See the accessibility guide for an overview.
Sourcefn a11y_synthetic_children(
&mut self,
_prepaint: &mut Self::PrepaintState,
_builder: &mut A11ySubtreeBuilder<'_>,
)
fn a11y_synthetic_children( &mut self, _prepaint: &mut Self::PrepaintState, _builder: &mut A11ySubtreeBuilder<'_>, )
Add synthetic child nodes to an Element that has an
.id() and a .role().
Some elements may want to inject accessibility nodes that do not correspond to any GPUI element. For example, a custom text field element may want to inject synthetic child nodes for the text content.
See Synthetic children in the accessibility guide for more detail.
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".
Implementations on Foreign Types§
Source§impl Element for &'static str
impl Element for &'static str
type RequestLayoutState = TextLayout
type PrepaintState = ()
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, <&'static str as Element>::RequestLayoutState)
fn prepaint( &mut self, _id: Option<&GlobalElementId>, _inspector_id: Option<&InspectorElementId>, bounds: Bounds<Pixels>, text_layout: &mut <&'static str as Element>::RequestLayoutState, _window: &mut Window, _cx: &mut App, )
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, )
Source§impl Element for MotionReveal
impl Element for MotionReveal
type RequestLayoutState = ()
type PrepaintState = ()
fn id(&self) -> Option<ElementId>
fn source_location(&self) -> Option<&'static Location<'static>>
fn request_layout( &mut self, global_id: Option<&GlobalElementId>, _: Option<&InspectorElementId>, window: &mut Window, cx: &mut App, ) -> (LayoutId, <MotionReveal as Element>::RequestLayoutState)
fn prepaint( &mut self, global_id: Option<&GlobalElementId>, _: Option<&InspectorElementId>, bounds: Bounds<Pixels>, _: &mut <MotionReveal as Element>::RequestLayoutState, window: &mut Window, cx: &mut App, ) -> <MotionReveal as Element>::PrepaintState
fn paint( &mut self, _: Option<&GlobalElementId>, _: Option<&InspectorElementId>, bounds: Bounds<Pixels>, _: &mut <MotionReveal as Element>::RequestLayoutState, _: &mut <MotionReveal as Element>::PrepaintState, window: &mut Window, cx: &mut App, )
Source§impl Element for PlotAppearScope
impl Element for PlotAppearScope
type RequestLayoutState = (Option<AnyElement>, Rc<RefCell<HashMap<GlobalElementId, u64>>>)
type PrepaintState = ()
fn id(&self) -> Option<ElementId>
fn source_location(&self) -> Option<&'static Location<'static>>
fn request_layout( &mut self, global_id: Option<&GlobalElementId>, _: Option<&InspectorElementId>, window: &mut Window, cx: &mut App, ) -> (LayoutId, <PlotAppearScope as Element>::RequestLayoutState)
fn prepaint( &mut self, _: Option<&GlobalElementId>, _: Option<&InspectorElementId>, _: Bounds<Pixels>, _: &mut <PlotAppearScope as Element>::RequestLayoutState, window: &mut Window, cx: &mut App, ) -> <PlotAppearScope as Element>::PrepaintState
fn paint( &mut self, _: Option<&GlobalElementId>, _: Option<&InspectorElementId>, _: Bounds<Pixels>, _: &mut <PlotAppearScope as Element>::RequestLayoutState, _: &mut <PlotAppearScope as Element>::PrepaintState, window: &mut Window, cx: &mut App, )
Source§impl Element for Positioner
impl Element for Positioner
type RequestLayoutState = PositionerState
type PrepaintState = ()
fn id(&self) -> Option<ElementId>
fn source_location(&self) -> Option<&'static Location<'static>>
fn request_layout( &mut self, _: Option<&GlobalElementId>, _: Option<&InspectorElementId>, window: &mut Window, cx: &mut App, ) -> (LayoutId, <Positioner as Element>::RequestLayoutState)
fn prepaint( &mut self, _: Option<&GlobalElementId>, _: Option<&InspectorElementId>, bounds: Bounds<Pixels>, request_layout: &mut <Positioner as Element>::RequestLayoutState, window: &mut Window, cx: &mut App, )
fn paint( &mut self, _: Option<&GlobalElementId>, _: Option<&InspectorElementId>, _: Bounds<Pixels>, _: &mut <Positioner as Element>::RequestLayoutState, _: &mut <Positioner as Element>::PrepaintState, window: &mut Window, cx: &mut App, )
Source§impl Element for RoundedFrameCover
impl Element for RoundedFrameCover
type RequestLayoutState = ()
type PrepaintState = Bounds<Pixels>
fn id(&self) -> Option<ElementId>
fn source_location(&self) -> Option<&'static Location<'static>>
fn request_layout( &mut self, _: Option<&GlobalElementId>, _: Option<&InspectorElementId>, window: &mut Window, cx: &mut App, ) -> (LayoutId, <RoundedFrameCover as Element>::RequestLayoutState)
fn prepaint( &mut self, _: Option<&GlobalElementId>, _: Option<&InspectorElementId>, bounds: Bounds<Pixels>, _: &mut <RoundedFrameCover as Element>::RequestLayoutState, _: &mut Window, _: &mut App, ) -> <RoundedFrameCover as Element>::PrepaintState
fn paint( &mut self, _: Option<&GlobalElementId>, _: Option<&InspectorElementId>, _: Bounds<Pixels>, _: &mut <RoundedFrameCover as Element>::RequestLayoutState, cover_bounds: &mut <RoundedFrameCover as Element>::PrepaintState, window: &mut Window, cx: &mut App, )
Source§impl Element for ScrollBounce
impl Element for ScrollBounce
type RequestLayoutState = ()
type PrepaintState = ScrollBouncePrepaintState
fn id(&self) -> Option<ElementId>
fn source_location(&self) -> Option<&'static Location<'static>>
fn request_layout( &mut self, _: Option<&GlobalElementId>, _: Option<&InspectorElementId>, window: &mut Window, cx: &mut App, ) -> (LayoutId, ())
fn prepaint( &mut self, id: Option<&GlobalElementId>, _: Option<&InspectorElementId>, bounds: Bounds<Pixels>, _: &mut (), window: &mut Window, cx: &mut App, ) -> <ScrollBounce as Element>::PrepaintState
fn paint( &mut self, _: Option<&GlobalElementId>, _: Option<&InspectorElementId>, bounds: Bounds<Pixels>, _: &mut (), prepaint: &mut <ScrollBounce as Element>::PrepaintState, window: &mut Window, cx: &mut App, )
Source§impl Element for Scrollbar
impl Element for Scrollbar
type RequestLayoutState = ()
type PrepaintState = PrepaintState
fn id(&self) -> Option<ElementId>
fn source_location(&self) -> Option<&'static Location<'static>>
fn request_layout( &mut self, _: Option<&GlobalElementId>, _: Option<&InspectorElementId>, window: &mut Window, cx: &mut App, ) -> (LayoutId, <Scrollbar as Element>::RequestLayoutState)
fn prepaint( &mut self, _: Option<&GlobalElementId>, _: Option<&InspectorElementId>, bounds: Bounds<Pixels>, _: &mut <Scrollbar as Element>::RequestLayoutState, window: &mut Window, cx: &mut App, ) -> <Scrollbar as Element>::PrepaintState
fn paint( &mut self, _: Option<&GlobalElementId>, _: Option<&InspectorElementId>, _: Bounds<Pixels>, _: &mut <Scrollbar as Element>::RequestLayoutState, prepaint: &mut <Scrollbar as Element>::PrepaintState, window: &mut Window, cx: &mut App, )
Source§impl Element for SelectableText
impl Element for SelectableText
type RequestLayoutState = TextSelectionHandle
type PrepaintState = Hitbox
fn id(&self) -> Option<ElementId>
fn source_location(&self) -> Option<&'static Location<'static>>
fn request_layout( &mut self, global_id: Option<&GlobalElementId>, inspector_id: Option<&InspectorElementId>, window: &mut Window, cx: &mut App, ) -> (LayoutId, <SelectableText as Element>::RequestLayoutState)
fn prepaint( &mut self, global_id: Option<&GlobalElementId>, inspector_id: Option<&InspectorElementId>, bounds: Bounds<Pixels>, handle: &mut <SelectableText as Element>::RequestLayoutState, window: &mut Window, cx: &mut App, ) -> <SelectableText as Element>::PrepaintState
fn paint( &mut self, global_id: Option<&GlobalElementId>, inspector_id: Option<&InspectorElementId>, bounds: Bounds<Pixels>, handle: &mut <SelectableText as Element>::RequestLayoutState, _: &mut <SelectableText as Element>::PrepaintState, window: &mut Window, cx: &mut App, )
Source§impl Element for TextSelectionLayer
impl Element for TextSelectionLayer
type RequestLayoutState = ()
type PrepaintState = TextSelectionLayerPrepaintState
fn id(&self) -> Option<ElementId>
fn source_location(&self) -> Option<&'static Location<'static>>
fn request_layout( &mut self, _: Option<&GlobalElementId>, _: Option<&InspectorElementId>, window: &mut Window, cx: &mut App, ) -> (LayoutId, <TextSelectionLayer as Element>::RequestLayoutState)
fn prepaint( &mut self, global_id: Option<&GlobalElementId>, _: Option<&InspectorElementId>, _: Bounds<Pixels>, _: &mut <TextSelectionLayer as Element>::RequestLayoutState, window: &mut Window, cx: &mut App, ) -> <TextSelectionLayer as Element>::PrepaintState
fn paint( &mut self, _: Option<&GlobalElementId>, _: Option<&InspectorElementId>, _: Bounds<Pixels>, _: &mut <TextSelectionLayer as Element>::RequestLayoutState, state: &mut <TextSelectionLayer as Element>::PrepaintState, window: &mut Window, cx: &mut App, )
Source§impl Element for TextView
impl Element for TextView
type RequestLayoutState = TextViewLayoutState
type PrepaintState = TextViewPrepaintState
fn id(&self) -> Option<ElementId>
fn source_location(&self) -> Option<&'static Location<'static>>
fn request_layout( &mut self, _: Option<&GlobalElementId>, _: Option<&InspectorElementId>, window: &mut Window, cx: &mut App, ) -> (LayoutId, <TextView as Element>::RequestLayoutState)
fn prepaint( &mut self, _: Option<&GlobalElementId>, _: Option<&InspectorElementId>, bounds: Bounds<Pixels>, request_layout: &mut <TextView as Element>::RequestLayoutState, window: &mut Window, cx: &mut App, ) -> <TextView as Element>::PrepaintState
fn paint( &mut self, _: Option<&GlobalElementId>, _: Option<&InspectorElementId>, bounds: Bounds<Pixels>, request_layout: &mut <TextView as Element>::RequestLayoutState, prepaint: &mut <TextView as Element>::PrepaintState, window: &mut Window, cx: &mut App, )
Source§impl Element for TextView
impl Element for TextView
type RequestLayoutState = TextViewLayoutState
type PrepaintState = TextViewPrepaintState
fn id(&self) -> Option<ElementId>
fn source_location(&self) -> Option<&'static Location<'static>>
fn request_layout( &mut self, _: Option<&GlobalElementId>, _: Option<&InspectorElementId>, window: &mut Window, cx: &mut App, ) -> (LayoutId, <TextView as Element>::RequestLayoutState)
fn prepaint( &mut self, _: Option<&GlobalElementId>, _: Option<&InspectorElementId>, _: Bounds<Pixels>, element: &mut <TextView as Element>::RequestLayoutState, window: &mut Window, cx: &mut App, ) -> <TextView as Element>::PrepaintState
fn paint( &mut self, _: Option<&GlobalElementId>, _: Option<&InspectorElementId>, _: Bounds<Pixels>, element: &mut <TextView as Element>::RequestLayoutState, _: &mut <TextView as Element>::PrepaintState, window: &mut Window, cx: &mut App, )
Source§impl Element for VirtualList
impl Element for VirtualList
type RequestLayoutState = VirtualListFrameState
type PrepaintState = Option<Hitbox>
fn id(&self) -> Option<ElementId>
fn source_location(&self) -> Option<&'static Location<'static>>
fn request_layout( &mut self, global_id: Option<&GlobalElementId>, inspector_id: Option<&InspectorElementId>, window: &mut Window, cx: &mut App, ) -> (LayoutId, <VirtualList as Element>::RequestLayoutState)
fn prepaint( &mut self, global_id: Option<&GlobalElementId>, inspector_id: Option<&InspectorElementId>, bounds: Bounds<Pixels>, layout: &mut <VirtualList as Element>::RequestLayoutState, window: &mut Window, cx: &mut App, ) -> <VirtualList as Element>::PrepaintState
fn paint( &mut self, global_id: Option<&GlobalElementId>, inspector_id: Option<&InspectorElementId>, bounds: Bounds<Pixels>, layout: &mut <VirtualList as Element>::RequestLayoutState, hitbox: &mut <VirtualList as Element>::PrepaintState, window: &mut Window, cx: &mut App, )
Source§impl<E> Element for ContextMenu<E>
impl<E> Element for ContextMenu<E>
type RequestLayoutState = ContextMenuState
type PrepaintState = Hitbox
fn id(&self) -> Option<ElementId>
fn source_location(&self) -> Option<&'static Location<'static>>
fn request_layout( &mut self, id: Option<&GlobalElementId>, _: Option<&InspectorElementId>, window: &mut Window, cx: &mut App, ) -> (LayoutId, <ContextMenu<E> as Element>::RequestLayoutState)
fn prepaint( &mut self, _: Option<&GlobalElementId>, _: Option<&InspectorElementId>, bounds: Bounds<Pixels>, request_layout: &mut <ContextMenu<E> as Element>::RequestLayoutState, window: &mut Window, cx: &mut App, ) -> <ContextMenu<E> as Element>::PrepaintState
fn paint( &mut self, _: Option<&GlobalElementId>, _: Option<&InspectorElementId>, _: Bounds<Pixels>, request_layout: &mut <ContextMenu<E> as Element>::RequestLayoutState, hitbox: &mut <ContextMenu<E> as Element>::PrepaintState, window: &mut Window, cx: &mut App, )
Source§impl<H> Element for ScrollableMask<H>where
H: ScrollbarHandle + Clone,
impl<H> Element for ScrollableMask<H>where
H: ScrollbarHandle + Clone,
type RequestLayoutState = ()
type PrepaintState = Hitbox
fn id(&self) -> Option<ElementId>
fn source_location(&self) -> Option<&'static Location<'static>>
fn request_layout( &mut self, _: Option<&GlobalElementId>, _: Option<&InspectorElementId>, window: &mut Window, cx: &mut App, ) -> (LayoutId, <ScrollableMask<H> as Element>::RequestLayoutState)
fn prepaint( &mut self, _: Option<&GlobalElementId>, _: Option<&InspectorElementId>, bounds: Bounds<Pixels>, _: &mut <ScrollableMask<H> as Element>::RequestLayoutState, window: &mut Window, _: &mut App, ) -> <ScrollableMask<H> as Element>::PrepaintState
fn paint( &mut self, global_id: Option<&GlobalElementId>, _: Option<&InspectorElementId>, _: Bounds<Pixels>, _: &mut <ScrollableMask<H> as Element>::RequestLayoutState, hitbox: &mut <ScrollableMask<H> as Element>::PrepaintState, window: &mut Window, _: &mut App, )
Source§impl<P> Element for PlotElement<P>where
P: Plot + 'static,
impl<P> Element for PlotElement<P>where
P: Plot + 'static,
type RequestLayoutState = ()
type PrepaintState = (Option<Hitbox>, Vec<AnyElement>, Option<AnyElement>)
fn id(&self) -> Option<ElementId>
fn source_location(&self) -> Option<&'static Location<'static>>
fn request_layout( &mut self, _: Option<&GlobalElementId>, _: Option<&InspectorElementId>, window: &mut Window, cx: &mut App, ) -> (LayoutId, <PlotElement<P> as Element>::RequestLayoutState)
fn prepaint( &mut self, global_id: Option<&GlobalElementId>, _: Option<&InspectorElementId>, bounds: Bounds<Pixels>, _: &mut <PlotElement<P> as Element>::RequestLayoutState, window: &mut Window, cx: &mut App, ) -> <PlotElement<P> as Element>::PrepaintState
fn paint( &mut self, global_id: Option<&GlobalElementId>, _: Option<&InspectorElementId>, bounds: Bounds<Pixels>, _: &mut <PlotElement<P> as Element>::RequestLayoutState, prepaint: &mut <PlotElement<P> as Element>::PrepaintState, window: &mut Window, cx: &mut App, )
Source§impl<T, E> Element for ResizeHandle<T, E>where
T: 'static,
E: 'static + Render,
impl<T, E> Element for ResizeHandle<T, E>where
T: 'static,
E: 'static + Render,
Source§type PrepaintState = Hitbox
type PrepaintState = Hitbox
The band’s own hitbox, so the listeners in paint can ask whether the
pointer is really on the handle rather than merely within its bounds.