1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use conrod_core::{
    image,
    widget::{
        self,
        image::{State, Style},
    },
    Widget, WidgetCommon,
};

/// This widget is like conrod's `Image` widget except it always returns false
/// for is_over so widgets under it are still interactable
#[derive(WidgetCommon)]
pub struct GhostImage {
    #[conrod(common_builder)]
    common: widget::CommonBuilder,
    image_id: image::Id,
    style: Style,
}

impl GhostImage {
    pub fn new(image_id: image::Id) -> Self {
        Self {
            common: widget::CommonBuilder::default(),
            image_id,
            style: Style::default(),
        }
    }
}

impl Widget for GhostImage {
    type Event = ();
    type State = State;
    type Style = Style;

    fn init_state(&self, _: widget::id::Generator) -> Self::State {
        State {
            src_rect: None,
            image_id: self.image_id,
        }
    }

    fn style(&self) -> Self::Style { self.style }

    fn update(self, args: widget::UpdateArgs<Self>) -> Self::Event {
        let widget::UpdateArgs { state, .. } = args;

        if state.image_id != self.image_id {
            state.update(|state| state.image_id = self.image_id)
        }
    }

    // This is what we are here for
    fn is_over(&self) -> widget::IsOverFn { |_, _, _| widget::IsOver::Bool(false) }
}