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>
70 lines
1.9 KiB
Go
70 lines
1.9 KiB
Go
package shop
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/datetime"
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/icon"
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
|
)
|
|
|
|
// Bid is an offer by a bidder at a time.
|
|
type Bid struct {
|
|
Bidder string
|
|
Amount int
|
|
At time.Time
|
|
}
|
|
|
|
type BidTickerOptions struct {
|
|
Currency Currency
|
|
// Width is in dots; zero means 240.
|
|
Width int
|
|
}
|
|
|
|
// BidTicker lists bids, newest first, crowning the highest.
|
|
func BidTicker(c *ui.Context, text string, bids []Bid, o BidTickerOptions) ui.Element {
|
|
k := pixel.K(c)
|
|
top := -1
|
|
for i, b := range bids {
|
|
amount("BidTicker", b.Amount)
|
|
if b.Bidder == "" || b.At.IsZero() {
|
|
panic(fmt.Sprintf("shop: BidTicker bid %d has no bidder or time", i))
|
|
}
|
|
// The first to reach the highest keeps the crown.
|
|
if top < 0 || b.Amount > bids[top].Amount {
|
|
top = i
|
|
}
|
|
}
|
|
list := ui.Column(c).Width(k.D(pixel.Or("BidTicker Width", o.Width, 240))).Gap(k.D(2)).Role(ui.RoleList).Label(text)
|
|
if top >= 0 {
|
|
_, word := coin(k, o.Currency)
|
|
list.Description(fmt.Sprintf(k.Msg("highest"), bids[top].Bidder, bids[top].Amount, word))
|
|
}
|
|
return list.Children(func() {
|
|
for i := len(bids) - 1; i >= 0; i-- {
|
|
b, crowned := bids[i], i == top
|
|
// New bids come in on top; rows keep keys.
|
|
ui.Row(c).Key(i).FillWidth().Gap(k.D(4)).AlignItems(ui.Center).Role(ui.RoleListItem).Children(func() {
|
|
ui.Box(c).Size(k.D(12), k.D(12)).Draw(func(p *ui.Painter, r ui.Rect) {
|
|
if crowned {
|
|
k.Canvas(p, r).Sprite(0, 0, icon.Crown, 0, pixel.Ink, 1)
|
|
}
|
|
})
|
|
ink := pixel.Ink
|
|
if crowned {
|
|
ink = pixel.Warn
|
|
}
|
|
pixel.Text(c, b.Bidder, pixel.TextOptions{Wrap: true, MaxLines: 1, Slot: ink}).Grow(1)
|
|
money(c, k, o.Currency, b.Amount, ink)
|
|
datetime.RelativeTime(c, b.At, datetime.RelativeTimeOptions{})
|
|
})
|
|
}
|
|
if len(bids) == 0 {
|
|
pixel.Text(c, k.Msg("empty"), pixel.TextOptions{Slot: pixel.Faint})
|
|
}
|
|
})
|
|
}
|