wgpui_base/
element_ext.rs1use wgpui::{App, Bounds, IntoElement, ParentElement, Pixels, Styled as _, Window, canvas};
2
3use crate::TextSelectionScopeId;
4
5pub trait TextSelectionScopeExt: Sized {
7 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
16impl<T: Sized> TextSelectionScopeExt for T {}
17
18pub trait ElementExt: ParentElement + Sized {
20 fn on_prepaint<F>(self, callback: F) -> Self
22 where
23 F: FnOnce(Bounds<Pixels>, &mut Window, &mut App) + 'static,
24 {
25 self.child(
26 canvas(
27 move |bounds, window, cx| callback(bounds, window, cx),
28 |_, _, _, _| {},
29 )
30 .absolute()
33 .top_0()
34 .left_0()
35 .size_full(),
36 )
37 }
38}
39
40impl<T: ParentElement> ElementExt for T {}