Files
8bitMyGoUI/feedback/emptystate.go
T
ZacharyZhang-NY 1f3d38110e One component per file; GAME OVER offers CONTINUE
PRD G1 asks for one component per file. Eight files held two or
three; their eleven extra components move to files of their own,
helpers stay where both sides use them, and an archtest now fails
any file that holds two.

PRD 4.4 and the request say an error always offers CONTINUE.
ErrorState's button read RETRY; it now reads CONTINUE, under the
CONTINUE? countdown, on the crash screen and the lost page alike.
2026-10-12 16:50:17 -04:00

52 lines
1.4 KiB
Go

package feedback
import (
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/display"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/input"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/text"
)
var openChest = pixel.MustSprite(`
..eeeeeeeeeeee..
.esssssssssssse.
.elllllllllllle.
..eeeeeeeeeeee..
................
eeeeeeeeeeeeeeee
ewwwwwwwwwwwwwwe
ewwwwwwwwwwwwwwe
eeeeeeeyyeeeeeee
essssssyysssssse
esssssssssssssse
eeeeeeeeeeeeeeee
`)
type EmptyStateOptions struct {
// Action labels a button; Acted reports it.
Action string
Disabled bool
}
type EmptyStateResult struct {
Element *ui.Element
Acted bool
}
// EmptyState shows NO ITEMS over an empty chest.
func EmptyState(c *ui.Context, message string, o EmptyStateOptions) EmptyStateResult {
k := pixel.K(c)
res := EmptyStateResult{}
res.Element = ui.Column(c).Gap(k.D(6)).Padding(k.D(12)).AlignItems(ui.Center).Role(ui.RoleStatus).Label(k.Msg("empty")).Children(func() {
display.Sprite(c, openChest, display.SpriteOptions{Scale: 2})
text.ShadowText(c, k.Msg("empty"), text.ShadowTextOptions{Slot: pixel.Faint, Scale: 2})
pixel.Text(c, message, pixel.TextOptions{Slot: pixel.Faint})
if o.Action != "" {
res.Acted = input.Button(c, o.Action, input.ButtonOptions{Variant: input.Primary, Disabled: o.Disabled}).Clicked
}
})
return res
}