Skip to content
Back to skills

Draw A Panel

ASecurity

Draw a bordered box of any size from one small piece of panel art. A nine-slice cuts the art into 4 corners, 4 edges, and a center: corners stay 1:1, edges and center stretch or tile to fill the box. For a plain filled box with no art, `BT.drawRectFill` is enough (draw-shapes skill).

  • 17 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added November 7, 2026
developmentgoaws

Security analysis

A100/100

Scanned November 24, 2026

npx -y skills add blit386/blit386 --skill draw-a-panel --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Draw A Panel?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Draw A Panel
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/blit386-draw-a-panel/badge)](https://www.skillsdirectory.com/skills/blit386-draw-a-panel)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: draw-a-panel
description:
  Draw UI panels, dialog boxes, buttons, window frames, and bars of any size from one small piece of panel art with a
  nine-slice (NineSlice.fromSheet + BT.drawNineSlice, engine 1.8.0+). Use whenever the user wants a bordered box, menu
  frame, speech bubble, health bar, or any pixel-art panel that must resize without blurry or stretched corners.
---

# Draw a panel

Draw a bordered box of any size from one small piece of panel art. A nine-slice cuts the art into 4 corners, 4 edges,
and a center: corners stay 1:1, edges and center stretch or tile to fill the box.

For a plain filled box with no art, `BT.drawRectFill` is enough (draw-shapes skill).

## How to do it

Load the sheet the same way as any sprite (add-sprite skill: a bigger palette, colors after the starter's own), build
the nine-slice once in `init()`, then draw it into any `Rect2i` in `render()`:

```js
import { BT, NineSlice, Rect2i, SpriteSheet, Vector2i } from 'blit386';

const FIRST_SPRITE_SLOT = COLOR_TEXT + 1; // the panel art's colors go after the starter's slots 1 to 4

async init() {
    // ...
    const palette = BT.paletteCreate(64); // the starter's palette, made bigger
    // ...the starter's palette.set(...) lines...
    const { sheet } = await SpriteSheet.loadIndexed('/sprites/ui.png', palette, FIRST_SPRITE_SLOT);
    this.ui = sheet;

    // Both rectangles are in sheet pixels. `outer` is the whole 16x16 panel,
    // `inner` is its 8x8 middle - the 4-pixel ring around it becomes the corners and edges.
    this.panel = NineSlice.fromSheet(this.ui, new Rect2i(0, 0, 16, 16), new Rect2i(4, 4, 8, 8), {
        edges: 'tile', // repeat the edge art 1:1 (default 'stretch')
        center: 'stretch', // stretch the middle (default)
    });

    this.dialogBox = new Rect2i(20, 160, 280, 64); // reuse the box instead of making one per frame
    BT.paletteSet(palette);
    // ...the rest of the starter's init()...
    return true;
}

render() {
    BT.clear(COLOR_BACKGROUND);
    BT.drawNineSlice(this.panel, this.dialogBox);
    BT.systemPrint(new Vector2i(28, 168), COLOR_TEXT, 'Hello, traveler!');
}
```

Recolor a panel the same way as a sprite, with a palette offset: `BT.drawNineSlice(this.panel, box, 16)` draws it with
every slot shifted by 16 (a second set of colors you put there in `init()`).

## Key calls

- `NineSlice.fromSheet(sheet, outer, inner, options?)` (static, engine 1.8.0+) - cut a sheet region into nine parts.
  `outer` must sit inside the sheet, `inner` inside `outer` and at least 1x1. `options` is `{ edges, center }`, each
  `'stretch'` (default) or `'tile'`. The result is frozen; build it once in `init()`.
- `BT.drawNineSlice(nineSlice, destRect, paletteOffset?)` (method, engine 1.8.0+) - draw it into a `Rect2i`. Allocates
  nothing, so it is fine every frame.

## Notes

- `'stretch'` suits flat colors and gradients; `'tile'` keeps dotted, striped, or riveted borders crisp. Mix them: tiled
  edges with a stretched center is the usual choice.
- A box smaller than the two corners crops the corners and drops the edges between them, so a panel can animate open
  from a zero-size `Rect2i` and keep its outline the whole way.
- `inner` may touch `outer`. A zero-height top and bottom makes a horizontal three-slice bar - good for health and
  progress bars.
- An empty or negative `destRect` draws nothing. There is no tint; recolor with `paletteOffset` only.
- Tiling a 1-pixel strip across a large box costs one draw per pixel. Stretch flat fills; tile only patterned art.
- Everything is whole pixels: both sheet rectangles and the destination `Rect2i`.

See `docs/drawing.md` and the add-sprite skill.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.