pixel_handler/structs/
drawable_object.rs1use ggez::graphics::{self, Canvas, Drawable, Image, Mesh, Text};
4
5pub enum DrawableObject {
6 Text(Text),
7 Image(Image),
8 Mesh(Mesh),
9}
10
11impl Drawable for DrawableObject {
12 fn draw(&self, canvas: &mut Canvas, param: impl Into<graphics::DrawParam>) {
13 match self {
14 DrawableObject::Text(text) => {
15 canvas.draw(text, param);
16 }
17 DrawableObject::Image(image) => {
18 canvas.draw(image, param);
19 }
20 DrawableObject::Mesh(mesh) => {
21 canvas.draw(mesh, param);
22 }
23 }
24 }
25
26 fn dimensions(
27 &self,
28 gfx: &impl ggez::context::Has<graphics::GraphicsContext>,
29 ) -> Option<graphics::Rect> {
30 match self {
31 DrawableObject::Text(text) => text.dimensions(gfx),
32 DrawableObject::Image(image) => image.dimensions(gfx),
33 DrawableObject::Mesh(mesh) => mesh.dimensions(gfx),
34 }
35 }
36}