pub struct PixelCanvas {
pub width: u32,
pub height: u32,
pub background_color: [u8; 3],
pub buffer: Vec<u8>,
pub margin: u32,
}
Expand description
A structure representing a pixel-based drawing canvas.
Fields§
§width: u32
Width of the canvas in pixels.
height: u32
Height of the canvas in pixels.
background_color: [u8; 3]
Background color of the canvas (RGB format).
buffer: Vec<u8>
Buffer storing pixel data as a linear array.
margin: u32
Margin around the canvas (in pixels).
Implementations§
source§impl PixelCanvas
impl PixelCanvas
sourcepub fn new(
width: u32,
height: u32,
background_color: [u8; 3],
margin: u32,
) -> Self
pub fn new( width: u32, height: u32, background_color: [u8; 3], margin: u32, ) -> Self
Creates a new PixelCanvas
with the specified dimensions, background color, and margin.
§Parameters
width
: The width of the canvas in pixels.height
: The height of the canvas in pixels.background_color
: The RGB color of the canvas background.margin
: Margin size in pixels.
§Returns
A new PixelCanvas
instance.
sourcepub fn draw_pixel(&mut self, x: u32, y: u32, color: [u8; 3])
pub fn draw_pixel(&mut self, x: u32, y: u32, color: [u8; 3])
Draws a single pixel at the specified coordinates with the given color.
§Parameters
x
: The x-coordinate of the pixel.y
: The y-coordinate of the pixel.color
: The RGB color of the pixel.
sourcepub fn blend_pixel(&mut self, x: u32, y: u32, color: [u8; 3], alpha: f64)
pub fn blend_pixel(&mut self, x: u32, y: u32, color: [u8; 3], alpha: f64)
Blends a pixel with the specified color and alpha value.
§Parameters
x
: The x-coordinate of the pixel.y
: The y-coordinate of the pixel.color
: The RGB color to blend.alpha
: The transparency value (0.0 to 1.0).
sourcepub fn draw_horizontal_line(&mut self, y: u32, color: [u8; 3])
pub fn draw_horizontal_line(&mut self, y: u32, color: [u8; 3])
Draws a horizontal line at the specified y-coordinate.
§Parameters
y
: The y-coordinate of the line.color
: The RGB color of the line.
sourcepub fn draw_vertical_line(&mut self, x: u32, color: [u8; 3])
pub fn draw_vertical_line(&mut self, x: u32, color: [u8; 3])
Draws a vertical line at the specified x-coordinate.
§Parameters
x
: The x-coordinate of the line.color
: The RGB color of the line.
sourcepub fn draw_grid(&mut self, grid_size: &[usize; 2], color: [u8; 3])
pub fn draw_grid(&mut self, grid_size: &[usize; 2], color: [u8; 3])
Draws a grid on the canvas.
§Parameters
grid_size
: An array specifying the spacing of grid lines in the x and y directions.color
: The RGB color of the grid lines.
sourcepub fn draw_text_vertical(
&mut self,
x: u32,
y: u32,
text: &str,
color: [u8; 3],
font: &FontRef<'_>,
scale: PxScale,
)
pub fn draw_text_vertical( &mut self, x: u32, y: u32, text: &str, color: [u8; 3], font: &FontRef<'_>, scale: PxScale, )
Draws text vertically at the specified position.
§Parameters
x
: The x-coordinate for the text.y
: The y-coordinate for the text.text
: The text content.color
: The RGB color of the text.font
: The font reference for rendering text.scale
: The scaling factor for the font size.
sourcepub fn draw_text(
&mut self,
x: u32,
y: u32,
text: &str,
color: [u8; 3],
font: &FontRef<'_>,
scale: PxScale,
)
pub fn draw_text( &mut self, x: u32, y: u32, text: &str, color: [u8; 3], font: &FontRef<'_>, scale: PxScale, )
Draws text at the specified position.
§Parameters
x
: The x-coordinate for the text.y
: The y-coordinate for the text.text
: The text content.color
: The RGB color of the text.font
: The font reference for rendering text.scale
: The scaling factor for the font size.
sourcepub fn draw_line(
&mut self,
x1: i32,
y1: i32,
x2: i32,
y2: i32,
color: [u8; 3],
line_type: LineType,
)
pub fn draw_line( &mut self, x1: i32, y1: i32, x2: i32, y2: i32, color: [u8; 3], line_type: LineType, )
Draws a line with the specified type (solid, dashed, or dotted).
§Parameters
x1
,y1
: Coordinates of the start point.x2
,y2
: Coordinates of the end point.color
: The RGB color of the line.line_type
: The type of line to draw (LineType
).
sourcepub fn save_as_image(&self, file_path: &str)
pub fn save_as_image(&self, file_path: &str)
Auto Trait Implementations§
impl Freeze for PixelCanvas
impl RefUnwindSafe for PixelCanvas
impl Send for PixelCanvas
impl Sync for PixelCanvas
impl Unpin for PixelCanvas
impl UnwindSafe for PixelCanvas
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§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.