Skip to main content

Canvas

Struct Canvas 

Source
pub struct Canvas<'fb> {
    pub aa: bool,
    /* private fields */
}
Expand description

A clipped drawing surface over a Framebuffer.

Fields§

§aa: bool

When true, polygon / path fill operations use sub-pixel AA (vertical supersample coverage). Set via Canvas::set_aa.

Implementations§

Source§

impl<'fb> Canvas<'fb>

Source

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.

Source

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).

Source

pub fn framebuffer(&self) -> &Framebuffer

Borrow the underlying framebuffer.

Source

pub fn push_clip(&mut self, x: f32, y: f32, w: f32, h: f32)

Push a rectangular clip (intersected with the current clip).

Source

pub fn pop_clip(&mut self)

Pop the most recently pushed clip.

Source

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).

Source

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).

Source

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).

Source

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.

Source

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.

Source

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).

Source

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.

Source

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.

Source

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).

Source

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].

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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).

Source

pub fn draw_quad_bezier( &mut self, p0: (f32, f32), ctrl: (f32, f32), p2: (f32, f32), color: Color, )

Draw a quadratic Bézier curve from p0 via ctrl to p2.

Source

pub fn draw_cubic_bezier( &mut self, p0: (f32, f32), c1: (f32, f32), c2: (f32, f32), p3: (f32, f32), color: Color, )

Draw a cubic Bézier curve from p0 via c1, c2 to p3.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.