Skip to main content

Renderer

Trait Renderer 

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

Source

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.

Source

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.

Source

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.

Source

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.

Source

fn clear_clip(&mut self)

Remove the current clip region, allowing drawing to the full surface.

Source

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.

Source

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.

Source

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.

Source

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.

Source

fn draw_glyphs<'a>( &mut self, origin: Point, props: &GlyphRunProps<'a>, glyphs: impl Iterator<Item = Glyph> + 'a, )

Draw a single glyph run.

Source

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.

Source

fn draw_img(&mut self, img: Img<'_>, rect: Rect)

Draw a raster image inside rect.

The image is scaled to fit the destination rectangle.

Source

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§

Source

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.

Implementors§