interactive.rs

 1use gpui::{platform::MouseMovedEvent, EventContext};
 2use smallvec::SmallVec;
 3use std::rc::Rc;
 4
 5pub trait Interactive<V: 'static> {
 6    fn interaction_handlers(&mut self) -> &mut InteractionHandlers<V>;
 7
 8    fn on_mouse_move<H>(mut self, handler: H) -> Self
 9    where
10        H: 'static + Fn(&mut V, &MouseMovedEvent, bool, &mut EventContext<V>),
11        Self: Sized,
12    {
13        self.interaction_handlers()
14            .mouse_moved
15            .push(Rc::new(move |view, event, hit_test, cx| {
16                handler(view, event, hit_test, cx);
17                cx.bubble
18            }));
19        self
20    }
21}
22
23pub struct InteractionHandlers<V: 'static> {
24    mouse_moved:
25        SmallVec<[Rc<dyn Fn(&mut V, &MouseMovedEvent, bool, &mut EventContext<V>) -> bool>; 2]>,
26}
27
28impl<V> Default for InteractionHandlers<V> {
29    fn default() -> Self {
30        Self {
31            mouse_moved: Default::default(),
32        }
33    }
34}