Menu

A short list of words over the page: a sort order, the actions on a file, a few choices to tick. It opens from a button or a right-click and closes when something is picked.

Part of a Files window with the sort button Newest first and, open under it, a menu with the group Sort by (Newest first ticked, Oldest first under the pointer, Name), a rule and the group Show with Hidden files.

Use a menu for choices that change what you see, and for a thing's lesser actions when there is no room for a docked panel. Three parts make it:

Anatomy

A menu at 1.4 times its size with six numbered callouts beside its pieces: the group name Sort by, the tick on Newest first, the line under the pointer, the detail A to Z, the rule and the risk line Delete.
A menu at 1.4 times its size.
  1. Group nameIn the meta ink for the overlay, medium weight, 13 pixels. It is not pressable and the keyboard skips it.
  2. TickA check in the accent, 16 pixels, on the choice in force.
  3. LineWords, 34 high, in the secondary ink. The line under the pointer or the keyboard has a wash of 10 % and its words in the main ink.
  4. DetailA word or number at the end of the line, 13 pixels in the meta ink for the overlay: a key, a count.
  5. RuleA hairline between groups, 9 high with the line 1 pixel at 10 % of the main ink.
  6. RiskThe warning symbol and the risk ink for the overlay. It goes last.

The menu is solid, in the overlay colour, with a faint 1-pixel edge. Text under it never shows through. The overlay's inks (group names, details, the risk line) are solved to an APCA contrast of 75 on a lit line, so they read on every line.

States

A line has two states, and the keyboard adds the ring. The menu itself fades in and grows from 0.96 over 150 ms (fadeFast), and fades out over 100 ms (dismiss).

The same three lines in three menus: at rest, with one under the pointer or the keyboard, and with the first ticked.
A menu at rest, with a line lit, and with a choice in force.
  1. RestNo wash.
  2. Under the pointer or the keyboardA wash of 10 %, in and out over 80 ms, and the words in the main ink. The pointer and the keyboard share one line. After a key, that line also has the focus ring, so the keyboard's place does not depend on the wash.
  3. Choice in forceA tick before the words. It has no wash of its own.

Sizes

A menu at twice its size with its vertical spaces measured: 28 for the group name, 34 for a line and 9 for the rule, and its horizontal spaces: 14 from the edge to the tick and 16 for the tick.
A menu at twice its size.
PartValue
Line34 high (height.menuRow)
Group name28 high, its words at 12 from the line's edge
Rule9 high
Edge4 all round
Tick or symbol16 pixels, 10 from the line's edge
Words15 pixels, 34 from the line's edge (13 for a group name)
Detail13 pixels, 12 from the line's right edge
WidthThe widest label with 12 each side and the tick's room (28), and the widest detail with 24; at least 180, and 8 for the edge
Corner12 (radius.slab); a line's wash #8 (radius.row)

A MenuButton has the search field's padding and shape: 36 high, 12 before the words, 4 between the words and the 18-pixel chevron, 8 after.

Keys and pointer

Do thisTo
Enter, Space or ↓ on a MenuButtonOpen the menu with the cursor on its first item
↑ ↓Move to the line above or below, skipping rules and group names
Home EndGo to the first or the last line
A letterGo to the next line whose label starts with it
Enter or SpacePick the lit line
EscClose, and give the focus back to what opened the menu
ClickPick a line
Click outsideClose

A line with keepOpen leaves the menu open when it is picked, so several kinds can be ticked in a filter. If the first item is a group name, no line is lit until ↓.

Accessibility

Writing

Keep a line to a word or two: "Newest first", "Rename", "Move to the trash". Name a group with a noun: "Sort by", "Show". Put a key as the detail, as the system writes it: "F2", "Enter". Do not add "..." to a line unless it opens another step that asks you something.

Do and don't

A menu with Open, Rename, a rule and the risk Move to the trash last.
DoPut the risk last, after a rule, with its symbol.
A menu with Move to the trash, a risk, between Open and Rename.
Don'tPut the risk among the other lines. It sits where the pointer will pass.

Code

import Tacit.Kit

MenuButton {
    text: "Newest first"
    items: [
        { heading: true, label: "Sort by" },
        { label: "Newest first", checked: true },
        { label: "Oldest first" },
        { rule: true },
        { heading: true, label: "Show" },
        { label: "Hidden files", keepOpen: true }
    ]
    onPicked: i => files.choose(i)
}
Item keyWhat it does
labelThe words
checkedThe tick: the choice in force
riskThe warning symbol and the risk ink. Put it last
detailA quiet word or number at the end of the line
headingA group's name; not pressable
ruleA separating line; not pressable
keepOpenLeaves the menu open when the line is picked
PartWhat it does
MenuButtontext, items; picked(index), the index into items, counting group names and rules. With no items it sends activated() instead, to show more of the page
MenuA popup: items, openAt(item, x, y), picked(index), also an index into items
MenuSurfaceThe menu in place: items, cursor (the lit line, -1 for none), keyboard (the cursor is the keyboard's, so its line has the ring), picked(index)

Experimental, in Tacit.Kit 0.1.