pub struct Layout { /* private fields */ }Expand description
A Layout is a dynamic representation of items that have been placed in a container at specific positions.
Items can be placed and removed. The container can be swapped. Snapshots can be taken and restored to.
Each layout maintains a CDEngine, which can be used to check for collisions before placing items.
Implementations§
Source§impl Layout
impl Layout
pub fn new(container: Container) -> Self
pub fn from_snapshot(ls: &LayoutSnapshot) -> Self
Sourcepub fn swap_container(&mut self, container: Container)
pub fn swap_container(&mut self, container: Container)
Replaces the current container with a new one, rebuilding the collision detection engine accordingly.
Sourcepub fn save(&self) -> LayoutSnapshot
pub fn save(&self) -> LayoutSnapshot
Saves the current state of the layout to be potentially restored to later.
Sourcepub fn restore(
&mut self,
layout_snapshot: &LayoutSnapshot,
) -> Result<(), ContainerMismatch>
pub fn restore( &mut self, layout_snapshot: &LayoutSnapshot, ) -> Result<(), ContainerMismatch>
Restores the layout from a snapshot.
§Errors
Returns ContainerMismatch if the snapshot uses a different container,
leaving the layout unchanged.
Use Layout::swap_container first or Layout::from_snapshot to
restore a snapshot with a different container.
Sourcepub fn place_item(
&mut self,
item: &Arc<Item>,
d_transformation: DTransformation,
) -> PItemKey
pub fn place_item( &mut self, item: &Arc<Item>, d_transformation: DTransformation, ) -> PItemKey
Places an item in the layout at a specific position by applying a transformation. Returns the unique key for the placed item. Does not check collisions or orientation permissions before placement.
Sourcepub fn remove_item(&mut self, pk: PItemKey) -> PlacedItem
pub fn remove_item(&mut self, pk: PItemKey) -> PlacedItem
Removes an item from the layout by its unique key and returns the removed PlacedItem.
Sourcepub fn density(&self) -> f32
pub fn density(&self) -> f32
The current density of the layout defined as the ratio of the area of the items placed to the area of the container. Uses the original shapes of items and container to calculate the area.
Sourcepub fn placed_item_area(&self) -> f32
pub fn placed_item_area(&self) -> f32
The sum of the areas of the items placed in the layout (using the original shapes of the items).
Sourcepub fn is_collision_free(&self) -> bool
pub fn is_collision_free(&self) -> bool
Returns true if no placed item collides with the container or another item. Quality zones meeting each item’s minimum quality are ignored; holes remain blocking.
Sourcepub fn placed_items(&self) -> &SlotMap<PItemKey, PlacedItem>
pub fn placed_items(&self) -> &SlotMap<PItemKey, PlacedItem>
All the items that have been placed in this layout, indexed by a unique key
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Layout
impl RefUnwindSafe for Layout
impl Send for Layout
impl Sync for Layout
impl Unpin for Layout
impl UnsafeUnpin for Layout
impl UnwindSafe for Layout
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more