Skip to main content

Module nine_patch

Module nine_patch 

Source
Expand description

Filling a box with an image that is bigger, or smaller, than the box.

Two questions this answers that a plain scale cannot. A tiled fill repeats its source instead of stretching it, which is how a texture, a hatch or a skin’s background covers an area of any size without going soft. And a nine-patch fill keeps the corners of a source at their own size while the edges and the middle grow, which is how a button, a panel or a scrollbar trough drawn once at one size is drawn correctly at every other.

Both are expressed the same way: a list of source-rectangle to destination-rectangle pairs, each of which is one ordinary image draw. That keeps the answer identical on every backend and, unlike a repeating sampler, cannot bleed a neighbouring sprite in from a shared atlas — the sprite an application tiles is usually a region of an atlas, and a wrapped sampler reads whatever is next to it.

Structs§

NinePatchInsets
How far in from each edge of a source image the stretchable middle starts.
PatchQuad
One image draw: the part of the source to read and the part of the destination to fill.

Enums§

PatchFill
How a region larger than its source is filled.

Functions§

nine_patch_quads
The draws that fill destination with source as a nine-patch.
tile_count
How many tiles tile_quads would produce, without building them.
tile_quads
The draws that tile source across destination at the source’s own size.