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>
134 lines
5.8 KiB
Go
134 lines
5.8 KiB
Go
package shop
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
|
)
|
|
|
|
type SaleBadgeOptions struct{}
|
|
|
|
var (
|
|
// A sixteen-point starburst and its rim, to flash.
|
|
burst = pixel.MustSprite(`
|
|
................................................
|
|
.......................ee.......................
|
|
.......................ee.......................
|
|
...............ee.....e##e.....ee...............
|
|
...............e#e...e####e...e#e...............
|
|
..............e###ee.e####e.ee###e..............
|
|
..............e#####e######e#####e..............
|
|
.......e......e##################e......e.......
|
|
........eeeee.e##################e.eeeee........
|
|
........e####e####################e####e........
|
|
........e##############################e........
|
|
........e##############################e........
|
|
........e##############################e........
|
|
.........e############################e.........
|
|
.....eeee##############################eeee.....
|
|
...ee######################################ee...
|
|
...e########################################e...
|
|
....e######################################e....
|
|
.....e####################################e.....
|
|
.....e####################################e.....
|
|
......e##################################e......
|
|
....ee####################################ee....
|
|
...e########################################e...
|
|
.ee##########################################ee.
|
|
.ee##########################################ee.
|
|
...e########################################e...
|
|
....ee####################################ee....
|
|
......e##################################e......
|
|
.....e####################################e.....
|
|
.....e####################################e.....
|
|
....e######################################e....
|
|
...e########################################e...
|
|
...ee######################################ee...
|
|
.....eeee##############################eeee.....
|
|
.........e############################e.........
|
|
........e##############################e........
|
|
........e##############################e........
|
|
........e##############################e........
|
|
........e####e####################e####e........
|
|
........eeeee.e##################e.eeeee........
|
|
.......e......e##################e......e.......
|
|
..............e#####e######e#####e..............
|
|
..............e###ee.e####e.ee###e..............
|
|
...............e#e...e####e...e#e...............
|
|
...............ee.....e##e.....ee...............
|
|
.......................ee.......................
|
|
.......................ee.......................
|
|
................................................`)
|
|
rim = pixel.MustSprite(`
|
|
................................................
|
|
.......................##.......................
|
|
.......................##.......................
|
|
...............##.....#..#.....##...............
|
|
...............#.#...#....#...#.#...............
|
|
..............#...##.#....#.##...#..............
|
|
..............#.....#......#.....#..............
|
|
.......#......#..................#......#.......
|
|
........#####.#..................#.#####........
|
|
........#....#....................#....#........
|
|
........#..............................#........
|
|
........#..............................#........
|
|
........#..............................#........
|
|
.........#............................#.........
|
|
.....####..............................####.....
|
|
...##......................................##...
|
|
...#........................................#...
|
|
....#......................................#....
|
|
.....#....................................#.....
|
|
.....#....................................#.....
|
|
......#..................................#......
|
|
....##....................................##....
|
|
...#........................................#...
|
|
.##..........................................##.
|
|
.##..........................................##.
|
|
...#........................................#...
|
|
....##....................................##....
|
|
......#..................................#......
|
|
.....#....................................#.....
|
|
.....#....................................#.....
|
|
....#......................................#....
|
|
...#........................................#...
|
|
...##......................................##...
|
|
.....####..............................####.....
|
|
.........#............................#.........
|
|
........#..............................#........
|
|
........#..............................#........
|
|
........#..............................#........
|
|
........#....#....................#....#........
|
|
........#####.#..................#.#####........
|
|
.......#......#..................#......#.......
|
|
..............#.....#......#.....#..............
|
|
..............#...##.#....#.##...#..............
|
|
...............#.#...#....#...#.#...............
|
|
...............##.....#..#.....##...............
|
|
.......................##.......................
|
|
.......................##.......................
|
|
................................................`)
|
|
)
|
|
|
|
// SaleBadge is a SALE -n% starburst whose rim flashes.
|
|
func SaleBadge(c *ui.Context, percent int, o SaleBadgeOptions) ui.Element {
|
|
k := pixel.K(c)
|
|
if percent < 1 || percent > 99 {
|
|
panic(fmt.Sprintf("shop: SaleBadge of %d%%", percent))
|
|
}
|
|
sale, off := k.Msg("sale"), "-"+strconv.Itoa(percent)+"%"
|
|
return ui.Box(c).Size(k.D(burst.W), k.D(burst.H)).Role(ui.RoleImage).Label(sale + " " + off).Draw(func(p *ui.Painter, r ui.Rect) {
|
|
g := k.Canvas(p, r)
|
|
g.Sprite(0, 0, burst, 0, pixel.Bad, 1)
|
|
// Each second the rim turns gold, unless motion is reduced.
|
|
if g.Step(4)/4%2 == 1 {
|
|
g.Sprite(0, 0, rim, 0, pixel.Warn, 1)
|
|
}
|
|
g.Text((burst.W-pixel.Measure(sale))/2, 8, sale, pixel.Lit, 1)
|
|
g.Text((burst.W-pixel.Measure(off))/2, 24, off, pixel.Lit, 1)
|
|
})
|
|
}
|