Cut the comments back to the genuinely subtle ones

This commit is contained in:
flamingcow
2026-08-01 16:14:12 -07:00
parent 726c4c2445
commit 5eea6856fb
6 changed files with 63 additions and 127 deletions
+23 -56
View File
@@ -19,21 +19,15 @@ var (
uiRed = rgb{0xf0, 0x6b, 0x6b}
)
// Every gap is a multiple of one step, so the spacing carries meaning: things
// a step apart belong together, things eight steps apart do not. Picking each
// number for itself is what produced a panel where a label could have gone with
// either the figure above it or the one below.
//
// These are distances actually seen, since layout measures a line of text from
// the top of a digit to the baseline rather than across a cell with accent and
// descender slack in it. Values that looked right when that slack was padding
// them out are too small once it is gone.
// Distances between ink, since layout measures a line from the top of a digit
// to the baseline rather than across a cell with accent and descender slack in
// it. Values carried over from spacing cells will look too small here.
const (
step = 4
spaceTight = step * 2 // neighbouring chips
spaceGroup = step * 4 // a figure and its label, chip padding, block to block
spaceRow = step * 8 // one labelled pair and the next
spaceTight = step * 2
spaceGroup = step * 4
spaceRow = step * 8
)
const (
@@ -47,13 +41,9 @@ const (
btnH = 80
holdDuration = time.Second
// Shared by the chips and the button, which are the same object drawn at
// different sizes.
chipRadius = spaceTight
chipBorder = 2
// One grid for the panel: the figures and the chips beneath them stand in
// the same columns because they are placed by the same arithmetic.
gridCols = 2
chipPadY = spaceGroup
chipGap = spaceTight
@@ -111,21 +101,13 @@ func newDisplay() (*display, error) {
return nil, fmt.Errorf("grid faces disagree on cell width: %d vs %d",
d.grid.cellW, d.gridB.cellW)
}
// Guessed heights collide on a screen this small, so the layout follows what
// the loaded faces actually measure.
now := []int{d.statsH(d.big, 2), d.chipsH()}
since := []int{d.statsH(d.gridB, 4), d.countsH(), btnH}
// One gap for the whole screen rather than one per panel: whatever is left
// after the blocks is divided between every gap in both of them, so the
// space above the first figure, between each block, and below the last is
// the same distance everywhere. Each panel is then sized to exactly the
// blocks it holds plus its share, which is also what puts the button in the
// flow instead of pinned to the bottom with the remainder above it.
// Vertically the frame is the border and nothing else: the gap is the only
// whitespace there is. Insetting by uiPad as well would add it to the gaps
// at the top and bottom of a panel but not to the ones between blocks,
// which is not equal spacing however evenly the remainder is divided.
// One gap for both panels, and vertically the frame is the border alone.
// Insetting by uiPad as well would add it to the gaps at a panel's ends but
// not to the ones between blocks, which is not equal spacing however evenly
// the remainder is divided.
gaps := len(now) + len(since) + 2
spare := fb.h - 2*uiMargin - blockGap - 4*uiBorder - sum(now) - sum(since)
if spare < 0 {
@@ -168,9 +150,8 @@ func stack(y int, hs []int, gap int) []int {
return ys
}
// Tracks a press and hold on the reset button, returning true once it has been
// held long enough. Lifting or sliding off cancels, and the press has to be
// released before it can arm again.
// Lifting or sliding off cancels, and the press has to be released before it
// can arm again.
func (d *display) holdReset(x, y int, down bool, now time.Time) bool {
if !down {
d.holdStart, d.holdFrac, d.fired = time.Time{}, 0, false
@@ -191,17 +172,14 @@ func (d *display) holdReset(x, y int, down bool, now time.Time) bool {
return true
}
// Built like the error chips, since it sits among them: a coloured outline
// around a dark well. Cyan rather than the status colours because it is
// something to press, not something being reported.
// Cyan rather than the status colours because it is something to press, not
// something being reported.
func (d *display) drawResetButton() {
r := d.resetBtn
d.fb.roundRect(r.x, r.y, r.w, r.h, chipRadius, uiCyan)
d.fb.roundRect(r.x+chipBorder, r.y+chipBorder, r.w-2*chipBorder, r.h-2*chipBorder,
chipRadius-chipBorder, uiBg)
// The hold fills the well rather than the whole button, so the outline stays
// put and it reads as the button filling up.
split := r.x + chipBorder
if d.holdFrac > 0 {
w := int(float64(r.w-2*chipBorder) * math.Min(d.holdFrac, 1))
@@ -229,8 +207,8 @@ func (d *display) close() {
d.fb.close()
}
// y is the top of the line as read, so text and a bordered box placed the same
// distance apart are the same distance apart to look at.
// y is the top of the line as read, not the top of the cell, so text and a
// bordered box placed the same distance apart look it.
func (d *display) centerIn(f *textFace, x, w, y int, s string, col rgb) int {
f.draw(d.fb, x+(w-len([]rune(s))*f.cellW)/2, y-f.capTop, s, col)
return y + f.lineH + pairGap
@@ -252,9 +230,7 @@ func (d *display) statsH(vf *textFace, n int) int {
return gridRows(n)*(d.statPairH(vf)+statRowGap) - statRowGap
}
// Where cell i of n falls in the panel's grid. A last row that does not fill
// the grid is centred, so the odd one out balances the rows above rather than
// hanging off the left of them.
// A last row that does not fill the grid is centred.
func gridCell(i, n, x, w int) (cx, cw int) {
cw = (w - (gridCols-1)*chipGap) / gridCols
inRow := min(n-(i/gridCols)*gridCols, gridCols)
@@ -262,10 +238,8 @@ func gridCell(i, n, x, w int) (cx, cw int) {
return cx, cw
}
// A figure with its label directly underneath, two to a row. The gap between
// rows is wider than the one inside a pair, so which label belongs to which
// figure is a matter of spacing rather than of guessing. An empty value takes
// its space without drawing, so nothing below moves when it arrives.
// An empty value takes its space without drawing, so nothing below it moves
// when it arrives.
func (d *display) stats(vf *textFace, x, w, y int, cells []statCell) int {
for i, c := range cells {
if c.value == "" {
@@ -291,7 +265,6 @@ var errRows = []struct {
func (d *display) chipH() int { return d.grid.lineH + 2*chipPadY }
// Taller by a line, since these carry the count under the kind.
func (d *display) countChipH() int { return d.chipH() + d.gridB.lineH + pairGap }
func (d *display) chipsH() int {
@@ -302,24 +275,20 @@ func (d *display) countsH() int {
return gridRows(len(errRows))*(d.countChipH()+chipGap) - chipGap
}
// Shared by both panels so they are demonstrably the same object, one carrying
// a count and one not.
// Outlined by drawing the border colour and sinking a smaller well of
// background into it, so both curves get the same antialiasing.
func (d *display) chipAt(i, x, w, y, h int, c rgb) (int, int, int) {
cx, cw := gridCell(i, len(errRows), x, w)
cy := y + (i/gridCols)*(h+chipGap)
// Outlined by drawing the border colour and then sinking a smaller well of
// background into it, so both curves get the same antialiasing.
d.fb.roundRect(cx, cy, cw, h, chipRadius, c)
d.fb.roundRect(cx+chipBorder, cy+chipBorder,
cw-2*chipBorder, h-2*chipBorder, chipRadius-chipBorder, uiBg)
return cx, cw, cy
}
// The same kinds as errBlock, but answering whether rather than how many, and
// carrying their own labels so nothing has to be matched up across a row. Over
// a window this short a count is a number nobody can read before it changes;
// the only thing worth knowing at a glance is which kinds are happening now.
// Whether rather than how many: over a window this short a count changes faster
// than it can be read.
func (d *display) errChips(x, w, y int, e errs) int {
for i, r := range errRows {
c := errColor(r.get(e))
@@ -340,8 +309,6 @@ func (d *display) errCounts(x, w, y int, e errs) int {
return y + d.countsH()
}
// Draws the frame and hands back the writable width inside it. Where the blocks
// sit within it was settled once at startup, since it never changes.
func (d *display) panel(p rect, e errs) (int, int) {
fill, edge := uiOKFill, uiOKEdge
if e.total() > 0 {