Skip to main content

NineSlice

Struct NineSlice 

Source
pub struct NineSlice {
    pub left: u32,
    pub right: u32,
    pub top: u32,
    pub bottom: u32,
}
Expand description

Re-exported because SheetDesc::sample is spelled in it: a crate whose public API names a foreign type and does not export it is one every caller has to add a dependency for.

NineSlice and Rect are here for the same reason — NineSliceSource’s fields are spelled in both. The four insets that make a frame stretchable.

A nine-slice splits a frame into a 3×3 grid: the four corners never scale, the top and bottom edges stretch horizontally only, the left and right edges stretch vertically only, and the centre stretches both ways. That is what keeps a button’s rounded corner square at any size, and what lets one pipe image serve a gap of any height.

Stored as insets rather than as Aseprite’s centre rectangle because insets are what the geometry needs and what a human can write; the two are the same information and NineSlice::from_center converts.

Fields§

§left: u32§right: u32§top: u32§bottom: u32

Implementations§

Source§

impl NineSlice

Source

pub const fn new(left: u32, right: u32, top: u32, bottom: u32) -> NineSlice

Source

pub fn from_center(frame: Rect, center: Rect) -> Option<NineSlice>

The insets implied by Aseprite’s center rect inside a frame rect.

Aseprite stores the middle of the nine, positioned relative to the slice’s own bounds. Returns None when the centre is not actually inside the frame, which is a malformed export rather than a slice with odd insets.

Source

pub fn fits_in(&self, frame: Rect) -> bool

Whether these insets leave a non-negative centre inside frame.

Insets that overlap would give the centre a negative size, and the geometry builder would produce inside-out quads that render as nothing — a sprite that silently disappears at one size and not another.

Source

pub const fn minimum_size(&self) -> (u32, u32)

The smallest size this slice can be drawn at without the fixed parts overlapping, in pixels.

Trait Implementations§

Source§

impl Clone for NineSlice

Source§

fn clone(&self) -> NineSlice

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for NineSlice

Source§

impl Debug for NineSlice

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for NineSlice

Source§

fn default() -> NineSlice

Returns the “default value” for a type. Read more
Source§

impl Eq for NineSlice

Source§

impl PartialEq for NineSlice

Source§

fn eq(&self, other: &NineSlice) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for NineSlice

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> HalThreadSafe for T
where T: Send + Sync,

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,

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.