pub struct Layout {
pub container: Container,
pub placed_items: SlotMap<PItemKey, PlacedItem>,
/* 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.
Fields§
§container: Container
The container used for this layout
placed_items: SlotMap<PItemKey, PlacedItem>
All the items that have been placed in this layout, indexed by a unique key
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(&mut self) -> LayoutSnapshot
pub fn save(&mut self) -> LayoutSnapshot
Saves the current state of the layout to be potentially restored to later.
Sourcepub fn restore(&mut self, layout_snapshot: &LayoutSnapshot)
pub fn restore(&mut self, layout_snapshot: &LayoutSnapshot)
Restores the layout to a previous state using a snapshot.
Sourcepub fn place_item(
&mut self,
item: &Item,
d_transformation: DTransformation,
) -> PItemKey
pub fn place_item( &mut self, item: &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.
Sourcepub fn remove_item(&mut self, pk: PItemKey, commit_instant: bool) -> PlacedItem
pub fn remove_item(&mut self, pk: PItemKey, commit_instant: bool) -> PlacedItem
Removes an item from the layout by its unique key and returns the removed PlacedItem
.
If commit_instant
is true, the removal is immediately fully executed to the collision detection engine.
If false, the item is disabled in the collision detection engine, but not yet fully removed.
Useful for scenarios with high probability of reverting the removal.
Sourcepub fn density(&self, instance: &impl Instance) -> f32
pub fn density(&self, instance: &impl Instance) -> 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, instance: &impl Instance) -> f32
pub fn placed_item_area(&self, instance: &impl Instance) -> f32
The sum of the areas of the items placed in the layout (using the original shapes of the items).
Sourcepub fn is_feasible(&self) -> bool
pub fn is_feasible(&self) -> bool
Returns true if all the items are placed without colliding
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 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