1use gpui::{
2 App, ClickEvent, InteractiveElement, OngoingScroll, Pixels, Point, Stateful,
3 StatefulInteractiveElement, TouchPhase, Window,
4};
5
6pub trait OngoingScrollExt {
12 fn lock_axis(&mut self, delta: &mut Point<Pixels>, touch_phase: TouchPhase);
15}
16
17impl OngoingScrollExt for OngoingScroll {
18 fn lock_axis(&mut self, delta: &mut Point<Pixels>, touch_phase: TouchPhase) {
19 #[cfg(target_family = "wasm")]
20 let _ = (delta, touch_phase);
21 #[cfg(not(target_family = "wasm"))]
22 self.filter(delta, touch_phase);
23 }
24}
25
26pub trait InteractiveElementExt: InteractiveElement {
27 fn lock_scroll_axis(self) -> Self
30 where
31 Self: Sized + StatefulInteractiveElement,
32 {
33 #[cfg(target_family = "wasm")]
34 {
35 self
36 }
37 #[cfg(not(target_family = "wasm"))]
38 {
39 self.restrict_scroll_to_axis()
40 }
41 }
42
43 fn on_double_click(
45 mut self,
46 listener: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static,
47 ) -> Self
48 where
49 Self: Sized,
50 {
51 self.interactivity().on_click(move |event, window, cx| {
52 if event.click_count() == 2 {
53 listener(event, window, cx);
54 }
55 });
56 self
57 }
58}
59
60impl<E: InteractiveElement> InteractiveElementExt for Stateful<E> {}