Skip to main content

Scene

Struct Scene 

Source
pub struct Scene { /* private fields */ }
Expand description

A builder of vector draw primitives in logical-pixel space.

Implementations§

Source§

impl Scene

Source

pub fn draw_image_source( &mut self, bounds: Rect, source: &ImageSource, fit: ImageFit, )

Draw source into bounds, placed per fit. A bitmap is scaled into the fitted rect (clipped to bounds for ImageFit::Cover); an SVG is rasterized at bounds’ physical size (see Scene::scale) so it stays sharp.

Source§

impl Scene

Source

pub fn new(logical_size: Size) -> Self

Create an empty scene covering logical_size.

Source

pub fn set_scale(&mut self, scale: f64)

Set the physical-per-logical pixel scale this scene will be shown at.

Source

pub fn scale(&self) -> f64

The physical-per-logical pixel scale this scene will be shown at.

Source

pub fn draw_image(&mut self, rect: Rect, image: Arc<Pixmap>)

Draw image (straight-alpha RGBA) into rect.

Source

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

Begin clipping subsequently-emitted primitives to rect; nests until the matching pop_clip. Used by scroll containers to mask overflowing content to the viewport.

Source

pub fn pop_clip(&mut self)

End the innermost clip region opened by push_clip, folding its primitives into a clipped group. A no-op if none is open (or the innermost open region is a layer).

Source

pub fn push_layer(&mut self, transform: Affine, opacity: f32)

Begin a layer: primitives emitted until the matching pop_layer are drawn through transform (mapping logical pixels to logical pixels, inside any enclosing layer’s) and composited as a group at opacity (0.0..=1.0): the layer’s content is rendered at full opacity on its own, then blended once, so overlapping primitives inside it don’t show through each other. Layers and clips nest freely; a clip opened inside a layer is transformed with it.

Source

pub fn pop_layer(&mut self)

End the innermost layer opened by push_layer. A no-op if none is open (or the innermost open region is a clip).

Source

pub fn has_effects(&self) -> bool

Whether any layer pushed so far moves things or makes them translucent (a DrawCmd::PushLayer with a non-identity transform or an opacity below 1). Backends that can’t draw layers natively fall back on this.

Source

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

The structured draw commands recorded by the typed helpers (for a GPU backend; the CPU rasterizer uses the lowered nodes instead).

Source

pub fn logical_size(&self) -> Size

The scene’s extent in logical pixels.

Source

pub fn len(&self) -> usize

Number of top-level primitives queued (at the root clip level).

Source

pub fn is_empty(&self) -> bool

Source

pub fn stroke_round_rect( &mut self, rect: Rect, radius: f64, color: Color, width: f64, )

Stroke the outline of a rectangle with rounded corners.

Source

pub fn fill_rect(&mut self, rect: Rect, color: Color)

Fill an axis-aligned rectangle with a solid color.

Source

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

Fill a rectangle with rounded corners (corner radius in logical pixels, clamped to half the shorter side).

Source

pub fn stroke_rect(&mut self, rect: Rect, color: Color, width: f64)

Stroke the outline of a rectangle with the given line width.

Source

pub fn fill_viewport(&mut self, rect: Rect, id: u64, placeholder: Color)

Reserve an embedded-content area rect for the viewport id, painting a solid placeholder so the region is visible before any content is composited in. Records a DrawCmd::Viewport so a GPU backend can texture the rect from an imported content surface instead, and so the app can locate the rect to blit registered CPU content over the placeholder.

Source

pub fn push_node(&mut self, node: Node)

Escape hatch: push a pre-built oxideav scene-graph node. Lets callers emit text runs, images, gradients, or clips that the typed helpers don’t yet cover.

Source

pub fn into_vector_frame(self) -> VectorFrame

Lower the scene to an oxideav-core VectorFrame.

The frame carries a view box equal to the logical size, so the rasterizer maps logical pixels onto whatever physical canvas size the renderer was constructed with — that mapping is the DPI scale.

Source

pub fn into_vector_frame_region(self, view: Rect) -> VectorFrame

Lower to a frame whose view box is view — a logical-pixel sub-rect of the scene. A renderer sized to that region’s physical pixels then rasterizes only the region; content outside it is clipped by the canvas bounds. Used for area-limited repaints (see SoftwareRenderer::render_region).

Source§

impl Scene

Source

pub fn fill_text( &mut self, font: &Font, text: &str, origin: Point, size_px: f64, color: Color, )

Shape and paint text with font at origin (the top-left of the text box, logical pixels), size_px, and color. Newlines (\n) start a new line, each dropped by one line_height from the last.

Each line goes through the Unicode Bidirectional Algorithm, with its direction taken from its first strong character; right-to-left lines are aligned to the right edge of the widest line. Use Font::layout and Scene::fill_layout to choose the direction or the alignment width.

Source

pub fn fill_layout( &mut self, layout: &TextLayout<'_>, origin: Point, color: Color, )

Paint a TextLayout with its top-left at origin, in color.

Glyphs are emitted as scene-graph nodes under a group translated to each line’s baseline, so they rasterize and composite like any other primitive.

Trait Implementations§

Source§

impl Clone for Scene

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Scene

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Forget for Scene

§

impl Freeze for Scene

§

impl RefUnwindSafe for Scene

§

impl Send for Scene

§

impl Sync for Scene

§

impl Unpin for Scene

§

impl UnsafeUnpin for Scene

§

impl UnwindSafe for Scene

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.