use super::Engine; use crate::core::{shapes::Shape as CoreShape, types::DefinitelyBounded}; use cairo::Context; pub struct CairoEngine { ctx: Context, } impl Engine for CairoEngine { fn new() -> Self { let surface = cairo::SvgSurface::for_stream(200., 100., std::io::stdout()).unwrap(); let ctx = cairo::Context::new(&surface); CairoEngine { ctx } } fn draw(&mut self, shape: &DefinitelyBounded) { let bounds = &shape.bounds; self.ctx.move_to(bounds.left, bounds.top); match &shape.shape { CoreShape::Rectangle(_rectangle) => { self.ctx .rectangle(bounds.left, bounds.top, bounds.width, bounds.height); self.ctx.stroke(); } CoreShape::Text(text) => { // TODO: properly shape it, with font, etc. self.ctx.show_text(&text.content); } } } }