Files
ZacharyZhang-NYandClaude Opus 5.5 03e1f91706 Upgrade MyGo to v0.5.5
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>
2026-10-17 01:31:08 -04:00

51 lines
1.3 KiB
Go

// Package shop holds prices, carts, rewards and trading components.
package shop
import (
"fmt"
"strconv"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/icon"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
// Currency is what a price is counted in.
type Currency int
const (
Gold Currency = iota
Gems
)
// coin is a currency's icon and word; unknown ones panic.
func coin(k pixel.Kit, cur Currency) (*pixel.Sprite, string) {
switch cur {
case Gold:
return icon.Coin, k.Msg("coins")
case Gems:
return icon.Gem, k.Msg("gems")
}
panic(fmt.Sprintf("shop: unknown currency %d", cur))
}
// amount checks n is not negative and prints it.
func amount(name string, n int) string {
if n < 0 {
panic(fmt.Sprintf("shop: %s amount %d is negative", name, n))
}
return strconv.Itoa(n)
}
// money draws a currency icon and amount, named for readers.
func money(c *ui.Context, k pixel.Kit, cur Currency, n int, slot pixel.Slot) ui.Element {
sp, word := coin(k, cur)
s := amount("money", n)
return ui.Box(c).Size(k.D(14+pixel.Measure(s)), k.D(pixel.LineHeight)).Role(ui.RoleText).Label(s + " " + word).Draw(func(p *ui.Painter, r ui.Rect) {
g := k.Canvas(p, r)
g.Sprite(0, 2, sp, 0, pixel.Warn, 1)
g.Text(14, 0, s, slot, 1)
})
}