index : snake-rs
An implementation of the classic Snake game in Rust using SDL2
about summary refs log tree commit diff

Diffstat (limited to 'src/ui_components/mod.rs')

-rw-r--r-- src/ui_components/mod.rs 45
 1 file changed, 45 deletions(-)

diff --git a/src/ui_components/mod.rs b/src/ui_components/mod.rs
deleted file mode 100644
index 471175d..0000000 100644
--- a/src/ui_components/mod.rs
+++ /dev/null
@@ -1,45 +1,0 @@
use sdl2::{pixels::Color, rect::Rect};

use crate::{game_context::{GameEvent, Point}, ui_components::{button::Button, text::Text}};

pub mod button;
pub mod text;

pub struct Ui {
    pub buttons: Vec<Button>,
    pub texts: Vec<Text>,
}

impl Ui {
    pub fn new() -> Self {
        Self {
            buttons: vec![],
            texts: vec![],
        }
    }

    pub fn button(&mut self, x: i32, y: i32, width: u32, height: u32, text: &str, event: GameEvent) -> &mut Button {
        self.buttons.push(Button {
            rect: Rect::new(x, y, width, height),
            color: Color::RGB(0, 120, 215),
            text: text.to_string(),
            event
        });
        self.buttons.last_mut().unwrap()
    }

    pub fn text(&mut self, text: &str, color: Color, point: Point) -> &mut Text {
        self.texts.push(Text {
            text: text.to_string(),
            color,
            point

        });
        self.texts.last_mut().unwrap()
    }

    pub fn clear(&mut self) {
        self.buttons.clear();
        self.texts.clear();
    }
}