pub trait RenderBackend {
// Required methods
fn clear(&mut self, color: Color);
fn fill_rect(&mut self, x: f32, y: f32, w: f32, h: f32, color: Color);
fn fill_circle(&mut self, cx: f32, cy: f32, radius: f32, color: Color);
fn stroke_circle(
&mut self,
cx: f32,
cy: f32,
radius: f32,
color: Color,
width: f32,
);
fn stroke_arc(
&mut self,
cx: f32,
cy: f32,
radius: f32,
start_angle: f32,
end_angle: f32,
color: Color,
width: f32,
);
fn draw_line(
&mut self,
x1: f32,
y1: f32,
x2: f32,
y2: f32,
color: Color,
width: f32,
);
fn draw_text(&mut self, text: &str, x: f32, y: f32, size: f32, color: Color);
fn text_width(&self, text: &str, size: f32) -> f32;
// Provided method
fn present(&mut self) { ... }
}Expand description
Abstraction over rendering backends (CPU via tiny-skia, future GPU via wgpu).
All coordinates are in pixels. The CPU backend renders to an in-memory RGBA buffer; a GPU backend would render via Metal/DX12/Vulkan.
Required Methods§
Sourcefn stroke_circle(
&mut self,
cx: f32,
cy: f32,
radius: f32,
color: Color,
width: f32,
)
fn stroke_circle( &mut self, cx: f32, cy: f32, radius: f32, color: Color, width: f32, )
Stroke a circle outline.
Sourcefn stroke_arc(
&mut self,
cx: f32,
cy: f32,
radius: f32,
start_angle: f32,
end_angle: f32,
color: Color,
width: f32,
)
fn stroke_arc( &mut self, cx: f32, cy: f32, radius: f32, start_angle: f32, end_angle: f32, color: Color, width: f32, )
Stroke an arc (portion of a circle).
Sourcefn draw_line(
&mut self,
x1: f32,
y1: f32,
x2: f32,
y2: f32,
color: Color,
width: f32,
)
fn draw_line( &mut self, x1: f32, y1: f32, x2: f32, y2: f32, color: Color, width: f32, )
Draw a line between two points.
Sourcefn draw_text(&mut self, text: &str, x: f32, y: f32, size: f32, color: Color)
fn draw_text(&mut self, text: &str, x: f32, y: f32, size: f32, color: Color)
Draw text using the embedded TrueType font (fontdue).
Sourcefn text_width(&self, text: &str, size: f32) -> f32
fn text_width(&self, text: &str, size: f32) -> f32
Measure the width of a text string in pixels.