Skip to main content

SceneBuilder

Struct SceneBuilder 

Source
pub struct SceneBuilder<'a> { /* private fields */ }
Expand description

Records paint commands into a Scene, maintaining a transform stack.

Widgets call SceneBuilder::push_transform/SceneBuilder::pop_transform around their subtree’s paint calls to compose local offsets/scales with the ancestor transform, mirroring nested widget placement.

Implementations§

Source§

impl<'a> SceneBuilder<'a>

Source

pub fn new(scene: &'a mut Scene) -> Self

Wraps scene for recording, starting with an identity transform.

The transform stack’s backing allocation lives on scene itself so it’s reused across every call instead of reallocating a fresh Vec per frame — reset here to [Affine::IDENTITY], identical to a freshly allocated stack.

Source

pub fn current_transform(&self) -> Affine

The transform currently in effect (composition of all pushed transforms).

Source

pub fn push_transform(&mut self, transform: Affine)

Pushes a transform, composed with the current one, onto the stack.

Subsequent paint calls use the composed transform until the matching SceneBuilder::pop_transform.

Source

pub fn pop_transform(&mut self)

Pops the most recently pushed transform, restoring the previous one.

A no-op if called without a matching push_transform (the base identity transform is never popped).

Source

pub fn fill_rect(&mut self, rect: Rect, brush: Brush)

Records a filled rectangle under the current transform.

Source

pub fn fill_rounded_rect(&mut self, rect: Rect, radius: f64, brush: Brush)

Records a filled rounded rectangle (uniform corner radius) under the current transform.

The uniform-radius spelling of SceneBuilder::fill_rounded_rect_radii — kept verbatim so every existing call site is unaffected by per-corner radii.

Source

pub fn fill_rounded_rect_radii( &mut self, rect: Rect, radii: CornerRadii, brush: Brush, )

Records a filled rounded rectangle with per-corner radii under the current transform.

Source

pub fn stroke_line(&mut self, p0: Point, p1: Point, width: f64, brush: Brush)

Records a stroked line segment from p0 to p1 under the current transform.

Source

pub fn draw_glyph_run(&mut self, glyph_run: GlyphRun)

Records a glyph run, composing its own transform with the current one.

Source

pub fn push_clip(&mut self, rect: Rect)

Pushes a rectangular clip onto the render backend’s clip stack, recording the current transform so the clip is applied in the same space as the draws it encloses.

Source

pub fn push_clip_rounded(&mut self, rect: Rect, radius: f64)

Pushes a clip with uniformly rounded corners (radius, in the pre-transform coordinate space) onto the render backend’s clip stack, recording the current transform so the clip is applied in the same space as the draws it encloses.

Popped by SceneBuilder::pop_clip — the same method that pops a rectangular SceneBuilder::push_clip, since both share one clip stack (see Command::PushClipRounded).

Source

pub fn push_clip_rounded_radii(&mut self, rect: Rect, radii: CornerRadii)

Pushes a clip with per-corner radii onto the render backend’s clip stack, recording the current transform — the per-corner spelling of SceneBuilder::push_clip_rounded, popped by the same SceneBuilder::pop_clip.

Source

pub fn pop_clip(&mut self)

Pops the most recently pushed clip, rectangular or rounded.

Source

pub fn draw_image(&mut self, data: &ImageData, dest: Rect)

Records a decoded image, scaled to fill dest, under the current transform.

data is cloned into the command — cheap, since ImageData’s Blob<u8> is reference-counted internally (see Command::Image).

Source

pub fn draw_blurred_rounded_rect( &mut self, rect: Rect, radius: f64, std_dev: f64, color: Color, )

Records a gaussian-blurred rounded-rectangle shadow (uniform corner radius) under the current transform (see Command::BlurredRoundedRect).

Source

pub fn draw_blurred_rounded_rect_radii( &mut self, rect: Rect, radii: CornerRadii, std_dev: f64, color: Color, )

Records a gaussian-blurred rounded-rectangle shadow with per-corner radii under the current transform.

Neither render tier has a per-corner blurred primitive, so a non-uniform shadow lowers through CornerRadii::largest at encode time — see Command::BlurredRoundedRect for why the largest corner and not the smallest.

Source

pub fn push_layer(&mut self, rect: Rect, alpha: f32)

Pushes a translucent layer onto the render backend’s layer stack, recording the current transform (see Command::PushLayer).

Source

pub fn pop_layer(&mut self)

Pops the most recently pushed layer.

Source

pub fn clear_rect(&mut self, rect: Rect)

Records a rectangle cleared to full transparency (alpha 0) under the current transform (see Command::ClearRect) — the platform-view hole-punch. Unlike SceneBuilder::fill_rect with a transparent brush (which composites transparent over the backdrop, a no-op), this erases whatever was already drawn beneath the rect.

Source

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

Records a filled arbitrary vector path (e.g. an arc) under the current transform, using the nonzero winding rule.

Source

pub fn stroke_path(&mut self, path: BezPath, width: f64, brush: Brush)

Records a stroked arbitrary vector path (e.g. an arc), with round caps/joins, under the current transform.

Source

pub fn stroke_path_dashed( &mut self, path: BezPath, width: f64, dash: DashPattern, brush: Brush, )

Records a dashed stroked path under the current transform: the same stroke SceneBuilder::stroke_path records, carrying a DashPattern the render crate expands into dash segments at encode time.

Source

pub fn push_snapshot(&mut self, key: u64, rect: Rect, alpha: f32, scale: f64)

Pushes a snapshot bracket, recording the current transform (see Command::PushSnapshot) and incrementing the scene’s snapshot depth so the matching SceneBuilder::pop_snapshot knows a bracket is open. key identifies the body’s cache entry across frames; rect/alpha/scale are the presentation parameters a renderer may apply on top of the body as a whole.

Source

pub fn pop_snapshot(&mut self)

Pops the most recently pushed snapshot bracket. A no-op — matching Command::PopClip/Command::PopLayer’s unbalanced-pop policy — when no bracket is open.

Source

pub fn draw_shader(&mut self, program: &ShaderProgram, dest: Rect, time: f32)

Records a fragment-shader-filled rectangle, scaled to fill dest, under the current transform (see Command::ShaderQuad).

The engine renders the fragment program in a pre-pass into an offscreen target and draws it over dest. Output is treated as premultiplied alpha. The rendering is disabled by FRUST_ENGINE_NO_SHADER_EFFECTS.

program is cloned into the command — cheap, since ShaderProgram clones its id and its Arc<str> source handle, never the source text. time is seconds, app-supplied.

Source

pub fn scene_texture(&mut self, id: u64, dest: Rect)

Records an externally owned GPU texture, scaled to fill dest, under the current transform (see Command::SceneTexture).

id is opaque scene-layer data — only the render backend resolves it against textures registered with the GPU context; an unregistered id draws nothing.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for SceneBuilder<'a>

§

impl<'a> !UnwindSafe for SceneBuilder<'a>

§

impl<'a> Freeze for SceneBuilder<'a>

§

impl<'a> Send for SceneBuilder<'a>

§

impl<'a> Sync for SceneBuilder<'a>

§

impl<'a> Unpin for SceneBuilder<'a>

§

impl<'a> UnsafeUnpin for SceneBuilder<'a>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.