Skip to main content

gpui_deck/
element_ext.rs

1// Modified for GPUI Deck: retain prepaint observation without rich-text scopes.
2use gpui::{App, Bounds, ParentElement, Pixels, Styled as _, Window, canvas};
3
4/// Extends a GPUI parent element with post-layout prepaint observation.
5pub trait ElementExt: ParentElement + Sized {
6    /// Invokes `callback` during prepaint with this element's resolved bounds.
7    fn on_prepaint<F>(self, callback: F) -> Self
8    where
9        F: FnOnce(Bounds<Pixels>, &mut Window, &mut App) + 'static,
10    {
11        self.child(
12            canvas(
13                move |bounds, window, cx| callback(bounds, window, cx),
14                |_, _, _, _| {},
15            )
16            // Without an inset, an absolute child starts after the padding but
17            // is still sized to the padding box, overhanging the far edges.
18            .absolute()
19            .top_0()
20            .left_0()
21            .size_full(),
22        )
23    }
24}
25
26impl<T: ParentElement> ElementExt for T {}