pub struct NineSlice { /* private fields */ }Expand description
A source image paired with the insets that split it into nine patches.
Corners keep their natural size, the four edge patches stretch along
one axis only, and the center patch stretches along both — so a
bordered panel can be resized to any destination size without
distorting its corners. The geometry itself lives on
NineSliceInsets; this type only carries the image handle so it
can be stored inside a deferred DrawCommand.
Implementations§
Source§impl NineSlice
Implements image-backed nine-slice drawing and deferred recording.
impl NineSlice
Implements image-backed nine-slice drawing and deferred recording.
Sourcepub fn from_image(image: HtmlImageElement, border: f64) -> NineSlice
pub fn from_image(image: HtmlImageElement, border: f64) -> NineSlice
Sourcepub fn source_rects(&self) -> NineSliceRects
pub fn source_rects(&self) -> NineSliceRects
Returns the nine source sub-rectangles for the whole source image.
§Returns
NineSliceRects- The nine source sub-rectangles in reading order.
Sourcepub fn dest_rects(&self, dest: Rect) -> NineSliceRects
pub fn dest_rects(&self, dest: Rect) -> NineSliceRects
Sourcepub fn draw_into(&self, context: &CanvasRenderingContext2d, dest: Rect)
pub fn draw_into(&self, context: &CanvasRenderingContext2d, dest: Rect)
Draws the nine-slice into a destination rectangle immediately.
Issues nine drawImage calls against the canvas context, pairing
each source patch with its destination sub-rectangle. Uses the
canvas transform already in effect, so the caller controls world
positioning, rotation and scale.
§Arguments
&CanvasRenderingContext2d- The canvas context.Rect- The destination rectangle in current canvas space.
Sourcepub fn record(
&self,
list: &mut DrawList,
dest_position: Vector2D,
dest_width: f64,
dest_height: f64,
)
pub fn record( &self, list: &mut DrawList, dest_position: Vector2D, dest_width: f64, dest_height: f64, )
Records the nine-slice into a deferred draw list.
The command carries the image plus the insets rather than the nine resolved sub-rectangles, so the split is recomputed at replay time against whatever destination size the command was recorded with.
§Arguments
&mut DrawList- The draw list to record into.Vector2D- The destination top-left position in world space.f64- The destination width in pixels.f64- The destination height in pixels.