plotine_render/
renderer.rs1use kurbo::BezPath;
2use plotine_core::{Point, Rect, Result};
3
4use crate::primitives::{FillStyle, StrokeStyle, TextStyle};
5
6pub trait Renderer {
15 fn clear(&mut self, color: plotine_core::Color) -> Result<()>;
16
17 fn fill_rect(&mut self, rect: Rect, style: &FillStyle) -> Result<()>;
18
19 fn stroke_rect(&mut self, rect: Rect, style: &StrokeStyle) -> Result<()>;
20
21 fn fill_path(&mut self, path: &BezPath, style: &FillStyle) -> Result<()>;
22
23 fn stroke_path(&mut self, path: &BezPath, style: &StrokeStyle) -> Result<()>;
24
25 fn draw_line(&mut self, p0: Point, p1: Point, style: &StrokeStyle) -> Result<()> {
26 let mut path = BezPath::new();
27 path.move_to(p0.to_kurbo());
28 path.line_to(p1.to_kurbo());
29 self.stroke_path(&path, style)
30 }
31
32 fn draw_text(&mut self, text: &str, position: Point, style: &TextStyle) -> Result<()>;
33
34 fn draw_rgba_image(
39 &mut self,
40 rgba: &[u8],
41 width: u32,
42 height: u32,
43 position: Point,
44 ) -> Result<()>;
45
46 fn measure_text(&self, text: &str, size_px: f32) -> Result<(f64, f64)> {
48 self.measure_text_styled(text, size_px, false)
49 }
50
51 fn measure_text_styled(&self, text: &str, size_px: f32, italic: bool) -> Result<(f64, f64)>;
53
54 fn push_clip_rect(&mut self, rect: Rect) -> Result<()>;
56
57 fn pop_clip(&mut self) -> Result<()>;
58
59 fn width(&self) -> u32;
60 fn height(&self) -> u32;
61}