gemini_engine/containers/
visibility_toggle.rs1use crate::core::CanDraw;
2
3use super::CanCollide;
4
5#[derive(Debug, Clone)]
7pub struct VisibilityToggle<E: CanDraw> {
8 pub element: E,
10 pub visible: bool,
12}
13
14impl<E: CanDraw> VisibilityToggle<E> {
15 pub const fn new(element: E) -> Self {
17 Self {
18 element,
19 visible: true,
20 }
21 }
22}
23
24impl<E: CanDraw> CanDraw for VisibilityToggle<E> {
25 fn draw_to(&self, canvas: &mut impl crate::core::Canvas) {
26 if self.visible {
27 self.element.draw_to(canvas);
28 }
29 }
30}
31
32impl<E: CanDraw + CanCollide> CanCollide for VisibilityToggle<E> {
33 fn collides_with_pos(&self, pos: crate::core::Vec2D) -> bool {
34 if self.visible {
35 self.element.collides_with_pos(pos)
36 } else {
37 false
38 }
39 }
40}