pub trait Renderer {
Show 14 methods
// Required methods
fn begin(&mut self, capture: bool);
fn set_transform(&mut self, transform: Affine);
fn set_z_index(&mut self, z_index: i32);
fn clip(&mut self, shape: &impl Shape);
fn clear_clip(&mut self);
fn stroke<'b, 's>(
&mut self,
shape: &impl Shape,
brush: impl Into<BrushRef<'b>>,
stroke: &'s Stroke,
);
fn fill<'b>(
&mut self,
path: &impl Shape,
brush: impl Into<BrushRef<'b>>,
blur_radius: f64,
);
fn push_layer(
&mut self,
blend: impl Into<BlendMode>,
alpha: f32,
transform: Affine,
clip: &impl Shape,
);
fn pop_layer(&mut self);
fn draw_glyphs<'a>(
&mut self,
origin: Point,
props: &GlyphRunProps<'a>,
glyphs: impl Iterator<Item = Glyph> + 'a,
);
fn draw_svg<'b>(
&mut self,
svg: Svg<'b>,
rect: Rect,
brush: Option<impl Into<BrushRef<'b>>>,
);
fn draw_img(&mut self, img: Img<'_>, rect: Rect);
fn finish(&mut self) -> Option<ImageBrush>;
// Provided method
fn debug_info(&self) -> String { ... }
}Expand description
The core rendering trait that every Floem backend must implement.
A frame is bracketed by begin and finish.
Between those calls the framework issues drawing commands — fills, strokes, text,
images, SVGs — which the backend records or executes immediately depending on its
architecture.
The typical call sequence within a single frame looks like:
renderer.begin(capture);
renderer.set_transform(..);
renderer.fill(..); // background
renderer.clip(..); // restrict drawing area
renderer.draw_text_lines(..); // labels, editors
renderer.draw_svg(..); // icons
renderer.draw_img(..); // photos
renderer.stroke(..); // borders
renderer.clear_clip();
renderer.finish();Required Methods§
Sourcefn begin(&mut self, capture: bool)
fn begin(&mut self, capture: bool)
Begin a new frame.
Must be called exactly once before any drawing commands.
When capture is true the renderer should record the frame into an
off-screen buffer so that finish can return it as
an ImageBrush. This is used by the Floem
inspector to take snapshots.
Sourcefn set_transform(&mut self, transform: Affine)
fn set_transform(&mut self, transform: Affine)
Set the current affine transform in device/render-target coordinates.
All subsequent drawing commands are transformed by transform until it
is changed again. The framework provides this as the final transform for
the current visual node, including window scaling, so backends should not
apply an additional global window-scale multiply to ordinary geometry.
Raster-backed operations such as glyph and SVG caching may still derive a rasterization scale from this transform to choose an appropriate pixel resolution.
Sourcefn set_z_index(&mut self, z_index: i32)
fn set_z_index(&mut self, z_index: i32)
Set the z-index for subsequent draw commands.
Not all backends honour this — Vello and tiny-skia rely on painter’s order instead.
Sourcefn clip(&mut self, shape: &impl Shape)
fn clip(&mut self, shape: &impl Shape)
Clip all subsequent drawing to the interior of shape.
The clip remains in effect until clear_clip is
called. On the Vello backend clipping is implemented via
push_layer / pop_layer
instead, so this method may be a no-op there.
Sourcefn clear_clip(&mut self)
fn clear_clip(&mut self)
Remove the current clip region, allowing drawing to the full surface.
Sourcefn stroke<'b, 's>(
&mut self,
shape: &impl Shape,
brush: impl Into<BrushRef<'b>>,
stroke: &'s Stroke,
)
fn stroke<'b, 's>( &mut self, shape: &impl Shape, brush: impl Into<BrushRef<'b>>, stroke: &'s Stroke, )
Stroke the outline of a [Shape].
The brush defines the color or gradient and stroke controls the
line width, join style, dash pattern, etc.
Sourcefn fill<'b>(
&mut self,
path: &impl Shape,
brush: impl Into<BrushRef<'b>>,
blur_radius: f64,
)
fn fill<'b>( &mut self, path: &impl Shape, brush: impl Into<BrushRef<'b>>, blur_radius: f64, )
Fill the interior of a [Shape] using the non-zero fill rule.
When blur_radius is greater than zero the fill is drawn with a
Gaussian blur, which is used for box shadows.
Sourcefn push_layer(
&mut self,
blend: impl Into<BlendMode>,
alpha: f32,
transform: Affine,
clip: &impl Shape,
)
fn push_layer( &mut self, blend: impl Into<BlendMode>, alpha: f32, transform: Affine, clip: &impl Shape, )
Push a compositing layer onto the layer stack.
Drawing commands issued after this call are composited into the layer.
Call pop_layer to flatten the layer back into
the parent using the specified blend mode and alpha.
The clip shape restricts drawing within the layer, and transform is
applied to the layer contents.
Sourcefn pop_layer(&mut self)
fn pop_layer(&mut self)
Pop the topmost compositing layer pushed by push_layer.
The layer contents are composited into the parent surface using the blend mode and alpha that were specified when the layer was pushed.
Sourcefn draw_glyphs<'a>(
&mut self,
origin: Point,
props: &GlyphRunProps<'a>,
glyphs: impl Iterator<Item = Glyph> + 'a,
)
fn draw_glyphs<'a>( &mut self, origin: Point, props: &GlyphRunProps<'a>, glyphs: impl Iterator<Item = Glyph> + 'a, )
Draw a single glyph run.
Sourcefn draw_svg<'b>(
&mut self,
svg: Svg<'b>,
rect: Rect,
brush: Option<impl Into<BrushRef<'b>>>,
)
fn draw_svg<'b>( &mut self, svg: Svg<'b>, rect: Rect, brush: Option<impl Into<BrushRef<'b>>>, )
Draw an SVG image inside rect.
When brush is Some, the SVG is rendered as a mask and filled with
the given brush — this is how Floem applies a color override to icons.
Sourcefn draw_img(&mut self, img: Img<'_>, rect: Rect)
fn draw_img(&mut self, img: Img<'_>, rect: Rect)
Draw a raster image inside rect.
The image is scaled to fit the destination rectangle.
Sourcefn finish(&mut self) -> Option<ImageBrush>
fn finish(&mut self) -> Option<ImageBrush>
Finish the current frame and present it.
If the frame was started with capture = true, the rendered content is
returned as an ImageBrush. Otherwise returns
None after presenting the frame to the screen.
Provided Methods§
Sourcefn debug_info(&self) -> String
fn debug_info(&self) -> String
Return a human-readable string identifying the renderer backend.
Used by the Floem inspector. Implementations typically return a string
like "name: Vello\ninfo: …".
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.