euv_ui/hook/use_scroll/fn.rs
1use super::*;
2
3/// Obtains the [`UseScroll`] registered against the current hook context
4/// slot.
5///
6/// Behaves like `HookContext::use_hook` - the same handle is returned on
7/// every render at the same hook index, so the window listener is
8/// attached once and the offsets survive re-renders.
9///
10/// # Returns
11///
12/// - `UseScroll` - The handle, with `get_x()` and `get_y()` returning
13/// the reactive scroll offset signals.
14pub fn use_scroll() -> UseScroll {
15 let handle: UseScroll = HookContext::use_hook(|| {
16 let handle: UseScroll = UseScroll::new();
17 handle.attach();
18 handle
19 });
20 App::use_cleanup({
21 let handle: UseScroll = handle.clone();
22 move || handle.detach()
23 });
24 handle
25}