pub struct CrosstermCanvas { /* private fields */ }Expand description
A canvas implementation that renders to the terminal using crossterm.
This canvas provides terminal-based rendering using Unicode half blocks and ANSI colors. It supports frame rate limiting and efficient updates by only redrawing changed parts of the screen.
§Example
use pixel_loop::canvas::CrosstermCanvas;
use pixel_loop::color::*;
use pixel_loop::canvas::Canvas;
use pixel_loop::canvas::RenderableCanvas;
use std::ops::Range;
use anyhow::Result;
fn main() -> Result<()> {
let mut canvas = CrosstermCanvas::new(80, 24);
canvas.filled_rect(5, 5, 10, 10, &Color::from_rgb(255, 0, 0));
// Should of course be called within the [pixel_loop::run] function.
canvas.render()?;
Ok(())
}Implementations§
Source§impl CrosstermCanvas
impl CrosstermCanvas
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new terminal canvas automatically toking the size of the terminal it is spawned in.
A canvas based on the terminals size is resizable by default.
§Example
use pixel_loop::canvas::CrosstermCanvas;
let canvas = CrosstermCanvas::new();Sourcepub fn new_with_size(width: u32, height: u32) -> Self
pub fn new_with_size(width: u32, height: u32) -> Self
Creates a new terminal canvas with the specified dimensions.
A canvas with specified dimensions is not resizable by default.
§Arguments
width- The width of the canvas in charactersheight- The height of the canvas in half characters
§Example
use pixel_loop::canvas::CrosstermCanvas;
let canvas = CrosstermCanvas::new(80, 42);Sourcepub fn with_resizable(self, resizable: bool) -> Self
pub fn with_resizable(self, resizable: bool) -> Self
Sets the canvas to be resizable or not.
Sourcepub fn with_refresh_limit(self, limit: usize) -> Self
pub fn with_refresh_limit(self, limit: usize) -> Self
Trait Implementations§
Source§impl Canvas for CrosstermCanvas
impl Canvas for CrosstermCanvas
Source§fn set_range(&mut self, range: Range<usize>, color: &[Color])
fn set_range(&mut self, range: Range<usize>, color: &[Color])
Set a range of pixels to a given Color
Source§fn get_range(&self, range: Range<usize>) -> &[Color]
fn get_range(&self, range: Range<usize>) -> &[Color]
Get a range of pixels as a slice of Colors
Source§fn 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. Read more
Source§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 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. Read more
Source§fn 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. Read more
Source§fn 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. Read more
Source§fn 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
Source§fn 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. Read more
Source§fn clear_screen(&mut self, color: &Color)
fn clear_screen(&mut self, color: &Color)
Clear (fill) the whole canvas with a specific color
Source§impl RenderableCanvas for CrosstermCanvas
impl RenderableCanvas for CrosstermCanvas
type Input = CrosstermInputState
fn render(&mut self) -> Result<()>
Source§fn resize_surface(&mut self, width: u32, height: u32, scale_factor: Option<f64>)
fn resize_surface(&mut self, width: u32, height: u32, scale_factor: Option<f64>)
Called when the surface of the canvas has been resized.
The physical_dimensions of the new rendering surface are supplied. Read more
Auto Trait Implementations§
impl Freeze for CrosstermCanvas
impl RefUnwindSafe for CrosstermCanvas
impl Send for CrosstermCanvas
impl Sync for CrosstermCanvas
impl Unpin for CrosstermCanvas
impl UnwindSafe for CrosstermCanvas
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more