| 1 | use gpui::{App, Bounds, IntoElement, ParentElement, Pixels, Styled as _, Window, canvas}; |
| 2 | |
| 3 | use crate::TextSelectionScopeId; |
| 4 | |
| 5 | /// Extends a GPUI parent element with post-layout prepaint observation. |
| 6 | pub 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 | |
| 31 | impl<T: ParentElement> ElementExt for T {} |