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

source

pub fn with_options(size: Size, options: &AllocatorOptions) -> Self

Create an atlas allocator with provided options.

source

pub fn new(size: Size) -> Self

Create an atlas allocator with default options.

source

pub fn clear(&mut self)

source

fn init(&mut self)

source

pub fn size(&self) -> Size

source

pub fn allocate(&mut self, size: Size) -> Option<Allocation>

Allocate a rectangle in the atlas.

source

pub fn deallocate(&mut self, id: AllocId)

Deallocate a rectangle in the atlas.

source

pub fn is_empty(&self) -> bool

source

pub fn allocated_space(&self) -> i32

Amount of occupied space in the atlas.

source

pub fn free_space(&self) -> i32

How much space is available for future allocations.

source

pub fn iter(&self) -> Iter<'_>

source

fn remove_item(&mut self, idx: ItemIndex)

source

fn remove_shelf(&mut self, idx: ShelfIndex)

source

fn add_item(&mut self, item: Item) -> ItemIndex

source

fn add_shelf(&mut self, shelf: Shelf) -> ShelfIndex

source

fn check(&self)

source

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).
source

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.

source

pub fn dump_svg(&self, output: &mut dyn Write) -> Result<()>

Dump a visual representation of the atlas in SVG format.

source

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

source§

fn clone(&self) -> AtlasAllocator

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'de> Deserialize<'de> for AtlasAllocator

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<'l> IntoIterator for &'l AtlasAllocator

§

type Item = Allocation

The type of the elements being iterated over.
§

type IntoIter = Iter<'l>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Iter<'l>

Creates an iterator from a value. Read more
source§

impl Serialize for AtlasAllocator

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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<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> ToOwned for T
where T: Clone,

§

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>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,