BlueGit

ict rusty-teams

Files

rusty-teams / vendor / gpui-base / src / element_ext.rs

element_ext.rs

eef6c0a4 History
element_ext.rs 1001 B Download Raw
1use gpui::{App, Bounds, IntoElement, ParentElement, Pixels, Styled as _, Window, canvas};
2
3use crate::TextSelectionScopeId;
4
5/// Extends a GPUI parent element with post-layout prepaint observation.
6pub trait ElementExt: ParentElement + Sized {
7 /// Marks this element subtree as belonging to a text-selection scope.
8 fn text_selection_scope(self, scope: TextSelectionScopeId) -> impl IntoElement
9 where
10 Self: IntoElement,
11 {
12 crate::text_selection::text_selection_scope(scope, self)
13 }
14
15 /// Invokes `callback` during prepaint with this element's resolved bounds.
16 fn on_prepaint<F>(self, callback: F) -> Self
17 where
18 F: FnOnce(Bounds<Pixels>, &mut Window, &mut App) + 'static,
19 {
20 self.child(
21 canvas(
22 move |bounds, window, cx| callback(bounds, window, cx),
23 |_, _, _, _| {},
24 )
25 .absolute()
26 .size_full(),
27 )
28 }
29}
30
31impl<T: ParentElement> ElementExt for T {}