gdrust_trinkets/ui/grid/
grid_container.rs

1use godot::obj::WithBaseField;
2use godot::classes::IContainer;
3use godot::prelude::*;
4use godot::classes::InputEventMouseButton;
5
6pub trait ObjectContainer: IContainer + WithBaseField {
7    // This prevents the Cursor from handling events that the container will later handle
8    fn will_handle(&self, event: Gd<InputEventMouseButton>) -> bool {
9        let base = self.base();
10        godot_print!("{}, {}", base.get_global_rect(), event.get_global_position());
11        base.get_global_rect().contains_point(event.get_global_position())
12    }
13}
14
15pub struct ContainerSystem<T> where T: ObjectContainer {
16    pub containers: Vec<Gd<T>>
17}
18
19impl<T: ObjectContainer> Default for ContainerSystem<T> {
20    fn default() -> Self {
21        ContainerSystem { containers: Vec::<Gd<T>>::new() }
22    }
23}
24
25impl<T> ContainerSystem<T> where T: ObjectContainer {
26    pub fn handled(&self, event: Gd<InputEventMouseButton>) -> bool {
27        self.containers.iter()
28            .any(|x| x.bind().will_handle(event.clone()))
29    }
30}