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
// Wrapper for drawable objects

use ggez::graphics::{self, Canvas, Drawable, Image, Mesh, Text};

pub enum DrawableObject {
    Text(Text),
    Image(Image),
    Mesh(Mesh),
}

impl Drawable for DrawableObject {
    fn draw(&self, canvas: &mut Canvas, param: impl Into<graphics::DrawParam>) {
        match self {
            DrawableObject::Text(text) => {
                canvas.draw(text, param);
            }
            DrawableObject::Image(image) => {
                canvas.draw(image, param);
            }
            DrawableObject::Mesh(mesh) => {
                canvas.draw(mesh, param);
            }
        }
    }

    fn dimensions(
        &self,
        gfx: &impl ggez::context::Has<graphics::GraphicsContext>,
    ) -> Option<graphics::Rect> {
        match self {
            DrawableObject::Text(text) => text.dimensions(gfx),
            DrawableObject::Image(image) => image.dimensions(gfx),
            DrawableObject::Mesh(mesh) => mesh.dimensions(gfx),
        }
    }
}