v0.6.0 mouse: every wheel direction and side button named; tui: a scrollbar the pointer drives

* mouse: the wheel's four directions and the side buttons

parseSGRMouse read a report's low two bits alone, so a wheel tilted left or
right (66, 67) reported as WheelDown, and a mouse's back and forward buttons
(128, 129) as a left or middle press. It now decodes by bank: bits 0-1 number
a button within the main three and none, the wheel's four directions (bit 6),
or buttons 8 to 11 (bit 7). WheelLeft and WheelRight join MouseButton after
Forward, so every existing value keeps its number; Back and Forward are
reported for buttons 8 and 9; buttons 10 and 11, and a report with both bank
bits set, are dropped as KeyNone. A wheel step is a press with no release in
every direction.

* tui: ScrollThumb and ScrollDrag

ScrollThumb is the thumb ScrollBarStyled draws, its first row and height,
exported so an application hit-tests the bar it drew. ScrollDrag drives a bar
by the pointer, rows counted from the track's top: a press on the thumb takes
hold where it lands, a press on the track moves the thumb's middle there and
takes hold, and each drag keeps the held row under the pointer, clamped at the
track's ends, at the nearest offset when there are fewer offsets than rows.
Each call returns the offset to show.

A table of SGR reports covers each bank and drops the buttons past 9; a
property test over every track of 3 to 10 rows and content up to 30 checks
each press and drag against the thumb ScrollThumb draws.
This commit is contained in:
Lixen authored and GitHub committed 2026-10-26 20:42:04 -04:00
1 parent d4cc9f2407
commit bc22a9bf00
7 files changed
+215 -60

No files matched your search

+25 -2
View File
@@ -187,6 +187,28 @@ r.List(items, state.Selection, state.Offset, tui.ListOpts{CursorBg: color.DarkSl
r.ScrollBar(r.W-1, state.Offset, state.Visible, state.Total, color.IronGray)
```
`ScrollThumb` is the thumb a bar draws. `ScrollDrag` drives one by the
pointer, rows counted from the track's top: a press on the thumb takes hold
of it, a press on the track moves the thumb's middle there and takes hold, and
a drag keeps the held row under the pointer, each returning the offset to show.
```go
var drag tui.ScrollDrag // kept across events
bar := r.Sub(r.W-1, 0, 1, r.H) // the column ScrollBar draws, in screen cells at bar.X, bar.Y
// per left button event:
switch ev.MouseAction {
case terminal.MouseActionPress:
if ev.MouseX == bar.X {
state.ScrollTo(drag.Press(ev.MouseY-bar.Y, bar.H, state.Offset, state.Visible, state.Total))
}
case terminal.MouseActionDrag:
state.ScrollTo(drag.Drag(ev.MouseY-bar.Y, bar.H, state.Offset, state.Visible, state.Total))
case terminal.MouseActionRelease:
drag.Release()
}
```
### Modal dialog
```go
@@ -265,5 +287,6 @@ Pure logic, no rendering — usable independently:
(widget default or row background) — check specific widget docs. A zero
background with no Bg color bits is transparent: the cell keeps the
background beneath it, bits and all.
- Mouse hit testing: `TabBar` returns `[]TabBounds`; other widgets require
application-side geometry from the regions used.
- Mouse hit testing: `TabBar` returns `[]TabBounds`, and `ScrollDrag` maps a
scrollbar's rows to offsets; other widgets require application-side
geometry from the regions used.