Struct riddle_image::packer::ImagePacker[][src]

pub struct ImagePacker { /* fields omitted */ }

Utility for packing multiple images to a single image.

Example

let mut img1 = Image::new(2,2);
let mut img2 = Image::new(3,3);
let packed = ImagePacker::new().pack(&[&img1, &img2]).unwrap();

assert!(packed.image().dimensions().x > 3 || packed.image().dimensions().y > 3);
assert_eq!(img1.dimensions(), packed.rects()[0].dimensions);
assert_eq!(img2.dimensions(), packed.rects()[1].dimensions);

Implementations

impl ImagePacker[src]

pub fn new() -> Self[src]

Create the ImagePacker, with default settings.

pub fn size_policy(&mut self, policy: ImagePackerSizePolicy) -> &mut Self[src]

Set the size policy for the packer. This controls how the packing algorithm sizes the output image, and how those dimensions grow if the algorithm needs to grow the output image.

Example

let mut img1 = Image::new(2,2);
let mut img2 = Image::new(3,3);
let packed = ImagePacker::new()
    .size_policy(ImagePackerSizePolicy::Fixed(Vector2::new(10, 10)))
    .pack(&[&img1, &img2]).unwrap();

assert_eq!(Vector2::new(10, 10), packed.image().dimensions());

pub fn padding(&mut self, amount: u32) -> &mut Self[src]

The padding around each image in pixels.The gap between images will thus be twice the padding value.

Example

let mut img1 = Image::new(2,2);
let packed = ImagePacker::new()
    .size_policy(ImagePackerSizePolicy::Pow2Square)
    .padding(1)
    .pack(&[&img1]).unwrap();

assert_eq!(Vector2::new(4,4), packed.image().dimensions());
assert_eq!(Vector2::new(1,1), packed.rects()[0].location);

pub fn pack(
    &self,
    images: &[&Image]
) -> Result<ImagePackerResult, ImagePackerError>
[src]

Pack the slice of images provides in to a single image using the settings stored in the image packer. The values in ImagePackerResult::rects() will reference images in the same order as the slice provided.

If the slice is empty an Error result will be returned

Example

let mut img1 = Image::new(2,2);
let mut img2 = Image::new(3,3);
let packed = ImagePacker::new()
    .pack(&[&img1, &img2]).unwrap();

assert_eq!(Vector2::new(2, 2), packed.rects()[0].dimensions);
assert_eq!(Vector2::new(3, 3), packed.rects()[1].dimensions);

Trait Implementations

impl Default for ImagePacker[src]

Auto Trait Implementations

impl RefUnwindSafe for ImagePacker

impl Send for ImagePacker

impl Sync for ImagePacker

impl Unpin for ImagePacker

impl UnwindSafe for ImagePacker

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pointable for T

type Init = T

The type for initializers.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.