1use crate::{BorrowWindow, Bounds, Element, ElementId, LayoutId, StatefulElement, ViewContext};
2use anyhow::Result;
3
4pub struct Identified<E> {
5 pub(crate) element: E,
6 pub(crate) id: ElementId,
7}
8
9impl<E: Element> Element for Identified<E> {
10 type State = E::State;
11 type FrameState = E::FrameState;
12
13 fn element_id(&self) -> Option<ElementId> {
14 Some(self.id.clone())
15 }
16
17 fn layout(
18 &mut self,
19 state: &mut Self::State,
20 cx: &mut ViewContext<Self::State>,
21 ) -> Result<(LayoutId, Self::FrameState)> {
22 self.element.layout(state, cx)
23 }
24
25 fn paint(
26 &mut self,
27 bounds: Bounds<crate::Pixels>,
28 state: &mut Self::State,
29 frame_state: &mut Self::FrameState,
30 cx: &mut ViewContext<Self::State>,
31 ) -> Result<()> {
32 cx.with_element_id(self.id.clone(), |cx| {
33 self.element.paint(bounds, state, frame_state, cx)
34 })
35 }
36}
37
38impl<E: Element> StatefulElement for Identified<E> {}