Skip to main content

LabelLayout

Struct LabelLayout 

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

Eight candidate positions per label; unplaceable labels are explicitly omitted. Placement is greedy: accepted labels are never moved to make room for later ones. Stable ordering does not guarantee a globally optimal or temporally smooth layout.

use motion_content::prelude::*;
use motion_core::prelude::*;
use motion_core::{
    DisplayList, RasterLimits, ResourcePool, ValidatedDisplayList, MAX_PATH_VERBS,
    MAX_STROKE_VERBS, MAX_SVG_PATH_BYTES, sample_offsets,
};
use motion_render::{Composition, RenderPrepare, RenderOptions, Renderer, render_still};
use motion_content::diagram::*;
let labels = [Label::new(Point::new(50.0, 50.0), Size::new(40.0, 30.0))];
let positions = LabelLayout::new(Rect::new(0.0, 0.0, 100.0, 100.0))
    .gap(2.0)
    .place(&labels)?;
assert_eq!(positions, [Some(Rect::new(52.0, 18.0, 92.0, 48.0))]);

Implementations§

Source§

impl LabelLayout

Source

pub fn new(bounds: Rect) -> Self

Creates a placement viewport with a four-pixel separation.

Source

pub fn gap(self, pixels: f64) -> Self

Replaces finite spacing in 0..=1024 pixels.

Source

pub fn obstacle(self, bounds: Rect) -> Self

Adds fixed artwork to avoid; at most 256 obstacles are accepted by place.

Source

pub fn place( &self, labels: &[Label], ) -> Result<Vec<Option<Rect>>, ValidationError>

Returns positions in input order. None means no collision-free candidate fits. Placement is stateless and bounded to 256 labels and 256 obstacles. Invalid geometry, nonpositive label/viewport dimensions, invalid spacing or exceeded counts return std::io::ErrorKind::InvalidInput, not omitted labels.

Trait Implementations§

Source§

impl Clone for LabelLayout

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 LabelLayout

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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

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.