pub struct Canvas { /* private fields */ }
Expand description
Logical clone of Frame that exposes backend functionality for users without breaking the API rules
§Examples
ⓘ
use oxide::Canvas;
let mut canvas = Canvas::new(60, 10);
let (rows, cols) = canvas.size();
// Set the entire canvas to '-' character
for i in 0..cols*rows {
let y = i / cols;
let x = i % cols;
let mut cell = canvas.get_mut(x, y).unwrap();
cell.set_ch('-');
}
Implementations§
Source§impl Canvas
impl Canvas
Sourcepub fn new(cols: usize, rows: usize) -> Canvas
pub fn new(cols: usize, rows: usize) -> Canvas
Constructs a new Canvas
object cols wide by rows high
§Examples
use oxide::Canvas;
let mut canvas = Canvas::new(60, 10);
Sourcepub fn size(&self) -> Size
pub fn size(&self) -> Size
Returns the size of the canvas
§Examples
use oxide::Canvas;
let mut canvas = Canvas::new(60, 10);
assert_eq!(canvas.size(), (60, 10));
Sourcepub fn cellvec(&self) -> &Vec<Cell>
pub fn cellvec(&self) -> &Vec<Cell>
Returns a reference to the vector of cells that lie within the canvas
Sourcepub fn cellvec_mut(&mut self) -> &mut Vec<Cell>
pub fn cellvec_mut(&mut self) -> &mut Vec<Cell>
Returns a mutable reference to the vector of cells that lie within the canvas
Sourcepub fn pos_to_index(&self, x: usize, y: usize) -> Option<usize>
pub fn pos_to_index(&self, x: usize, y: usize) -> Option<usize>
Converts a position on the screen to the relative coordinate within the Canvas cell buffer
Sourcepub fn get(&self, x: usize, y: usize) -> Option<&Cell>
pub fn get(&self, x: usize, y: usize) -> Option<&Cell>
Returns a reference to the cell at the specified position (x,y), in the form of an Option. If no cell exists at that position, then None
Sourcepub fn get_mut(&mut self, x: usize, y: usize) -> Option<&mut Cell>
pub fn get_mut(&mut self, x: usize, y: usize) -> Option<&mut Cell>
Returns a mutable reference to the cell at the specified position (x, y), in the form of an Option. If no cell exists at that position, then None
Sourcepub fn set_origin(&mut self, new_origin: Pos)
pub fn set_origin(&mut self, new_origin: Pos)
Mantually sets the location of the canvas
Trait Implementations§
Source§impl Widget for Canvas
impl Widget for Canvas
Source§fn draw(&mut self, parent: &mut dyn CellAccessor)
fn draw(&mut self, parent: &mut dyn CellAccessor)
Draws the widget to the valid
CellAccessor
passedSource§fn pack(
&mut self,
parent: &dyn HasSize,
halign: HorizontalAlign,
valign: VerticalAlign,
margin: (usize, usize),
)
fn pack( &mut self, parent: &dyn HasSize, halign: HorizontalAlign, valign: VerticalAlign, margin: (usize, usize), )
Aligns the widget with the
parent
as referenceAuto Trait Implementations§
impl Freeze for Canvas
impl RefUnwindSafe for Canvas
impl Send for Canvas
impl Sync for Canvas
impl Unpin for Canvas
impl UnwindSafe for Canvas
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