pub struct PaintContext { /* private fields */ }Expand description
The paint context used for custom 2D drawing
PaintContext wraps a RecordingContext to record draw commands, while providing a Canvas-like API for convenience.
Implementations§
Source§impl PaintContext
impl PaintContext
Sourcepub fn new(width: f32, height: f32) -> Self
pub fn new(width: f32, height: f32) -> Self
Create a new paint context with the given viewport size
Sourcepub fn commands(&self) -> &[DrawCommand]
pub fn commands(&self) -> &[DrawCommand]
Get all recorded commands
Sourcepub fn take_commands(&mut self) -> Vec<DrawCommand>
pub fn take_commands(&mut self) -> Vec<DrawCommand>
Take ownership of recorded commands
Sourcepub fn fill_rect_xywh(
&mut self,
x: f32,
y: f32,
width: f32,
height: f32,
brush: impl Into<Brush>,
)
pub fn fill_rect_xywh( &mut self, x: f32, y: f32, width: f32, height: f32, brush: impl Into<Brush>, )
Fill a rectangle at (x, y) with width/height and a brush
Sourcepub fn stroke_rect_xywh(
&mut self,
x: f32,
y: f32,
width: f32,
height: f32,
stroke: &Stroke,
brush: impl Into<Brush>,
)
pub fn stroke_rect_xywh( &mut self, x: f32, y: f32, width: f32, height: f32, stroke: &Stroke, brush: impl Into<Brush>, )
Stroke a rectangle at (x, y) with width/height
Sourcepub fn fill_rounded_rect_xywh(
&mut self,
x: f32,
y: f32,
width: f32,
height: f32,
radius: f32,
brush: impl Into<Brush>,
)
pub fn fill_rounded_rect_xywh( &mut self, x: f32, y: f32, width: f32, height: f32, radius: f32, brush: impl Into<Brush>, )
Fill a rounded rectangle
Sourcepub fn fill_circle_xyr(
&mut self,
cx: f32,
cy: f32,
radius: f32,
brush: impl Into<Brush>,
)
pub fn fill_circle_xyr( &mut self, cx: f32, cy: f32, radius: f32, brush: impl Into<Brush>, )
Fill a circle at (cx, cy) with radius
Sourcepub fn stroke_circle_xyr(
&mut self,
cx: f32,
cy: f32,
radius: f32,
stroke: &Stroke,
brush: impl Into<Brush>,
)
pub fn stroke_circle_xyr( &mut self, cx: f32, cy: f32, radius: f32, stroke: &Stroke, brush: impl Into<Brush>, )
Stroke a circle at (cx, cy) with radius
Trait Implementations§
Source§impl Default for PaintContext
impl Default for PaintContext
Source§impl DrawContext for PaintContext
impl DrawContext for PaintContext
Source§fn push_transform(&mut self, transform: Transform)
fn push_transform(&mut self, transform: Transform)
Push a transform onto the stack
Source§fn pop_transform(&mut self)
fn pop_transform(&mut self)
Pop the top transform from the stack
Source§fn current_transform(&self) -> Transform
fn current_transform(&self) -> Transform
Get the current combined transform
Source§fn push_opacity(&mut self, opacity: f32)
fn push_opacity(&mut self, opacity: f32)
Push an opacity value (multiplied with parent)
Source§fn pop_opacity(&mut self)
fn pop_opacity(&mut self)
Pop the top opacity from the stack
Source§fn push_blend_mode(&mut self, mode: BlendMode)
fn push_blend_mode(&mut self, mode: BlendMode)
Push a blend mode
Source§fn pop_blend_mode(&mut self)
fn pop_blend_mode(&mut self)
Pop the top blend mode from the stack
Source§fn fill_rect(&mut self, rect: Rect, corner_radius: CornerRadius, brush: Brush)
fn fill_rect(&mut self, rect: Rect, corner_radius: CornerRadius, brush: Brush)
Fill a rectangle (convenience method)
Source§fn stroke_rect(
&mut self,
rect: Rect,
corner_radius: CornerRadius,
stroke: &Stroke,
brush: Brush,
)
fn stroke_rect( &mut self, rect: Rect, corner_radius: CornerRadius, stroke: &Stroke, brush: Brush, )
Stroke a rectangle (convenience method)
Source§fn fill_circle(&mut self, center: Point, radius: f32, brush: Brush)
fn fill_circle(&mut self, center: Point, radius: f32, brush: Brush)
Fill a circle (convenience method)
Source§fn stroke_circle(
&mut self,
center: Point,
radius: f32,
stroke: &Stroke,
brush: Brush,
)
fn stroke_circle( &mut self, center: Point, radius: f32, stroke: &Stroke, brush: Brush, )
Stroke a circle (convenience method)
Source§fn draw_image(&mut self, image: ImageId, rect: Rect, options: &ImageOptions)
fn draw_image(&mut self, image: ImageId, rect: Rect, options: &ImageOptions)
Draw an image
Source§fn draw_shadow(
&mut self,
rect: Rect,
corner_radius: CornerRadius,
shadow: Shadow,
)
fn draw_shadow( &mut self, rect: Rect, corner_radius: CornerRadius, shadow: Shadow, )
Draw a drop shadow (renders outside the shape)
Source§fn draw_inner_shadow(
&mut self,
rect: Rect,
corner_radius: CornerRadius,
shadow: Shadow,
)
fn draw_inner_shadow( &mut self, rect: Rect, corner_radius: CornerRadius, shadow: Shadow, )
Draw an inner shadow (renders inside the shape, like CSS inset box-shadow)
Source§fn draw_circle_shadow(&mut self, center: Point, radius: f32, shadow: Shadow)
fn draw_circle_shadow(&mut self, center: Point, radius: f32, shadow: Shadow)
Draw a circle drop shadow with radially symmetric blur
Source§fn draw_circle_inner_shadow(
&mut self,
center: Point,
radius: f32,
shadow: Shadow,
)
fn draw_circle_inner_shadow( &mut self, center: Point, radius: f32, shadow: Shadow, )
Draw a circle inner shadow (renders inside the circle)
Source§fn sdf_build(&mut self, f: &mut dyn FnMut(&mut dyn SdfBuilder))
fn sdf_build(&mut self, f: &mut dyn FnMut(&mut dyn SdfBuilder))
Build SDF shapes using the optimized SDF pipeline Read more
Source§fn set_camera(&mut self, camera: &Camera)
fn set_camera(&mut self, camera: &Camera)
Set the camera for 3D rendering
Source§fn draw_mesh(&mut self, mesh: MeshId, material: MaterialId, transform: Mat4)
fn draw_mesh(&mut self, mesh: MeshId, material: MaterialId, transform: Mat4)
Draw a mesh with a material
Source§fn draw_mesh_instanced(&mut self, mesh: MeshId, instances: &[MeshInstance])
fn draw_mesh_instanced(&mut self, mesh: MeshId, instances: &[MeshInstance])
Draw instanced meshes
Source§fn set_environment(&mut self, env: &Environment)
fn set_environment(&mut self, env: &Environment)
Set the environment (skybox, IBL)
Source§fn billboard_draw(
&mut self,
size: Size,
transform: Mat4,
facing: BillboardFacing,
f: &mut dyn FnMut(&mut dyn DrawContext),
)
fn billboard_draw( &mut self, size: Size, transform: Mat4, facing: BillboardFacing, f: &mut dyn FnMut(&mut dyn DrawContext), )
Embed 2D content in the current 3D context as a billboard
Source§fn viewport_3d_draw(
&mut self,
rect: Rect,
camera: &Camera,
f: &mut dyn FnMut(&mut dyn DrawContext),
)
fn viewport_3d_draw( &mut self, rect: Rect, camera: &Camera, f: &mut dyn FnMut(&mut dyn DrawContext), )
Embed a 3D viewport in the current 2D context
Source§fn push_layer(&mut self, config: LayerConfig)
fn push_layer(&mut self, config: LayerConfig)
Begin an offscreen layer
Source§fn sample_layer(&mut self, id: LayerId, source_rect: Rect, dest_rect: Rect)
fn sample_layer(&mut self, id: LayerId, source_rect: Rect, dest_rect: Rect)
Sample from a named layer’s output
Source§fn viewport_size(&self) -> Size
fn viewport_size(&self) -> Size
Get the current viewport size
Source§fn is_3d_context(&self) -> bool
fn is_3d_context(&self) -> bool
Check if we’re in a 3D context
Source§fn current_opacity(&self) -> f32
fn current_opacity(&self) -> f32
Get the current opacity
Source§fn current_blend_mode(&self) -> BlendMode
fn current_blend_mode(&self) -> BlendMode
Get the current blend mode
Source§fn set_foreground_layer(&mut self, _is_foreground: bool)
fn set_foreground_layer(&mut self, _is_foreground: bool)
Set whether we’re rendering to the foreground layer (after glass) Read more
Source§fn set_z_layer(&mut self, _layer: u32)
fn set_z_layer(&mut self, _layer: u32)
Set the current z-layer for rendering Read more
Source§fn set_3d_transform(&mut self, _rx_rad: f32, _ry_rad: f32, _perspective_d: f32)
fn set_3d_transform(&mut self, _rx_rad: f32, _ry_rad: f32, _perspective_d: f32)
Set 3D rotation and perspective for the current element
Source§fn set_3d_shape(
&mut self,
_shape_type: f32,
_depth: f32,
_ambient: f32,
_specular: f32,
)
fn set_3d_shape( &mut self, _shape_type: f32, _depth: f32, _ambient: f32, _specular: f32, )
Set 3D shape parameters for the current element
Source§fn set_3d_light(&mut self, _direction: [f32; 3], _intensity: f32)
fn set_3d_light(&mut self, _direction: [f32; 3], _intensity: f32)
Set 3D light parameters for the current element
Source§fn set_3d_translate_z(&mut self, _z: f32)
fn set_3d_translate_z(&mut self, _z: f32)
Set translate-z offset for 3D elements (positive = toward viewer)
Source§fn set_3d_group_raw(&mut self, _shapes: &[[f32; 16]])
fn set_3d_group_raw(&mut self, _shapes: &[[f32; 16]])
Set group shape descriptors for compound 3D rendering
Each shape is 16 floats: [offset(4), params(4), half_ext(4), color(4)]
Source§fn set_css_filter(
&mut self,
_grayscale: f32,
_invert: f32,
_sepia: f32,
_hue_rotate_deg: f32,
_brightness: f32,
_contrast: f32,
_saturate: f32,
)
fn set_css_filter( &mut self, _grayscale: f32, _invert: f32, _sepia: f32, _hue_rotate_deg: f32, _brightness: f32, _contrast: f32, _saturate: f32, )
Set CSS filter parameters for the current element
Source§fn clear_css_filter(&mut self)
fn clear_css_filter(&mut self)
Reset CSS filter state to identity
Source§fn set_mask_gradient(&mut self, _params: [f32; 4], _info: [f32; 4])
fn set_mask_gradient(&mut self, _params: [f32; 4], _info: [f32; 4])
Set mask gradient parameters for the current element
params: linear=(x1,y1,x2,y2), radial=(cx,cy,r,0) in pixel coords
info: [mask_type, start_alpha, end_alpha, 0] where mask_type: 0=none, 1=linear, 2=radial
Source§fn clear_mask_gradient(&mut self)
fn clear_mask_gradient(&mut self)
Clear mask gradient state
Source§fn set_corner_shape(&mut self, _shape: [f32; 4])
fn set_corner_shape(&mut self, _shape: [f32; 4])
Set corner shape (superellipse n parameter) for the current element.
Values: [top_left, top_right, bottom_right, bottom_left].
n=1.0 = round (default), n=0.0 = bevel, n=2.0 = squircle, n=-1.0 = scoop.
Source§fn clear_corner_shape(&mut self)
fn clear_corner_shape(&mut self)
Clear corner shape to default (round, n=1.0)
Source§fn set_overflow_fade(&mut self, _fade: [f32; 4])
fn set_overflow_fade(&mut self, _fade: [f32; 4])
Set overflow fade distances for the next push_clip.
Values: [top, right, bottom, left] in CSS pixels.
Source§fn clear_overflow_fade(&mut self)
fn clear_overflow_fade(&mut self)
Clear pending overflow fade
Source§fn fill_rect_with_per_side_border(
&mut self,
rect: Rect,
corner_radius: CornerRadius,
brush: Brush,
border_widths: [f32; 4],
border_color: Color,
)
fn fill_rect_with_per_side_border( &mut self, rect: Rect, corner_radius: CornerRadius, brush: Brush, border_widths: [f32; 4], border_color: Color, )
Fill a rectangle with per-side borders (all same color)
Border format: [top, right, bottom, left]
Default implementation draws fill then strokes with max border width
Source§fn draw_sdf_viewport(&mut self, _rect: Rect, _viewport: &Sdf3DViewport)
fn draw_sdf_viewport(&mut self, _rect: Rect, _viewport: &Sdf3DViewport)
Draw an SDF 3D viewport using GPU raymarching Read more
Source§fn draw_particles(&mut self, _rect: Rect, _particle_data: &ParticleSystemData)
fn draw_particles(&mut self, _rect: Rect, _particle_data: &ParticleSystemData)
Draw GPU-accelerated particles Read more
Auto Trait Implementations§
impl Freeze for PaintContext
impl RefUnwindSafe for PaintContext
impl Send for PaintContext
impl Sync for PaintContext
impl Unpin for PaintContext
impl UnsafeUnpin for PaintContext
impl UnwindSafe for PaintContext
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
Mutably borrows from an owned value. Read more
Source§impl<T> DrawContextExt for Twhere
T: DrawContext + ?Sized,
impl<T> DrawContextExt for Twhere
T: DrawContext + ?Sized,
Source§fn stroke<B>(&mut self, path: &Path, stroke: &Stroke, brush: B)
fn stroke<B>(&mut self, path: &Path, stroke: &Stroke, brush: B)
Stroke a path with a color or brush
Source§fn fill_rounded_rect<B>(
&mut self,
rect: Rect,
corner_radius: CornerRadius,
brush: B,
)
fn fill_rounded_rect<B>( &mut self, rect: Rect, corner_radius: CornerRadius, brush: B, )
Fill a rectangle with a color or brush
Source§fn sdf<F>(&mut self, f: F)where
F: FnMut(&mut dyn SdfBuilder),
fn sdf<F>(&mut self, f: F)where
F: FnMut(&mut dyn SdfBuilder),
Build SDF shapes with a closure (convenience wrapper)
Source§fn billboard<F>(
&mut self,
size: Size,
transform: Mat4,
facing: BillboardFacing,
f: F,
)where
F: FnMut(&mut dyn DrawContext),
fn billboard<F>(
&mut self,
size: Size,
transform: Mat4,
facing: BillboardFacing,
f: F,
)where
F: FnMut(&mut dyn DrawContext),
Embed 2D content as a billboard (convenience wrapper)
Source§fn viewport_3d<F>(&mut self, rect: Rect, camera: &Camera, f: F)where
F: FnMut(&mut dyn DrawContext),
fn viewport_3d<F>(&mut self, rect: Rect, camera: &Camera, f: F)where
F: FnMut(&mut dyn DrawContext),
Embed a 3D viewport (convenience wrapper)