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: u32Implementations§
Source§impl NineSlice
impl NineSlice
pub const fn new(left: u32, right: u32, top: u32, bottom: u32) -> NineSlice
Sourcepub fn from_center(frame: Rect, center: Rect) -> Option<NineSlice>
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.
Sourcepub fn fits_in(&self, frame: Rect) -> bool
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.
Sourcepub const fn minimum_size(&self) -> (u32, u32)
pub const fn minimum_size(&self) -> (u32, u32)
The smallest size this slice can be drawn at without the fixed parts overlapping, in pixels.