pub struct Canvas<IMG> { /* private fields */ }Expand description
The canvas is the area where drawing can take place. Each layer has a canvas, and the canvas in turn holds an image internally to represent the drawing on it.
Implementations§
Source§impl<IMG: Bitmap> Canvas<IMG>
impl<IMG: Bitmap> Canvas<IMG>
Sourcepub fn size(&self) -> Size<i32>
pub fn size(&self) -> Size<i32>
Get the size of the canvas in pixels. This is the amount of pixels of the underlying image, not the real screen-size that the canvas takes up when displayed.
Sourcepub fn width(&self) -> i32
pub fn width(&self) -> i32
Get the width of the canvas in pixels (width of the underlying image, not real screen-size)
Sourcepub fn height(&self) -> i32
pub fn height(&self) -> i32
Get the height of the canvas in pixels (height of the underlying image)
Sourcepub fn rect(&self) -> Rect<i32>
pub fn rect(&self) -> Rect<i32>
Get the rectangle representing the canvas dimensions, starting from the origin at (0, 0).
Sourcepub fn is_in_bounds(&self, p: Point<i32>) -> bool
pub fn is_in_bounds(&self, p: Point<i32>) -> bool
Check whether a point is inside the canvas
Sourcepub fn take_inner(&mut self) -> IMG
pub fn take_inner(&mut self) -> IMG
Take the inner image replacing it with a dummy empty one.
Sourcepub fn resize(&mut self, size: Size<i32>) -> IMG
pub fn resize(&mut self, size: Size<i32>) -> IMG
Resize the canvas, keeping the content that is in bounds and in case of an increase in one of the dimensions, set new pixels to transparent.
Sourcepub fn pixel(&self, p: Point<i32>) -> Color
pub fn pixel(&self, p: Point<i32>) -> Color
Get the color of a pixel in a certain position in the canvas
Sourcepub fn set_pixel(
&mut self,
p: Point<i32>,
color: Color,
) -> Option<(Point<i32>, Color)>
pub fn set_pixel( &mut self, p: Point<i32>, color: Color, ) -> Option<(Point<i32>, Color)>
Set the color of a pixel in a certain position in the canvas. If there was an actual change, return the data needed for a reversal, that is, which point needs to be set to which color to reverse the action.
Sourcepub fn line(
&mut self,
p1: Point<i32>,
p2: Point<i32>,
color: Color,
) -> Vec<(Point<i32>, Color)>
pub fn line( &mut self, p1: Point<i32>, p2: Point<i32>, color: Color, ) -> Vec<(Point<i32>, Color)>
Draw a line between two points in the canvas with a certain color. Returns a set of reversals (points and the colors they need to be set to in order to reverse the action).
Sourcepub fn rectangle(
&mut self,
p1: Point<i32>,
p2: Point<i32>,
color: Color,
) -> Vec<(Point<i32>, Color)>
pub fn rectangle( &mut self, p1: Point<i32>, p2: Point<i32>, color: Color, ) -> Vec<(Point<i32>, Color)>
Draw a rectangle (outline) between two points in the canvas with a certain color. Returns a set of reversals (points and the colors they need to be set to in order to reverse the action).
Sourcepub fn set_area(
&mut self,
area: Rect<i32>,
color: Color,
) -> Vec<(Point<i32>, Color)>
pub fn set_area( &mut self, area: Rect<i32>, color: Color, ) -> Vec<(Point<i32>, Color)>
Set an area of the canvas (determined by a rectangle) to a certain color. Returns a set of reversals (points and colors they need to be set to in order to reverse the action).
Sourcepub fn paste_obj(&mut self, obj: &FreeImage<IMG>) -> Vec<(Point<i32>, Color)>
pub fn paste_obj(&mut self, obj: &FreeImage<IMG>) -> Vec<(Point<i32>, Color)>
Paste a free image into the canvas, overriding the contents that existed below that area. Returns a set of reversals (points and colors they need to be set to in order to reverse the action).
Sourcepub fn bucket(
&mut self,
p: Point<i32>,
color: Color,
) -> Vec<(Point<i32>, Color)>
pub fn bucket( &mut self, p: Point<i32>, color: Color, ) -> Vec<(Point<i32>, Color)>
Paint an enclosed area with a certain color. Returns a set of reversals (points and colors they need to be set to in order to reverse the action).
Sourcepub fn img_from_area(&self, area: Rect<i32>) -> IMG
pub fn img_from_area(&self, area: Rect<i32>) -> IMG
Get an image from a certain area of the canvas (determined by a rectangle).
Trait Implementations§
Source§impl<'de, IMG> Deserialize<'de> for Canvas<IMG>where
IMG: Deserialize<'de>,
impl<'de, IMG> Deserialize<'de> for Canvas<IMG>where
IMG: Deserialize<'de>,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl<IMG> Freeze for Canvas<IMG>where
IMG: Freeze,
impl<IMG> RefUnwindSafe for Canvas<IMG>where
IMG: RefUnwindSafe,
impl<IMG> Send for Canvas<IMG>where
IMG: Send,
impl<IMG> Sync for Canvas<IMG>where
IMG: Sync,
impl<IMG> Unpin for Canvas<IMG>where
IMG: Unpin,
impl<IMG> UnwindSafe for Canvas<IMG>where
IMG: UnwindSafe,
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more