pub struct Canvas<'fb> {
pub aa: bool,
/* private fields */
}Expand description
A clipped drawing surface over a Framebuffer.
Fields§
§aa: boolWhen true, polygon / path fill operations use sub-pixel AA (vertical
supersample coverage). Set via Canvas::set_aa.
Implementations§
Source§impl<'fb> Canvas<'fb>
impl<'fb> Canvas<'fb>
Sourcepub fn new(fb: &'fb mut Framebuffer) -> Self
pub fn new(fb: &'fb mut Framebuffer) -> Self
Create a canvas over fb with a base clip covering the whole buffer.
Anti-aliasing is enabled by default.
Sourcepub fn set_aa(&mut self, enabled: bool)
pub fn set_aa(&mut self, enabled: bool)
Set whether polygon / path fill operations use sub-pixel AA.
When false, the aa flag passed to fill_polygon_clipped is false,
producing aliased edges (faster).
Sourcepub fn framebuffer(&self) -> &Framebuffer
pub fn framebuffer(&self) -> &Framebuffer
Borrow the underlying framebuffer.
Sourcepub fn push_clip(&mut self, x: f32, y: f32, w: f32, h: f32)
pub fn push_clip(&mut self, x: f32, y: f32, w: f32, h: f32)
Push a rectangular clip (intersected with the current clip).
Sourcepub fn fill_rect(&mut self, x: f32, y: f32, w: f32, h: f32, color: Color)
pub fn fill_rect(&mut self, x: f32, y: f32, w: f32, h: f32, color: Color)
Fill an axis-aligned rectangle with a solid colour (no AA; pixel-snapped).
Sourcepub fn stroke_rect(
&mut self,
x: f32,
y: f32,
w: f32,
h: f32,
thickness: f32,
color: Color,
)
pub fn stroke_rect( &mut self, x: f32, y: f32, w: f32, h: f32, thickness: f32, color: Color, )
Stroke a rectangle outline of the given thickness (drawn inward).
Sourcepub fn draw_line(&mut self, x0: f32, y0: f32, x1: f32, y1: f32, color: Color)
pub fn draw_line(&mut self, x0: f32, y0: f32, x1: f32, y1: f32, color: Color)
Draw a 1-pixel line from (x0, y0) to (x1, y1) using Bresenham’s
algorithm (no anti-aliasing).
Sourcepub fn fill_circle(&mut self, cx: f32, cy: f32, radius: f32, color: Color)
pub fn fill_circle(&mut self, cx: f32, cy: f32, radius: f32, color: Color)
Fill an anti-aliased circle centred at (cx, cy) with radius.
Coverage is estimated from the signed distance to the circle edge, giving a smooth one-pixel-wide anti-aliased boundary.
Sourcepub fn fill_rounded_rect(
&mut self,
x: f32,
y: f32,
w: f32,
h: f32,
radius: f32,
color: Color,
)
pub fn fill_rounded_rect( &mut self, x: f32, y: f32, w: f32, h: f32, radius: f32, color: Color, )
Fill a rounded rectangle with a uniform corner radius and AA edges.
Sourcepub fn draw_line_wu(&mut self, x0: f32, y0: f32, x1: f32, y1: f32, color: Color)
pub fn draw_line_wu(&mut self, x0: f32, y0: f32, x1: f32, y1: f32, color: Color)
Draw an anti-aliased line from (x0, y0) to (x1, y1) using Wu’s
algorithm (float pixel coverage).
Sourcepub fn draw_line_thick(
&mut self,
x0: f32,
y0: f32,
x1: f32,
y1: f32,
width: f32,
color: Color,
)
pub fn draw_line_thick( &mut self, x0: f32, y0: f32, x1: f32, y1: f32, width: f32, color: Color, )
Draw a thick anti-aliased line of the given width using a parallel-offset
rectangle polygon fill.
Sourcepub fn draw_line_dashed(
&mut self,
x0: f32,
y0: f32,
x1: f32,
y1: f32,
color: Color,
pattern: DashPattern,
)
pub fn draw_line_dashed( &mut self, x0: f32, y0: f32, x1: f32, y1: f32, color: Color, pattern: DashPattern, )
Draw a dashed line from (x0, y0) to (x1, y1) using pattern.
Dashes and gaps alternate until the endpoint is reached.
Sourcepub fn fill_ellipse(&mut self, cx: f32, cy: f32, rx: f32, ry: f32, color: Color)
pub fn fill_ellipse(&mut self, cx: f32, cy: f32, rx: f32, ry: f32, color: Color)
Fill an axis-aligned anti-aliased ellipse centred at (cx, cy) with
semi-axes rx (horizontal) and ry (vertical).
Sourcepub fn fill_rounded_rect_per_corner(
&mut self,
x: f32,
y: f32,
w: f32,
h: f32,
radii: [f32; 4],
color: Color,
)
pub fn fill_rounded_rect_per_corner( &mut self, x: f32, y: f32, w: f32, h: f32, radii: [f32; 4], color: Color, )
Fill a rounded rectangle where each corner may have a different radius.
radii = [top_left, top_right, bottom_right, bottom_left].
Sourcepub fn blit_rgba(
&mut self,
src: SrcImage<'_>,
dx: f32,
dy: f32,
dst_w: u32,
dst_h: u32,
)
pub fn blit_rgba( &mut self, src: SrcImage<'_>, dx: f32, dy: f32, dst_w: u32, dst_h: u32, )
Blit an RGBA source image at destination position (dx, dy) with
source-over blending and nearest-neighbour scaling to dst_w × dst_h.
Sourcepub fn blit_bilinear(
&mut self,
src: SrcImage<'_>,
dx: f32,
dy: f32,
dst_w: u32,
dst_h: u32,
)
pub fn blit_bilinear( &mut self, src: SrcImage<'_>, dx: f32, dy: f32, dst_w: u32, dst_h: u32, )
Blit an RGBA source image at destination position (dx, dy) with
source-over blending and bilinear interpolation scaled to dst_w × dst_h.
Sourcepub fn blit_nine_slice(
&mut self,
src: SrcImage<'_>,
dx: f32,
dy: f32,
dst_w: u32,
dst_h: u32,
insets: [u32; 4],
)
pub fn blit_nine_slice( &mut self, src: SrcImage<'_>, dx: f32, dy: f32, dst_w: u32, dst_h: u32, insets: [u32; 4], )
Nine-slice blit: corners are copied unscaled; edges stretch in one axis; centre stretches in both axes.
insets = [top, right, bottom, left] in source pixels.
Sourcepub fn fill_path(&mut self, path: &PathData, color: Color)
pub fn fill_path(&mut self, path: &PathData, color: Color)
Fill a oxiui_core::paint::PathData using the current clip. Converts verbs to a soft crate::path::Path.
Sourcepub fn stroke_path(
&mut self,
path: &PathData,
style: &StrokeStyle,
color: Color,
)
pub fn stroke_path( &mut self, path: &PathData, style: &StrokeStyle, color: Color, )
Stroke a oxiui_core::paint::PathData using the current clip and stroke style.
Sourcepub fn fill_linear_gradient_cmd(
&mut self,
rect: Rect,
start: Point,
end: Point,
stops: &[GradientStop],
)
pub fn fill_linear_gradient_cmd( &mut self, rect: Rect, start: Point, end: Point, stops: &[GradientStop], )
Fill a rectangle with a linear gradient, respecting the current clip.
Sourcepub fn fill_radial_gradient_cmd(
&mut self,
rect: Rect,
center: Point,
radius: f32,
stops: &[GradientStop],
)
pub fn fill_radial_gradient_cmd( &mut self, rect: Rect, center: Point, radius: f32, stops: &[GradientStop], )
Fill a rectangle with a radial gradient, respecting the current clip.
Sourcepub fn box_shadow_cmd(
&mut self,
rect: Rect,
offset: Point,
blur_radius: f32,
color: Color,
cache: &mut GaussianCache,
)
pub fn box_shadow_cmd( &mut self, rect: Rect, offset: Point, blur_radius: f32, color: Color, cache: &mut GaussianCache, )
Draw a box shadow. The shadow composites into the full framebuffer
(no clip applied — consistent with the existing box_shadow function).
Auto Trait Implementations§
impl<'fb> !UnwindSafe for Canvas<'fb>
impl<'fb> Freeze for Canvas<'fb>
impl<'fb> RefUnwindSafe for Canvas<'fb>
impl<'fb> Send for Canvas<'fb>
impl<'fb> Sync for Canvas<'fb>
impl<'fb> Unpin for Canvas<'fb>
impl<'fb> UnsafeUnpin for Canvas<'fb>
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