Files
8bitMyGoUI/data/bestiary.go
T
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

62 lines
1.7 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package data
import (
"fmt"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/display"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/layout"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/text"
)
// Monster is a bestiary entry; unseen ones keep their secrets.
type Monster struct {
Sprite *pixel.Sprite
Name string
Stats [][2]string
Notes string
Seen bool
}
type BestiaryOptions struct {
// Scale enlarges the sprite, 1–4; zero means 2.
Scale int
}
// Bestiary is a monster card; unseen ones are silhouettes.
func Bestiary(c *ui.Context, m Monster, o BestiaryOptions) ui.Element {
k := pixel.K(c)
sc := pixel.Or("Bestiary Scale", o.Scale, 2)
if m.Sprite == nil || sc > 4 {
panic(fmt.Sprintf("data: Bestiary %q needs a Sprite and Scale 1–4", m.Name))
}
hide := func(s string) string {
if m.Seen {
return s
}
return k.Msg("unknown")
}
return layout.Card(c, layout.CardOptions{Title: hide(m.Name)}, func() {
ui.Row(c).Gap(k.D(8)).Children(func() {
ui.Box(c).Size(k.D(m.Sprite.W*sc+8), k.D(m.Sprite.H*sc+8)).Shrink(0).Role(ui.RoleImage).Label(hide(m.Name)).Draw(func(p *ui.Painter, r ui.Rect) {
g := k.Canvas(p, r)
g.Frame(0, 0, g.W, g.H, pixel.Sunken, pixel.Well)
if m.Seen {
g.Sprite(4, 4, m.Sprite, 0, pixel.Ink, sc)
} else {
g.Silhouette(4, 4, m.Sprite, 0, pixel.Shade, sc)
}
})
ui.Column(c).Grow(1).Gap(k.D(2)).Children(func() {
for _, s := range m.Stats {
display.KeyValue(c, s[0], hide(s[1]), display.KeyValueOptions{})
}
})
})
ui.Box(c).Height(k.D(6))
text.Paragraph(c, hide(m.Notes), text.ParagraphOptions{})
})
}