blob: 09baa9c9af0141de3d4479f476aebc13d645c822 (
plain)
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
|
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<CoreShape>) {
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);
}
}
}
}
|