Elements are now pass-scoped value handles: tests that read bounds after a frame bind a ui.Handle. pixel tells frames apart by the build pass's root, since the Tester clock no longer moves on its own. Fix the regressions the upgrade brought: - Clipboard reads in input handlers go through c.Services(). - MyGo notes an overlay's opener after building it, so AutoFocus inside lost it; pixel.AutoFocus focuses through a Handle, and archtest bans the raw call. Dialogs hand the focus back again. - Elements around a press stay hovered: Tooltip tells a press-given focus by focus arriving under the pointer. - The web host moves the Tester clock with real time, at most 500 ms a call, and gives components the real clock. The gallery's source index also accepts CRLF checkouts. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
package display
|
|
|
|
import (
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
|
)
|
|
|
|
type StampOptions struct {
|
|
// Slot is the ink; zero means Bad.
|
|
Slot pixel.Slot
|
|
Seed int
|
|
}
|
|
|
|
// Stamp is a rubber-stamp mark whose border wears unevenly.
|
|
func Stamp(c *ui.Context, s string, o StampOptions) ui.Element {
|
|
k := pixel.K(c)
|
|
ink := slotOr(o.Slot, pixel.Bad)
|
|
w, h := pixel.Measure(s)+12, pixel.LineHeight+8
|
|
return art(c, k, s, w, h, func(g pixel.Canvas) {
|
|
ring := func(in int) {
|
|
for i := in; i < w-in; i++ {
|
|
worn(g, o.Seed, i, in, ink)
|
|
worn(g, o.Seed, i, h-1-in, ink)
|
|
}
|
|
for j := in + 1; j < h-1-in; j++ {
|
|
worn(g, o.Seed, in, j, ink)
|
|
worn(g, o.Seed, w-1-in, j, ink)
|
|
}
|
|
}
|
|
ring(0)
|
|
ring(2)
|
|
g.Text(6, 4, s, ink, 1)
|
|
})
|
|
}
|
|
|
|
// worn inks a border dot unless seeded wear skips it.
|
|
func worn(g pixel.Canvas, seed, x, y int, ink pixel.Slot) {
|
|
if hash(seed, x, y)%7 != 0 {
|
|
g.Dot(x, y, ink)
|
|
}
|
|
}
|
|
|
|
func hash(seed, x, y int) uint32 {
|
|
n := uint32(seed*73856093 ^ x*19349663 ^ y*83492791)
|
|
n ^= n >> 13
|
|
n *= 0x5bd1e995
|
|
return n ^ n>>15
|
|
}
|