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 methods
fn present(&mut self) { ... }
fn register_image(
&mut self,
_rgba: &[u8],
_width: u32,
_height: u32,
) -> ImageId { ... }
fn unregister_image(&mut self, _id: ImageId) { ... }
fn draw_image(&mut self, _id: ImageId, x: f32, y: f32, w: f32, h: f32) { ... }
}Expand description
Abstraction over rendering backends (CPU via tiny-skia, GPU via wgpu).
Coordinate contract. All coordinates and font sizes are in
logical points. Backends own the display scale factor
internally and multiply inputs by it at raster time, so a widget
drawn at (100, 100) with size = 14.0 has the same apparent
size on 1× and 2× displays. Callers must not pre-multiply by
scale.
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 logical points, at the given logical-point font size.
Provided Methods§
Sourcefn present(&mut self)
fn present(&mut self)
Flush rendering to the display surface.
No-op for CPU backends (pixels are read directly from the buffer). GPU backends submit their command buffer and present here.
Sourcefn register_image(&mut self, _rgba: &[u8], _width: u32, _height: u32) -> ImageId
fn register_image(&mut self, _rgba: &[u8], _width: u32, _height: u32) -> ImageId
Register an RGBA8 image (premultiplied alpha, row-major, tightly packed).
Returned id is valid until unregister_image is called or the backend
is dropped. Returns ImageId::INVALID if the backend does not
support images.
Sourcefn unregister_image(&mut self, _id: ImageId)
fn unregister_image(&mut self, _id: ImageId)
Remove a previously-registered image. No-op if the id is invalid or already unregistered.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
impl RenderBackend for CpuBackend
All RenderBackend methods accept coordinates in logical
points. The backend multiplies by self.scale before handing
off to tiny-skia, so the pixmap is rasterized at physical-pixel
density.