pub trait RenderBackend {
Show 21 methods
// Required methods
fn clear(&self);
fn clear_with_color(&self, color: &str);
fn save(&self);
fn restore(&self);
fn set_fill_color(&self, color: &str);
fn set_stroke_color(&self, color: &str);
fn set_line_width(&self, width: f64);
fn set_global_alpha(&self, alpha: f64);
fn set_blend_mode(&self, mode: BlendMode);
fn set_shadow(&self, config: &ShadowConfig);
fn clear_shadow(&self);
fn fill_rect(&self, position: Vector2D, width: f64, height: f64);
fn stroke_rect(&self, position: Vector2D, width: f64, height: f64);
fn fill_circle(&self, center: Vector2D, radius: f64);
fn stroke_circle(&self, center: Vector2D, radius: f64);
fn draw_line(&self, start: Vector2D, end: Vector2D);
fn fill_text(&self, text: &str, position: Vector2D);
fn set_font(&self, font: &str);
fn draw_image(
&self,
image: &HtmlImageElement,
position: Vector2D,
width: f64,
height: f64,
);
fn set_linear_gradient_fill(&self, gradient: &LinearGradient);
fn set_radial_gradient_fill(&self, gradient: &RadialGradient);
}Expand description
An abstract rendering backend that decouples draw calls from the concrete canvas API, enabling future backends such as WebGL or WebGPU.
All methods mirror the CanvasRenderingContext2d interface so that
CanvasRenderer can implement this trait with zero overhead.
Required Methods§
Sourcefn clear_with_color(&self, color: &str)
fn clear_with_color(&self, color: &str)
Clears the viewport and fills it with the given CSS color string.
§Arguments
&str- The CSS color string (e.g.,"#000000").
Sourcefn set_fill_color(&self, color: &str)
fn set_fill_color(&self, color: &str)
Sourcefn set_stroke_color(&self, color: &str)
fn set_stroke_color(&self, color: &str)
Sourcefn set_line_width(&self, width: f64)
fn set_line_width(&self, width: f64)
Sourcefn set_global_alpha(&self, alpha: f64)
fn set_global_alpha(&self, alpha: f64)
Sets the global alpha (opacity) for all subsequent drawing operations.
§Arguments
f64- The alpha value in the range 0.0 to 1.0.
Sourcefn set_blend_mode(&self, mode: BlendMode)
fn set_blend_mode(&self, mode: BlendMode)
Sets the blend mode for compositing subsequent draw operations.
§Arguments
BlendMode- The blend mode to apply.
Sourcefn set_shadow(&self, config: &ShadowConfig)
fn set_shadow(&self, config: &ShadowConfig)
Applies a shadow configuration for subsequent draw operations.
§Arguments
&ShadowConfig- The shadow configuration to apply.
Sourcefn clear_shadow(&self)
fn clear_shadow(&self)
Clears any previously applied shadow, disabling shadow rendering.
Sourcefn fill_rect(&self, position: Vector2D, width: f64, height: f64)
fn fill_rect(&self, position: Vector2D, width: f64, height: f64)
Fills a rectangle at the given world-space position and dimensions.
§Arguments
Vector2D- The top-left position in world space.f64- The width.f64- The height.
Sourcefn stroke_rect(&self, position: Vector2D, width: f64, height: f64)
fn stroke_rect(&self, position: Vector2D, width: f64, height: f64)
Strokes the outline of a rectangle at the given world-space position and dimensions.
§Arguments
Vector2D- The top-left position in world space.f64- The width.f64- The height.
Sourcefn fill_circle(&self, center: Vector2D, radius: f64)
fn fill_circle(&self, center: Vector2D, radius: f64)
Fills a circle at the given world-space center with the specified radius.
§Arguments
Vector2D- The center in world space.f64- The radius.
Sourcefn stroke_circle(&self, center: Vector2D, radius: f64)
fn stroke_circle(&self, center: Vector2D, radius: f64)
Strokes the outline of a circle at the given world-space center.
§Arguments
Vector2D- The center in world space.f64- The radius.
Sourcefn draw_line(&self, start: Vector2D, end: Vector2D)
fn draw_line(&self, start: Vector2D, end: Vector2D)
Draws a line segment between two world-space points.
§Arguments
Vector2D- The start point.Vector2D- The end point.
Sourcefn fill_text(&self, text: &str, position: Vector2D)
fn fill_text(&self, text: &str, position: Vector2D)
Fills text at the given world-space position.
§Arguments
&str- The text to draw.Vector2D- The position in world space.
Sourcefn set_font(&self, font: &str)
fn set_font(&self, font: &str)
Sets the font for subsequent text rendering.
§Arguments
&str- The CSS font string (e.g.,"16px sans-serif").
Sourcefn draw_image(
&self,
image: &HtmlImageElement,
position: Vector2D,
width: f64,
height: f64,
)
fn draw_image( &self, image: &HtmlImageElement, position: Vector2D, width: f64, height: f64, )
Draws an image element at the given world-space position and dimensions.
§Arguments
&HtmlImageElement- The image element to draw.Vector2D- The top-left position in world space.f64- The destination width.f64- The destination height.
Sourcefn set_linear_gradient_fill(&self, gradient: &LinearGradient)
fn set_linear_gradient_fill(&self, gradient: &LinearGradient)
Applies a linear gradient as the fill style for subsequent operations.
§Arguments
&LinearGradient- The linear gradient to use as fill style.
Sourcefn set_radial_gradient_fill(&self, gradient: &RadialGradient)
fn set_radial_gradient_fill(&self, gradient: &RadialGradient)
Applies a radial gradient as the fill style for subsequent operations.
§Arguments
&RadialGradient- The radial gradient to use as fill style.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
impl RenderBackend for CanvasRenderer
Implements the RenderBackend trait for CanvasRenderer, providing
a backend-agnostic rendering interface.