Icons & Vector

Check and export icons

An icon that looks right at 800% can still be soft on a screen, a little heavy beside the others, or open at one corner. Look it over before it leaves Nox: check it in numbers, look at it at the sizes it will be shown, and only then export. The checks take a minute. A fault found after the icon is in an app takes a release.

The same house before and after the check, at 16, 24 and 48 pixels
The same house before and after the check, at 16, 24 and 48 pixels

Check an icon#

check_icon looks one icon over as an icon designer would and says what to put right, in numbers. It changes nothing. It works on an icon's frame, its component, or a group.

CheckWhat it finds
pixel_gridLevel and upright edges that lie between pixels and will be soft, points on neither a whole nor a half unit, and a stroke weight that cannot be sharp at 1x
stroke_weight, caps_and_joinsA shape whose weight, caps or joins differ from the icon's others
open_pathAn outline left open whose ends all but meet, or an open line with a fill
keylineAnything that reaches, stroke included, into the margin an icon keeps clear, or out of the frame, and a drawing that is not in the middle
sizeA frame that is not square

The margin is a twelfth of the icon's size: 2 of 24, 4 of 48, and 1 of 16. padding sets another for an icon that needs one.

With an agent

Ask for the check and the fixes together.

Check the Home icon and fix what the check finds.

The agent calls check_icon with:

{ "node": "1710143285:5" }

For the rough house in the picture above, it answers with counts and a finding for each fault:

{
  "clean": false,
  "counts": { "keyline": 2, "open_path": 1, "pixel_grid": 2, "stroke_weight": 1 },
  "findings": [
    {
      "check": "stroke_weight", "name": "Door",
      "says": "its stroke is 1.5; the icon's others are 2",
      "fix": "set `stroke_width` to 2"
    },
    {
      "check": "pixel_grid", "name": "House",
      "says": "2 of its straight edges lie between pixels, and will be soft: x 20.5 (wants 21), y 20.4 (wants 20)",
      "fix": "move those points onto whole units"
    },
    {
      "check": "open_path", "name": "House",
      "says": "a contour of it is open, with its two ends 0.539 apart: it looks meant to be closed",
      "fix": "close it (end its `path` with Z, or give `closed`: true with `points`), so that its last corner is joined like the others"
    }
  ]
}

The agent makes each fix with update_nodes and checks again, until clean is true.

Every finding names the shape and says what to change it to. That makes them safe to fix one by one, and easy to read yourself.

Look at it at 16, 24 and 48#

Numbers miss what the eye catches: a gap that closes at 16, a curve that looks flat. render_preview with sizes draws an icon with exactly that many pixels at each size, then enlarges each with its pixels kept square, so you see what a screen will show.

render_preview with sizes 16, 24 and 48, for a light icon on a dark ground
render_preview with sizes 16, 24 and 48, for a light icon on a dark ground
{ "node": "1710143285:2", "sizes": [16, 24, 48], "background": "#1B1E26" }

Give background a dark color for a light icon. Up to six sizes fit on one sheet.

How to read it:

  • One clean row of full color along an edge is on the pixel grid.
  • Two rows, or a gray row, is between pixels at that size.
  • At 16, a 24 icon is soft wherever its lines fall between pixels, as in the 16 tile above. If the icon must be used at 16, draw a 16 version in a 16 frame.

By hand, look at the icon at View › Actual Size (⌘0), at the size it will be used, and turn on View › Pixel Grid (⇧') when you zoom in close.

Export as SVG#

SVG is what the web and most code take. Draw the icon in one color and export it with that color written as currentColor. Placed inline in a web page, the icon is then drawn in the color of the text around it, and one file serves for every color.

The export sheet with SVG chosen and its one switch on
The export sheet with SVG chosen and its one switch on
By hand
  1. Select the icon's frame or component.
  2. Choose File › Export… (⇧⌘E) and choose SVG.
  3. Turn on One colour as currentColor (for the web).
  4. Press Export 1 file and choose a folder.
With an agent

The agent calls export_svg with:

{ "node": "1710143285:2", "current_color": true }

It answers with the SVG as text, here broken into lines:

<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
  <g data-name="Home">
    <g data-name="House"><path d="M4 11 L12 4 L20 11 L20 18 C20 19.105 19.105 20 18 20 L6 20 C4.895 20 4 19.105 4 18 Z" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></g>
    <g data-name="Door"><path d="M10 20 L10 14 L14 14 L14 20" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></g>
  </g>
</svg>

The rounded corners are part of the path, and each shape keeps its name. Something not drawn in one plain color, such as several colors, a gradient, a picture, a mask, a shadow or a blur, is refused with the reason. Export it without the switch.

To export an icon that sits inside an instance, such as the glyph in a tab bar item, an agent uses export_layer with current_color and a path ending in .svg. See Export images, SVG and PDF.

Hand it to a SwiftUI app as a Shape#

An app that draws its icons itself, to animate a stroke or fill one part, wants outlines rather than a picture. Nox writes an icon as a SwiftUI Shape: a struct that draws the outlines in whatever rectangle it is given.

By hand

Right-click the icon and choose Copy as › SwiftUI Shape. Paste it into a Swift file. Nothing is copied from a text or an instance: select the icon's own frame or component.

With an agent

The agent calls inspect with shape: true:

{ "node": "1710143285:2", "shape": true }

The struct is in swiftui_shape. Its first lines say how to use it:

/// Home, drawn in Nox at 24 × 24. It fills the rectangle it is given:
/// keep that rectangle's sides as 24 to 24 for its own proportions.
///
///     HomeShape()
///         .stroke(style: StrokeStyle(lineWidth: 2, lineCap: .round, lineJoin: .round))
struct HomeShape: Shape {
    func path(in rect: CGRect) -> Path {
        ...
        path.move(to: at(0.1667, 0.4583))
        path.addLine(to: at(0.5, 0.1667))

Every point is a share of the icon's box, so the shape is sharp at any size. What was filled gives its outline to fill, and what was only stroked gives the line to stroke. Give it a frame of 24 × 24 and a line of 2 to match the design, and widen the line in proportion where you draw it larger.

Before you hand over#

  1. check_icon says clean.
  2. The previews at 16, 24 and 48 are crisp at the sizes you ship.
  3. Every icon of the set has the same weight, caps and joins.
  4. The frame is named for the file it becomes: home, bell, arrow-left.