pub struct Canvas;Expand description
Immediate-mode canvas facade that wraps the low-level drawing functions.
All methods paint immediately (no retained scene graph). Create one per
frame or per start_app call and issue draw commands through it.
Implementations§
Source§impl Canvas
impl Canvas
Sourcepub fn fill_rounded_rect(&self, rect: Rect, radius: f32, color: Color)
pub fn fill_rounded_rect(&self, rect: Rect, radius: f32, color: Color)
Draw a filled rounded rectangle with uniform corner radius.
Sourcepub fn fill_circle(&self, center: Point2D, radius: f32, color: Color)
pub fn fill_circle(&self, center: Point2D, radius: f32, color: Color)
Draw a filled circle.
Sourcepub fn arc(
&self,
center: Point2D,
radius: f32,
start_angle: f32,
end_angle: f32,
thickness: f32,
color: Color,
)
pub fn arc( &self, center: Point2D, radius: f32, start_angle: f32, end_angle: f32, thickness: f32, color: Color, )
Draw a circular arc stroke from start_angle to end_angle (radians).
Sourcepub fn bezier(
&self,
from: Point2D,
ctrl1: Point2D,
ctrl2: Point2D,
to: Point2D,
thickness: f32,
color: Color,
)
pub fn bezier( &self, from: Point2D, ctrl1: Point2D, ctrl2: Point2D, to: Point2D, thickness: f32, color: Color, )
Draw a cubic Bézier curve stroke.
Sourcepub fn line(&self, from: Point2D, to: Point2D, thickness: f32, color: Color)
pub fn line(&self, from: Point2D, to: Point2D, thickness: f32, color: Color)
Draw a line between two points.
Sourcepub fn image(&self, rect: Rect, data: &[u8])
pub fn image(&self, rect: Rect, data: &[u8])
Draw an image from encoded bytes (PNG, JPEG, GIF, WebP).
Sourcepub fn linear_gradient(&self, rect: Rect, stops: &[GradientStop])
pub fn linear_gradient(&self, rect: Rect, stops: &[GradientStop])
Fill a rectangle with a linear gradient.
Sourcepub fn radial_gradient(&self, rect: Rect, stops: &[GradientStop])
pub fn radial_gradient(&self, rect: Rect, stops: &[GradientStop])
Fill a rectangle with a radial gradient.
Sourcepub fn transform(&self, a: f32, b: f32, c: f32, d: f32, tx: f32, ty: f32)
pub fn transform(&self, a: f32, b: f32, c: f32, d: f32, tx: f32, ty: f32)
Apply a full 2D affine transform.
Sourcepub fn set_opacity(&self, alpha: f32)
pub fn set_opacity(&self, alpha: f32)
Set layer opacity (0.0–1.0) for subsequent draw commands.
Sourcepub fn dimensions(&self) -> (u32, u32)
pub fn dimensions(&self) -> (u32, u32)
Get the canvas dimensions in pixels.
Sourcepub fn set_content_size(&self, width: u32, height: u32)
pub fn set_content_size(&self, width: u32, height: u32)
Set the virtual size of the canvas content to enable host scrollbars.
Sourcepub fn scroll_position(&self) -> (f32, f32)
pub fn scroll_position(&self) -> (f32, f32)
Get the current absolute (scroll_x, scroll_y) coordinates.
Sourcepub fn set_scroll_position(&self, x: f32, y: f32)
pub fn set_scroll_position(&self, x: f32, y: f32)
Programmatically set the absolute scroll position.
Sourcepub fn text_ex(
&self,
text: &str,
pos: Point2D,
size: f32,
color: Color,
family: &str,
weight: u32,
style: u32,
align: u32,
)
pub fn text_ex( &self, text: &str, pos: Point2D, size: f32, color: Color, family: &str, weight: u32, style: u32, align: u32, )
Draw text with explicit family, weight, style, and horizontal alignment.
Pass an empty family to use the system UI font.
Sourcepub fn measure_text(
&self,
size: f32,
family: &str,
weight: u32,
style: u32,
text: &str,
) -> TextMetrics
pub fn measure_text( &self, size: f32, family: &str, weight: u32, style: u32, text: &str, ) -> TextMetrics
Measure a line of text shaped with the given font parameters.