identified.rs

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