Skip to main content

PaintContext

Struct PaintContext 

Source
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

Source

pub fn new(width: f32, height: f32) -> Self

Create a new paint context with the given viewport size

Source

pub fn from_size(size: Size) -> Self

Create from a Size

Source

pub fn commands(&self) -> &[DrawCommand]

Get all recorded commands

Source

pub fn take_commands(&mut self) -> Vec<DrawCommand>

Take ownership of recorded commands

Source

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

Source

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

Source

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

Source

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

Source

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

Source

pub fn draw_text_simple( &mut self, text: impl Into<String>, x: f32, y: f32, size: f32, color: Color, )

Draw text at (x, y) with size and color

Source

pub fn translate(&mut self, x: f32, y: f32)

Push a translation transform

Source

pub fn scale(&mut self, sx: f32, sy: f32)

Push a scale transform

Source

pub fn rotate(&mut self, angle: f32)

Push a rotation transform (angle in radians)

Trait Implementations§

Source§

impl Default for PaintContext

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl DrawContext for PaintContext

Source§

fn push_transform(&mut self, transform: Transform)

Push a transform onto the stack
Source§

fn pop_transform(&mut self)

Pop the top transform from the stack
Source§

fn current_transform(&self) -> Transform

Get the current combined transform
Source§

fn push_clip(&mut self, shape: ClipShape)

Push a clip shape onto the stack
Source§

fn pop_clip(&mut self)

Pop the top clip from the stack
Source§

fn push_opacity(&mut self, opacity: f32)

Push an opacity value (multiplied with parent)
Source§

fn pop_opacity(&mut self)

Pop the top opacity from the stack
Source§

fn push_blend_mode(&mut self, mode: BlendMode)

Push a blend mode
Source§

fn pop_blend_mode(&mut self)

Pop the top blend mode from the stack
Source§

fn fill_path(&mut self, path: &Path, brush: Brush)

Fill a path with a brush
Source§

fn stroke_path(&mut self, path: &Path, stroke: &Stroke, brush: Brush)

Stroke a path
Source§

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

Stroke a rectangle (convenience method)
Source§

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

Stroke a circle (convenience method)
Source§

fn draw_text(&mut self, text: &str, origin: Point, style: &TextStyle)

Draw text at a position
Source§

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

Draw a drop shadow (renders outside the shape)
Source§

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)

Draw a circle drop shadow with radially symmetric blur
Source§

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

Build SDF shapes using the optimized SDF pipeline Read more
Source§

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)

Draw a mesh with a material
Source§

fn draw_mesh_instanced(&mut self, mesh: MeshId, instances: &[MeshInstance])

Draw instanced meshes
Source§

fn add_light(&mut self, light: Light)

Add a light to the scene
Source§

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

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

Embed a 3D viewport in the current 2D context
Source§

fn push_layer(&mut self, config: LayerConfig)

Begin an offscreen layer
Source§

fn pop_layer(&mut self)

End the current offscreen layer
Source§

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

Get the current viewport size
Source§

fn is_3d_context(&self) -> bool

Check if we’re in a 3D context
Source§

fn current_opacity(&self) -> f32

Get the current opacity
Source§

fn current_blend_mode(&self) -> BlendMode

Get the current blend mode
Source§

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)

Set the current z-layer for rendering Read more
Source§

fn z_layer(&self) -> u32

Get the current z-layer
Source§

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

Set 3D shape parameters for the current element
Source§

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)

Set translate-z offset for 3D elements (positive = toward viewer)
Source§

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 clear_3d(&mut self)

Reset 3D transient state to defaults
Source§

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)

Reset CSS filter state to identity
Source§

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)

Clear mask gradient state
Source§

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)

Clear corner shape to default (round, n=1.0)
Source§

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)

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

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)

Draw an SDF 3D viewport using GPU raymarching Read more
Source§

fn draw_particles(&mut self, _rect: Rect, _particle_data: &ParticleSystemData)

Draw GPU-accelerated particles Read more

Auto Trait Implementations§

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> DrawContextExt for T
where T: DrawContext + ?Sized,

Source§

fn fill<B>(&mut self, path: &Path, brush: B)
where B: Into<Brush>,

Fill a path with a color or brush
Source§

fn stroke<B>(&mut self, path: &Path, stroke: &Stroke, brush: B)
where B: Into<Brush>,

Stroke a path with a color or brush
Source§

fn fill_rounded_rect<B>( &mut self, rect: Rect, corner_radius: CornerRadius, brush: B, )
where B: Into<Brush>,

Fill a rectangle with a color or brush
Source§

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

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

Embed a 3D viewport (convenience wrapper)
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more