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) -> SceneBuilder<'a>

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: AlphaColor<Srgb>, )

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: AlphaColor<Srgb>, )

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.

Trait Implementations§

Source§

impl PaintScene for SceneBuilder<'_>

Bridges the provisional PaintScene boundary onto the real frust_scene::SceneBuilder.

Widgets paint through &mut dyn PaintScene; the desktop shell hands them a SceneBuilder, so filled rectangles and shaped glyph runs land in the display list under the builder’s current transform. Unshaped PaintScene::draw_text is intentionally dropped here — text must be shaped (by frust-text) into glyph runs before it can be drawn.

Source§

fn fill_rect(&mut self, origin: Point, size: Size, color: AlphaColor<Srgb>)

Emit a filled axis-aligned rectangle at origin with size, filled with the solid color.
Source§

fn fill_rounded_rect( &mut self, origin: Point, size: Size, radius: f64, color: AlphaColor<Srgb>, )

Emit a filled axis-aligned rectangle with uniformly rounded corners. Read more
Source§

fn fill_rounded_rect_radii( &mut self, origin: Point, size: Size, radii: CornerRadii, color: AlphaColor<Srgb>, )

Emit a filled axis-aligned rectangle with per-corner radii — the shape a uniform PaintScene::fill_rounded_rect cannot express (a bottom-anchored sheet with only its top corners rounded, a segmented control’s end caps). Read more
Source§

fn stroke_line( &mut self, p0: Point, p1: Point, width: f64, color: AlphaColor<Srgb>, )

Stroke a straight line from p0 to p1 with the given width and solid color. Read more
Source§

fn push_clip(&mut self, origin: Point, size: Size)

Push a rectangular clip (at origin/size) onto the backend clip stack; subsequent draws are clipped to it until the matching PaintScene::pop_clip. Read more
Source§

fn push_clip_rounded(&mut self, origin: Point, size: Size, radius: f64)

Push a clip with uniformly rounded corners (at origin/size, corner radius) onto the backend clip stack; subsequent draws are clipped to the rounded shape until the matching PaintScene::pop_clip — the same pop PaintScene::push_clip uses, since there is one clip stack. Read more
Source§

fn push_clip_rounded_radii( &mut self, origin: Point, size: Size, radii: CornerRadii, )

Push a clip with per-corner radii onto the backend clip stack, popped by the same PaintScene::pop_clip as every other push. Read more
Source§

fn pop_clip(&mut self)

Pop the most recently pushed clip, rectangular or rounded. Defaulted to a no-op; see PaintScene::push_clip.
Source§

fn draw_text(&mut self, _origin: Point, _text: &str)

Emit a run of unshaped text anchored at origin. Read more
Source§

fn draw_glyph_run(&mut self, run: GlyphRun)

Emit a run of already-shaped glyphs into the scene. Read more
Source§

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

Draw an already-decoded image, scaled from its natural (data.widthxdata.height) size to fill the absolute dest rect. Read more
Source§

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

Draw a fragment-shader-filled rectangle, scaled to fill dest. Read more
Source§

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

Composite a bound scene texture (pre-rendered via ExternalPass) into the scene. Read more
Source§

fn draw_shadow( &mut self, origin: Point, size: Size, radius: f64, std_dev: f64, color: AlphaColor<Srgb>, )

Draw a gaussian-blurred rounded-rectangle elevation shadow (an approximation of a CSS box-shadow) at origin/size. Read more
Source§

fn fill_rect_brush(&mut self, origin: Point, size: Size, brush: &Brush)

Emit a filled axis-aligned rectangle at origin with size, filled with an arbitrary brush (solid color or gradient). Read more
Source§

fn fill_rounded_rect_brush( &mut self, origin: Point, size: Size, radius: f64, brush: &Brush, )

Emit a filled axis-aligned rectangle with uniformly rounded corners, filled with an arbitrary brush (solid color or gradient). Read more
Source§

fn push_layer(&mut self, origin: Point, size: Size, alpha: f32)

Push a translucent layer (at origin/size) onto the backend layer stack; subsequent draws are composited at alpha until the matching PaintScene::pop_layer. Read more
Source§

fn pop_layer(&mut self)

Pop the most recently pushed layer. Defaulted to a no-op; see PaintScene::push_layer.
Source§

fn clear_rect(&mut self, origin: Point, size: Size)

Clear an axis-aligned rectangle (at origin/size) to full transparency (alpha 0), erasing everything already painted below it in this scene — a real destination-clearing composite, not merely skipping paint over the region. Read more
Source§

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

Fill an arbitrary vector path (e.g. an arc — see frust_scene::arc_path) at origin, using the nonzero winding rule and brush. Read more
Source§

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

Stroke an arbitrary vector path (e.g. an arc) at origin with width and round caps/joins, using brush. Read more
Source§

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

Stroke an arbitrary vector path at origin as a dashed line: the same stroke PaintScene::stroke_path paints, broken into dash’s on/off runs by the render crate at encode time. Read more
Source§

fn push_transform(&mut self, transform: Affine)

Push an affine transform, composed with the current one, onto the backend transform stack; subsequent draws are transformed until the matching PaintScene::pop_transform. Read more
Source§

fn pop_transform(&mut self)

Pop the most recently pushed transform, restoring the previous one. Defaulted to a no-op; see PaintScene::push_transform.
Source§

fn push_snapshot( &mut self, key: u64, origin: Point, size: Size, alpha: f32, scale: f64, )

Push a snapshot bracket: the body is rasterizable once and cached by key across frames. The alpha and scale are presentation parameters applied to the whole cached body (alpha blending, uniform scale). Read more
Source§

fn pop_snapshot(&mut self)

Pop the most recently pushed snapshot bracket. Defaulted to the reverse of PaintScene::push_snapshot’s default: pop layer, then transform. Recorders that don’t override both may see unbalanced stacks if only one is overridden; the default pair is provided for source compatibility.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T> StorageAccess<T> for T

Source§

fn as_borrowed(&self) -> &T

Borrows the value.
Source§

fn into_taken(self) -> T

Takes the value.
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.
Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

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