truce_gui/render.rs
1//! Render backend trait for abstracting over CPU and GPU rendering.
2//!
3//! Widgets draw through this trait, making them backend-agnostic.
4
5use crate::theme::Color;
6
7/// Abstraction over rendering backends (CPU via tiny-skia, future GPU via wgpu).
8///
9/// All coordinates are in pixels. The CPU backend renders to an in-memory
10/// RGBA buffer; a GPU backend would render via Metal/DX12/Vulkan.
11pub trait RenderBackend {
12 /// Clear the entire surface with a solid color.
13 fn clear(&mut self, color: Color);
14
15 /// Fill a rectangle.
16 fn fill_rect(&mut self, x: f32, y: f32, w: f32, h: f32, color: Color);
17
18 /// Fill a circle.
19 fn fill_circle(&mut self, cx: f32, cy: f32, radius: f32, color: Color);
20
21 /// Stroke a circle outline.
22 fn stroke_circle(&mut self, cx: f32, cy: f32, radius: f32, color: Color, width: f32);
23
24 /// Stroke an arc (portion of a circle).
25 fn stroke_arc(
26 &mut self,
27 cx: f32,
28 cy: f32,
29 radius: f32,
30 start_angle: f32,
31 end_angle: f32,
32 color: Color,
33 width: f32,
34 );
35
36 /// Draw a line between two points.
37 fn draw_line(&mut self, x1: f32, y1: f32, x2: f32, y2: f32, color: Color, width: f32);
38
39 /// Draw text using the embedded TrueType font (fontdue).
40 fn draw_text(&mut self, text: &str, x: f32, y: f32, size: f32, color: Color);
41
42 /// Measure the width of a text string in pixels.
43 fn text_width(&self, text: &str, size: f32) -> f32;
44
45 /// Flush rendering to the display surface.
46 ///
47 /// No-op for CPU backends (pixels are read directly from the buffer).
48 /// GPU backends submit their command buffer and present here.
49 fn present(&mut self) {}
50}