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, ResourceStore, ValidatedDisplayList, MAX_PATH_VERBS,
MAX_STROKE_VERBS, MAX_SVG_PATH_BYTES, sample_offsets,
};
use motion_render::{Composition, RenderPrepare, RenderOptions, BackendKind, 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
impl LabelLayout
Sourcepub fn obstacle(self, bounds: Rect) -> Self
pub fn obstacle(self, bounds: Rect) -> Self
Adds fixed artwork to avoid; at most 256 obstacles are accepted by place.
Sourcepub fn place(
&self,
labels: &[Label],
) -> Result<Vec<Option<Rect>>, ValidationError>
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
impl Clone for LabelLayout
Auto Trait Implementations§
impl Forget for LabelLayout
impl Freeze for LabelLayout
impl Move for LabelLayout
impl RefUnwindSafe for LabelLayout
impl Send for LabelLayout
impl Sync for LabelLayout
impl Unpin for LabelLayout
impl UnsafeUnpin for LabelLayout
impl UnwindSafe for LabelLayout
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more