Skip to main content

Node

Struct Node 

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

A cheaply cloned snapshot of authored grouping and compositing choices.

Drawable values convert directly into leaves with content bounds. Grouping and modifiers retain geometry and explicit drawing policy.

use motion_core::prelude::*;
use motion_core::{
    DisplayList, RasterLimits, ResourceStore, ValidatedDisplayList, MAX_PATH_VERBS,
    MAX_STROKE_VERBS, MAX_SVG_PATH_BYTES, sample_offsets,
};
let artwork = Rect::new(0.0, 0.0, 32.0, 24.0).fill(Color::rgb(20, 150, 125));
let node = Node::group([Node::from(artwork).z_index(2)])
    .opacity(0.5)
    .named("overlay");
node.compile(
    Size::new(32.0, 24.0),
    PixelSize::new(32, 24),
    ValidationLimits::default(),
)?;

Implementations§

Source§

impl Node

Source

pub fn inspect_with_context( &self, design_size: Size, output_size: PixelSize, limits: ValidationLimits, drawing: &DrawContext, ) -> Result<Vec<NodeInspection>, ValidationError>

Plans a bounded editor snapshot using the same layout, resources and z order as compilation. Drawables may resolve/record; no pixels or devices are used. Errors remain separate from normal rendering when used by an editor.

Source§

impl Node

Source

pub fn compile( &self, design_size: Size, output_size: PixelSize, limits: ValidationLimits, ) -> Result<ValidatedDisplayList, ValidationError>

Compiles content to flat device-space commands without rendering.

Logical design space is contained and centered in the output dimensions. bounds/draw callbacks receive the resulting device scale once per occurrence. Layout and stable sibling z order precede matrix composition. Nonunit opacity isolates its whole subtree without f32 narrowing.

All input branches and emitted work validate, including empty, transparent and offscreen content. There is no culling yet. Source and output have independent instances of the supplied limits. This does not prepare coverage/pixels.

use motion_core::prelude::*;
use motion_core::{
    DisplayList, RasterLimits, ResourceStore, ValidatedDisplayList, MAX_PATH_VERBS,
    MAX_STROKE_VERBS, MAX_SVG_PATH_BYTES, sample_offsets,
};
use motion_core::authoring::Scene as _;
let cache = SceneCache::new(0);
let context = SceneContext::new(
    Time::ZERO,
    fps!(30),
    Size::new(100.0, 50.0),
    &cache,
);
let scene = |context: &SceneContext<'_>| {
    let path = Path2D::from_rect(Rect::new(0.0, 0.0, 10.0, 10.0)).unwrap();
    Row::new()
        .gap(4.0)
        .children([
            Node::from(Rect::new(0.0, 0.0, 10.0, 20.0).fill(Color::WHITE)),
            Node::from(path.fill(Color::from_hex(0x24a49b))),
        ])
        .at(context.center())
        .opacity(0.5)
};
let list = scene.render(&context).compile(
    context.size(),
    PixelSize::new(200, 200),
    ValidationLimits::default(),
)?;
assert_eq!(list.commands.len(), 4);
assert!(matches!(
    list.commands[0],
    DrawCommand::PushLayer { opacity: 0.5, .. }
));
assert!(matches!(
    list.commands[2],
    DrawCommand::Fill {
        rule: FillRule::NonZero,
        ..
    }
));
list.preflight(ValidationLimits::default())?;
Source

pub fn compile_with_fonts( &self, design_size: Size, output_size: PixelSize, limits: ValidationLimits, fonts: impl Into<FontEnvironment>, ) -> Result<ValidatedDisplayList, ValidationError>

Compiles with one immutable font environment shared by paragraph callbacks.

Source

pub fn compile_with_context( &self, design_size: Size, output_size: PixelSize, limits: ValidationLimits, drawing: &DrawContext, ) -> Result<ValidatedDisplayList, ValidationError>

Compiles with explicit resources and a reusable session layout cache.

Source§

impl Node

Source

pub fn with_scene_time(self, time: Time) -> Self

Associates scene-local time with deferred content in this subtree.

Source

pub fn empty() -> Self

Creates a node with no artwork.

Source

pub fn next_to(self, reference: &Node, side: Side, gap: f64) -> Self

Positions a snapshot relative to compile-time measured reference bounds.

Source

pub fn align_to(self, reference: &Node, edge: Side) -> Self

Aligns an edge with a compile-time measured reference snapshot.

Source

pub fn accumulate( samples: impl IntoIterator<Item = Node>, ) -> Result<Self, ValidationError>

Averages 1..=64 independently rendered samples in linear premultiplied RGBA. Empty samples retain their weight; sibling z order cannot reorder samples.

Source

pub fn weighted_sum( samples: impl IntoIterator<Item = (Node, f64)>, ) -> Result<Self, ValidationError>

Composites 1..=64 isolated samples with explicit linear-light weights. Each weight must be finite in 0..=1; weights are not normalized.

Source

pub fn with_text_metrics(self, baseline: f64, bounds: Rect) -> Self

Attaches measured paragraph metrics for horizontal baseline layout. Content implementations must provide conservative local bounds and a real baseline.

Source

pub fn transformed(self, transform: Transform) -> Self

Applies a full local affine matrix in a new group, before subsequent placement modifiers.

Source

pub fn group<Kind>(children: impl IntoNodeGroup<Kind>) -> Self

Groups snapshots; sibling z indices are stably sorted during conversion.

Source

pub fn push(&mut self, child: impl Into<Node>)

Appends a drawable snapshot; nongroup nodes retain their original subtree.

Source

pub fn measure(&self, limits: ValidationLimits) -> Result<Rect, ValidationError>

Measures content or declared layout geometry in parent coordinates.

Uses f64 throughout, includes zero-area declared bounds and ignores empty nodes. Structure and parameters validate without pixel narrowing. Opacity does not change layout bounds. leaves call Drawable::bounds, not draw. Uses default drawing inputs at device scale one.

Source

pub fn preflight_with( &self, context: &DrawContext, limits: ValidationLimits, ) -> Result<SceneStats, ValidationError>

Validates structure and measured geometry without recording draw commands. Fonts, when required by content, must be supplied through the drawing context.

Source

pub fn measure_with( &self, context: &DrawContext, limits: ValidationLimits, ) -> Result<Rect, ValidationError>

Measures with explicit, time-independent drawing inputs.

Device scale is metadata for content; this adapter does not apply the future scene-to-device root transform or infer resource environments.

Source§

impl Node

Source

pub fn deferred(content: impl DeferredContent + 'static) -> Self

Wraps content that expands into ordinary nodes at compile time.

Trait Implementations§

Source§

impl Clone for Node

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 Node

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Node

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<()> for Node

Source§

fn from(_: ()) -> Self

Converts to this type from the input type.
Source§

impl<First: Into<Node>, Second: Into<Node>> From<(First, Second)> for Node

Source§

fn from(values: (First, Second)) -> Self

Converts to this type from the input type.
Source§

impl<First: Into<Node>, Second: Into<Node>, Third: Into<Node>> From<(First, Second, Third)> for Node

Source§

fn from(values: (First, Second, Third)) -> Self

Converts to this type from the input type.
Source§

impl<First: Into<Node>, Second: Into<Node>, Third: Into<Node>, Fourth: Into<Node>> From<(First, Second, Third, Fourth)> for Node

Source§

fn from(values: (First, Second, Third, Fourth)) -> Self

Converts to this type from the input type.
Source§

impl<First: Into<Node>, Second: Into<Node>, Third: Into<Node>, Fourth: Into<Node>, Fifth: Into<Node>> From<(First, Second, Third, Fourth, Fifth)> for Node

Source§

fn from(values: (First, Second, Third, Fourth, Fifth)) -> Self

Converts to this type from the input type.
Source§

impl<First: Into<Node>, Second: Into<Node>, Third: Into<Node>, Fourth: Into<Node>, Fifth: Into<Node>, Sixth: Into<Node>> From<(First, Second, Third, Fourth, Fifth, Sixth)> for Node

Source§

fn from(values: (First, Second, Third, Fourth, Fifth, Sixth)) -> Self

Converts to this type from the input type.
Source§

impl<First: Into<Node>, Second: Into<Node>, Third: Into<Node>, Fourth: Into<Node>, Fifth: Into<Node>, Sixth: Into<Node>, Seventh: Into<Node>> From<(First, Second, Third, Fourth, Fifth, Sixth, Seventh)> for Node

Source§

fn from(values: (First, Second, Third, Fourth, Fifth, Sixth, Seventh)) -> Self

Converts to this type from the input type.
Source§

impl<First: Into<Node>, Second: Into<Node>, Third: Into<Node>, Fourth: Into<Node>, Fifth: Into<Node>, Sixth: Into<Node>, Seventh: Into<Node>, Eighth: Into<Node>> From<(First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth)> for Node

Source§

fn from( values: (First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth), ) -> Self

Converts to this type from the input type.
Source§

impl<First: Into<Node>, Second: Into<Node>, Third: Into<Node>, Fourth: Into<Node>, Fifth: Into<Node>, Sixth: Into<Node>, Seventh: Into<Node>, Eighth: Into<Node>, Ninth: Into<Node>> From<(First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth)> for Node

Source§

fn from( values: (First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth), ) -> Self

Converts to this type from the input type.
Source§

impl<First: Into<Node>, Second: Into<Node>, Third: Into<Node>, Fourth: Into<Node>, Fifth: Into<Node>, Sixth: Into<Node>, Seventh: Into<Node>, Eighth: Into<Node>, Ninth: Into<Node>, Tenth: Into<Node>> From<(First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth, Tenth)> for Node

Source§

fn from( values: (First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth, Tenth), ) -> Self

Converts to this type from the input type.
Source§

impl<First: Into<Node>, Second: Into<Node>, Third: Into<Node>, Fourth: Into<Node>, Fifth: Into<Node>, Sixth: Into<Node>, Seventh: Into<Node>, Eighth: Into<Node>, Ninth: Into<Node>, Tenth: Into<Node>, Eleventh: Into<Node>> From<(First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth, Tenth, Eleventh)> for Node

Source§

fn from( values: (First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth, Tenth, Eleventh), ) -> Self

Converts to this type from the input type.
Source§

impl<First: Into<Node>, Second: Into<Node>, Third: Into<Node>, Fourth: Into<Node>, Fifth: Into<Node>, Sixth: Into<Node>, Seventh: Into<Node>, Eighth: Into<Node>, Ninth: Into<Node>, Tenth: Into<Node>, Eleventh: Into<Node>, Twelfth: Into<Node>> From<(First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth, Tenth, Eleventh, Twelfth)> for Node

Source§

impl<First: Into<Node>, Second: Into<Node>, Third: Into<Node>, Fourth: Into<Node>, Fifth: Into<Node>, Sixth: Into<Node>, Seventh: Into<Node>, Eighth: Into<Node>, Ninth: Into<Node>, Tenth: Into<Node>, Eleventh: Into<Node>, Twelfth: Into<Node>, Thirteenth: Into<Node>> From<(First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth, Tenth, Eleventh, Twelfth, Thirteenth)> for Node

Source§

impl<First: Into<Node>, Second: Into<Node>, Third: Into<Node>, Fourth: Into<Node>, Fifth: Into<Node>, Sixth: Into<Node>, Seventh: Into<Node>, Eighth: Into<Node>, Ninth: Into<Node>, Tenth: Into<Node>, Eleventh: Into<Node>, Twelfth: Into<Node>, Thirteenth: Into<Node>, Fourteenth: Into<Node>> From<(First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth, Tenth, Eleventh, Twelfth, Thirteenth, Fourteenth)> for Node

Source§

impl<First: Into<Node>, Second: Into<Node>, Third: Into<Node>, Fourth: Into<Node>, Fifth: Into<Node>, Sixth: Into<Node>, Seventh: Into<Node>, Eighth: Into<Node>, Ninth: Into<Node>, Tenth: Into<Node>, Eleventh: Into<Node>, Twelfth: Into<Node>, Thirteenth: Into<Node>, Fourteenth: Into<Node>, Fifteenth: Into<Node>> From<(First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth, Tenth, Eleventh, Twelfth, Thirteenth, Fourteenth, Fifteenth)> for Node

Source§

impl<First: Into<Node>, Second: Into<Node>, Third: Into<Node>, Fourth: Into<Node>, Fifth: Into<Node>, Sixth: Into<Node>, Seventh: Into<Node>, Eighth: Into<Node>, Ninth: Into<Node>, Tenth: Into<Node>, Eleventh: Into<Node>, Twelfth: Into<Node>, Thirteenth: Into<Node>, Fourteenth: Into<Node>, Fifteenth: Into<Node>, Sixteenth: Into<Node>> From<(First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth, Tenth, Eleventh, Twelfth, Thirteenth, Fourteenth, Fifteenth, Sixteenth)> for Node

Source§

impl<First: Into<Node>> From<(First,)> for Node

Source§

fn from(values: (First,)) -> Self

Converts to this type from the input type.
Source§

impl From<Arc<dyn Drawable>> for Node

Source§

fn from(content: Arc<dyn Drawable>) -> Self

Converts to this type from the input type.
Source§

impl<Content: Drawable + 'static> From<Content> for Node

Source§

fn from(content: Content) -> Self

Converts to this type from the input type.
Source§

impl<Value: Into<Node>> From<Option<Value>> for Node

Source§

fn from(value: Option<Value>) -> Self

Converts to this type from the input type.
Source§

impl FromIterator<Node> for Node

Source§

fn from_iter<Iter: IntoIterator<Item = Node>>(iter: Iter) -> Self

Creates a value from an iterator. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Node

§

impl !UnwindSafe for Node

§

impl Forget for Node

§

impl Freeze for Node

§

impl Move for Node

§

impl Send for Node

§

impl Sync for Node

§

impl Unpin for Node

§

impl UnsafeUnpin for Node

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<Output> IntoSceneOutput for Output
where Output: Into<Node>,

Source§

fn into_scene_output(self) -> Result<Node, Error>

Preserves the original failure category and source.
Source§

impl<Value> NodeModifiers for Value
where Value: Into<Node>,

Source§

fn layered_shadow(self, color: Color, radius: f64, offset: Vector2) -> Node

Layers three soft silhouettes behind a single untouched source snapshot.
Source§

fn elevated(self, elevation: Elevation) -> Node

Layers contact, key and ambient soft shadows that scale with an Elevation.
Source§

fn gate_weave(self, seed: u64, frame: u64, amount: f64) -> Node

Repeatable physical gate drift, keyed only by an explicit frame and seed.
Source§

fn next_to(self, reference: &Node, side: Side, gap: f64) -> Node

Places content next to the reference during compile-time layout.
Source§

fn align_to(self, reference: &Node, edge: Side) -> Node

Aligns an edge with a compile-time measured reference snapshot.
Source§

fn at(self, position: impl Into<Point>) -> Node

Places the selected pivot at a parent-space point, before translation.
Source§

fn translate(self, horizontal: f64, vertical: f64) -> Node

Adds parent-space translation, after scale and rotation.
Source§

fn rotate(self, radians: f64) -> Node

Adds clockwise radians about the pivot, after scale and before translation.
Source§

fn scale(self, factor: f64) -> Node

Multiplies both scale factors; negative factors reflect and zero collapses.
Source§

fn scale_xy(self, horizontal: f64, vertical: f64) -> Node

Multiplies per-axis scale factors about the pivot.
Source§

fn pivot(self, pivot: Pivot) -> Node

Replaces the local-space pivot; defaults to the layout-bounds center.
Source§

fn opacity(self, opacity: f64) -> Node

Replaces subtree opacity; invalid values are reported during conversion.
Source§

fn blend_mode(self, mode: BlendMode) -> Node

Blends the completed subtree once against its immediate parent backdrop. Read more
Source§

fn filter(self, filter: Filter) -> Node

Appends a source-only filter, preserving declaration order. Read more
Source§

fn clip(self, shape: impl IntoShapeClip) -> Node

Replaces the subtree’s local path-coverage clip without changing layout. Read more
Source§

fn clip_with(self, shape: impl IntoShapeClip, mode: ClipMode) -> Node

Clips with explicit coverage multiplication or geometric intersection.
Source§

fn mask(self, mask: impl Into<Node>, mode: MaskMode) -> Node

Replaces the local geometric rectangle clip without changing layout. Read more
Source§

fn z_index(self, index: i32) -> Node

Replaces sibling-local stacking order; ties retain insertion order.
Source§

fn visible(self, visible: bool) -> Node

Removes the snapshot entirely when false, rather than evaluating it hidden.
Source§

fn named(self, name: &str) -> Node

Attaches a diagnostic name without changing artwork or draw order.
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.