Add navigation components 131-150; pixel Pad, Finish, Park, Since

This commit is contained in:
ZacharyZhang-NY committed 2026-10-11 21:27:09 -04:00
1 parent bd3877e1b1
commit f587d25a5a
63 files changed
+2776 -87

No files matched your search

+27 -13
View File
@@ -97,25 +97,29 @@ func Shell(c *ui.Context, base func() *ui.Element) (shell, b *ui.Element, st Sta
b.Disabled(true)
}
off := own || inert
// MyGo keeps focus and keys on a newly disabled element.
parked := ui.Local(b, parkKey{}, func() bool { return false })
switch {
case off && b.Focused():
c.Root().Focus()
*parked = true
case !off && *parked:
// Focus comes back unless something else took it.
if root := c.Root(); root.Focused() || !root.FocusWithin() {
b.Focus()
}
*parked = false
}
Park(c, b, off)
st = State{Hover: b.Hovered(), Press: b.Pressed() && !off, Focus: b.FocusVisible(), Disabled: own}
return shell, b, st
}
type parkKey struct{}
// Park moves focus off e while off, back once on.
func Park(c *ui.Context, e *ui.Element, off bool) {
parked := ui.Local(e, parkKey{}, func() bool { return false })
switch {
case off && e.Focused():
c.Root().Focus()
*parked = true
case !off && *parked:
// Focus comes back unless something else took it.
if root := c.Root(); root.Focused() || !root.FocusWithin() {
e.Focus()
}
*parked = false
}
}
// Hand is the pointing cursor of focus and menus.
var Hand = MustSprite(`
.eee......
@@ -126,6 +130,16 @@ var Hand = MustSprite(`
.eeee.....
`)
// Finish dithers out a disabled control and marks its focus.
func (g Canvas) Finish(st State) {
if st.Disabled {
g.Checker(0, 0, g.W, g.H, Face)
}
if st.Focus {
g.FocusMark(0, 0, g.W, g.H)
}
}
// FocusMark rings a box with dots and points a hand.
func (g Canvas) FocusMark(x, y, w, h int) {
rx, ry, rw, rh := x-2, y-2, w+4, h+4