Struct etagere::AtlasAllocator
source · pub struct AtlasAllocator {
shelves: Vec<Shelf>,
items: Vec<Item>,
alignment: Size,
flip_xy: bool,
size: Size,
first_shelf: ShelfIndex,
free_items: ItemIndex,
free_shelves: ShelfIndex,
shelf_width: u16,
allocated_space: i32,
}
Expand description
A shelf-packing dynamic texture atlas allocator tracking each allocation individually and with support for coalescing empty shelves.
Fields§
§shelves: Vec<Shelf>
§items: Vec<Item>
§alignment: Size
§flip_xy: bool
§size: Size
§first_shelf: ShelfIndex
§free_items: ItemIndex
§free_shelves: ShelfIndex
§shelf_width: u16
§allocated_space: i32
Implementations§
source§impl AtlasAllocator
impl AtlasAllocator
sourcepub fn with_options(size: Size, options: &AllocatorOptions) -> Self
pub fn with_options(size: Size, options: &AllocatorOptions) -> Self
Create an atlas allocator with provided options.
pub fn clear(&mut self)
fn init(&mut self)
pub fn size(&self) -> Size
sourcepub fn allocate(&mut self, size: Size) -> Option<Allocation>
pub fn allocate(&mut self, size: Size) -> Option<Allocation>
Allocate a rectangle in the atlas.
sourcepub fn deallocate(&mut self, id: AllocId)
pub fn deallocate(&mut self, id: AllocId)
Deallocate a rectangle in the atlas.
pub fn is_empty(&self) -> bool
sourcepub fn allocated_space(&self) -> i32
pub fn allocated_space(&self) -> i32
Amount of occupied space in the atlas.
sourcepub fn free_space(&self) -> i32
pub fn free_space(&self) -> i32
How much space is available for future allocations.
pub fn iter(&self) -> Iter<'_> ⓘ
fn remove_item(&mut self, idx: ItemIndex)
fn remove_shelf(&mut self, idx: ShelfIndex)
fn add_item(&mut self, item: Item) -> ItemIndex
fn add_shelf(&mut self, shelf: Shelf) -> ShelfIndex
fn check(&self)
sourcepub fn get_index(&self, id: AllocId) -> u32
pub fn get_index(&self, id: AllocId) -> u32
Turn a valid AllocId into an index that can be used as a key for external storage.
The allocator internally stores all items in a single vector. In addition allocations stay at the same index in the vector until they are deallocated. As a result the index of an item can be used as a key for external storage using vectors. Note that:
- The provided ID must correspond to an item that is currently allocated in the atlas.
- After an item is deallocated, its index may be reused by a future allocation, so the returned index should only be considered valid during the lifetime of the its associated item.
- indices are expected to be “reasonable” with respect to the number of allocated items, in other words it is never larger than the maximum number of allocated items in the atlas (making it a good fit for indexing within a sparsely populated vector).
sourcepub fn get(&self, id: AllocId) -> Rectangle
pub fn get(&self, id: AllocId) -> Rectangle
Returns the allocation info associated to the allocation ID.
The id must correspond to an existing allocation in the atlas.
sourcepub fn dump_svg(&self, output: &mut dyn Write) -> Result<()>
pub fn dump_svg(&self, output: &mut dyn Write) -> Result<()>
Dump a visual representation of the atlas in SVG format.
sourcepub fn dump_into_svg(
&self,
rect: Option<&Rectangle>,
output: &mut dyn Write,
) -> Result<()>
pub fn dump_into_svg( &self, rect: Option<&Rectangle>, output: &mut dyn Write, ) -> Result<()>
Dump a visual representation of the atlas in SVG, omitting the beginning and end of the SVG document, so that it can be included in a larger document.
If a rectangle is provided, translate and scale the output to fit it.
Trait Implementations§
source§impl Clone for AtlasAllocator
impl Clone for AtlasAllocator
source§fn clone(&self) -> AtlasAllocator
fn clone(&self) -> AtlasAllocator
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more