pub struct Canvas { /* private fields */ }
Expand description
An object that holds the data for a grid of VisualElement
s for a single frame.
Implementations§
source§impl Canvas
impl Canvas
sourcepub fn new(dimension: Vec2, default_element: &VisualElement) -> Canvas
pub fn new(dimension: Vec2, default_element: &VisualElement) -> Canvas
Constructs a Canvas
with the given dimension
and each cell set to the given
VisualElement
as a default.
pub fn default_element(&self) -> &VisualElement
sourcepub fn set_default_element(&mut self, element: &VisualElement)
pub fn set_default_element(&mut self, element: &VisualElement)
Sets the current Canvas
’s default element, to which every cell is reset when
Canvas::clear
is called.
pub fn dimension(&self) -> Vec2
sourcepub fn contains(&self, pos: Vec2) -> bool
pub fn contains(&self, pos: Vec2) -> bool
Checks if the point represented by the given pos
would be within the dimensions of the
Canvas
.
The dimensions are sizes while the pos
are indices.
let canvas = Canvas::new(Vec2::xy(10, 20), &VisualElement::default());
let a = Vec2::xy(10, 20);
let b = Vec2::xy(9, 19);
assert!(!canvas.contains(a));
assert!(canvas.contains(b));
A Vec2
with any negative components will always evaluate false
.
let canvas = Canvas::new(Vec2::xy(10, 20), &VisualElement::default());
let p = Vec2::xy(-1, -3);
assert!(!canvas.contains(p));
sourcepub fn elem(&self, pos: Vec2) -> Option<&VisualElement>
pub fn elem(&self, pos: Vec2) -> Option<&VisualElement>
sourcepub fn elem_mut(&mut self, pos: Vec2) -> Option<&mut VisualElement>
pub fn elem_mut(&mut self, pos: Vec2) -> Option<&mut VisualElement>
sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears all of the VisualElement
cells in the grid by setting them to clones of the
default element.
sourcepub fn fill(&mut self, elem: &VisualElement)
pub fn fill(&mut self, elem: &VisualElement)
Sets every cell to the given elem
.
sourcepub fn data(&self) -> &Vec<VisualElement>
pub fn data(&self) -> &Vec<VisualElement>
Returns a reference to all the data the Canvas
holds.