Skip to main content

rosace_widgets/tree/
pointer.rs

1use super::{Widget, Children, PaintCtx};
2
3/// Makes its subtree transparent to the pointer — clicks, scrolls, and hover
4/// pass straight through to whatever is behind it. Useful for decorative
5/// overlays that must not steal input.
6///
7/// ```rust,ignore
8/// IgnorePointer::new(decorative_badge_overlay)
9/// ```
10pub struct IgnorePointer<W: Widget> { child: W }
11
12impl<W: Widget + Send + Sync + 'static> IgnorePointer<W> {
13    pub fn new(child: W) -> Self { Self { child } }
14}
15
16impl<W: Widget + Send + Sync + 'static> Widget for IgnorePointer<W> {
17    fn children(&self) -> Children<'_> { Children::One(&self.child) }
18    fn paint(&self, ctx: &mut PaintCtx) {
19        ctx.set_pointer_mode(1); // transparent
20        let r = ctx.rect;
21        self.child.paint(&mut ctx.child(r));
22    }
23}
24
25/// Absorbs every pointer event over its rect — nothing inside or behind
26/// receives clicks/scrolls. Useful for disabling a region or building a
27/// modal barrier.
28pub struct AbsorbPointer<W: Widget> { child: W }
29
30impl<W: Widget + Send + Sync + 'static> AbsorbPointer<W> {
31    pub fn new(child: W) -> Self { Self { child } }
32}
33
34impl<W: Widget + Send + Sync + 'static> Widget for AbsorbPointer<W> {
35    fn children(&self) -> Children<'_> { Children::One(&self.child) }
36    fn paint(&self, ctx: &mut PaintCtx) {
37        ctx.set_pointer_mode(2); // absorb
38        let r = ctx.rect;
39        self.child.paint(&mut ctx.child(r));
40    }
41}