use gpui::{
App, Bounds, Element, ElementId, GlobalElementId, InspectorElementId, IntoElement, LayoutId,
};
pub(crate) struct BoundsTrackerElement {
pub(crate) bounds_state: gpui::Entity<Bounds<gpui::Pixels>>,
pub(crate) inner: gpui::AnyElement,
}
impl IntoElement for BoundsTrackerElement {
type Element = Self;
fn into_element(self) -> Self::Element {
self
}
}
impl Element for BoundsTrackerElement {
type RequestLayoutState = ();
type PrepaintState = ();
fn id(&self) -> Option<ElementId> {
None
}
fn source_location(&self) -> Option<&'static core::panic::Location<'static>> {
None
}
fn request_layout(
&mut self,
_id: Option<&GlobalElementId>,
_inspector_id: Option<&InspectorElementId>,
window: &mut gpui::Window,
cx: &mut App,
) -> (LayoutId, Self::RequestLayoutState) {
(self.inner.request_layout(window, cx), ())
}
fn prepaint(
&mut self,
_id: Option<&GlobalElementId>,
_inspector_id: Option<&InspectorElementId>,
bounds: Bounds<gpui::Pixels>,
_request_layout: &mut Self::RequestLayoutState,
window: &mut gpui::Window,
cx: &mut App,
) -> Self::PrepaintState {
self.bounds_state.update(cx, |state, _| *state = bounds);
self.inner.prepaint(window, cx);
}
fn paint(
&mut self,
_id: Option<&GlobalElementId>,
_inspector_id: Option<&InspectorElementId>,
_bounds: Bounds<gpui::Pixels>,
_request_layout: &mut Self::RequestLayoutState,
_prepaint: &mut Self::PrepaintState,
window: &mut gpui::Window,
cx: &mut App,
) {
self.inner.paint(window, cx);
}
}