pub trait Canvas {
Show 13 methods
// Required methods
fn width(&self) -> u32;
fn height(&self) -> u32;
fn set_range(&mut self, range: Range<usize>, color: &[Color]);
fn get_range(&self, range: Range<usize>) -> &[Color];
// Provided methods
fn blit<C: Canvas>(
&mut self,
src_canvas: &C,
dst_x: i64,
dst_y: i64,
tint: Option<&Color>,
) { ... }
fn blit_rect<C: Canvas>(
&mut self,
src_canvas: &C,
src_x: u32,
src_y: u32,
width: u32,
height: u32,
dst_x: i64,
dst_y: i64,
tint: Option<&Color>,
) { ... }
fn get(&self, x: u32, y: u32) -> &Color { ... }
fn maybe_get(&self, x: i64, y: i64) -> Option<&Color> { ... }
fn is_empty_or_color(&self, x: i64, y: i64, color: &Color) -> bool { ... }
fn set(&mut self, x: u32, y: u32, color: &Color) { ... }
fn clip_rect(
&self,
x: i64,
y: i64,
width: u32,
height: u32,
) -> Option<(u32, u32, u32, u32)> { ... }
fn clear_screen(&mut self, color: &Color) { ... }
fn filled_rect(
&mut self,
sx: i64,
sy: i64,
width: u32,
height: u32,
color: &Color,
) { ... }
}Expand description
Trait representing a basic canvas that can be drawn to.
A canvas provides basic pixel manipulation operations and blitting capabilities for 2D graphics rendering as well as convenience methods for drawing shapes.
Different implementations of this trait exist to utilize different rendering backends like an ansi terminal (CrosstermCanvas), or a window (PixelsCanvas).
Required Methods§
Provided Methods§
Sourcefn blit<C: Canvas>(
&mut self,
src_canvas: &C,
dst_x: i64,
dst_y: i64,
tint: Option<&Color>,
)
fn blit<C: Canvas>( &mut self, src_canvas: &C, dst_x: i64, dst_y: i64, tint: Option<&Color>, )
Blit a full input canvas to this canvas instance at a given position, optionally tinting the input canvas with a color.
§Arguments
src_canvas- The source canvas to blit fromdst_x- The x position to blit the source canvas todst_y- The y position to blit the source canvas totint- An optional color to tint the source canvas with
Sourcefn blit_rect<C: Canvas>(
&mut self,
src_canvas: &C,
src_x: u32,
src_y: u32,
width: u32,
height: u32,
dst_x: i64,
dst_y: i64,
tint: Option<&Color>,
)
fn blit_rect<C: Canvas>( &mut self, src_canvas: &C, src_x: u32, src_y: u32, width: u32, height: u32, dst_x: i64, dst_y: i64, tint: Option<&Color>, )
Blit only a rectangular region of the input canvas to this canvas instance at a given position, optionally tinting the input canvas with a color. If the source rectangle is partially out of view, only the visible part will be blitted. If the destination rectangle is partially out of view, only the visible part will be blitted.
See also: blit_rect
Sourcefn maybe_get(&self, x: i64, y: i64) -> Option<&Color>
fn maybe_get(&self, x: i64, y: i64) -> Option<&Color>
Get the color of a specific pixel at a given position, if it is in bounds of the canvas.
§Returns
Some(&Color)- If the position is in boundsNone- If the position is out of bounds
Sourcefn is_empty_or_color(&self, x: i64, y: i64, color: &Color) -> bool
fn is_empty_or_color(&self, x: i64, y: i64, color: &Color) -> bool
Check if a specific pixel at a given position is out of bounds (empty) or has the specified color.
This method primarily can be used for pixel based collision detection.
Sourcefn set(&mut self, x: u32, y: u32, color: &Color)
fn set(&mut self, x: u32, y: u32, color: &Color)
Set the color of a specific pixel at a given position
Sourcefn clip_rect(
&self,
x: i64,
y: i64,
width: u32,
height: u32,
) -> Option<(u32, u32, u32, u32)>
fn clip_rect( &self, x: i64, y: i64, width: u32, height: u32, ) -> Option<(u32, u32, u32, u32)>
Clip a rectangle to the bounds of the canvas.
§Returns
Some((u32, u32, u32, u32))- If the rectangle is partially or fully in viewNone- If the rectangle is completely out of view
Sourcefn clear_screen(&mut self, color: &Color)
fn clear_screen(&mut self, color: &Color)
Clear (fill) the whole canvas with a specific color
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.