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

85 lines
1.9 KiB
Go

package files
import (
"fmt"
"log/slog"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/input"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
type TrashOptions struct {
Disabled bool
}
type TrashResult struct {
Element ui.Element
Emptied bool
}
var (
binEmpty = pixel.MustSprite(`
................
......eeee......
..eeeeelleeeee..
..elllllllllle..
..eeeeeeeeeeee..
...essssssssse..
...eslslslslse..
...eslslslslse..
...eslslslslse..
...eslslslslse..
...eslslslslse..
...eslslslslse..
...eslslslslse..
...essssssssse..
....eeeeeeeee...
................`)
// Crumpled paper peeks out from under the lid.
binFull = pixel.MustSprite(`
......ee........
.....elle.ee....
..eeeeleeeelee..
..elllllllllle..
..eeeeeeeeeeee..
...essssssssse..
...eslslslslse..
...eslslslslse..
...eslslslslse..
...eslslslslse..
...eslslslslse..
...eslslslslse..
...eslslslslse..
...essssssssse..
....eeeeeeeee...
................`)
)
// Trash is a bin with its count; EMPTY clears it.
func Trash(c *ui.Context, text string, count int, o TrashOptions) TrashResult {
k := pixel.K(c)
if count < 0 {
panic(fmt.Sprintf("files: Trash count %d", count))
}
art, say := binEmpty, k.Msg("empty")
if count > 0 {
art, say = binFull, fmt.Sprintf(k.Msg("in_bin"), count)
}
var res TrashResult
res.Element = ui.Row(c).Gap(k.D(6)).AlignItems(ui.Center).Role(ui.RoleGroup).Label(text).Children(func() {
ui.Box(c).Size(k.D(32), k.D(32)).Draw(func(p *ui.Painter, r ui.Rect) {
k.Canvas(p, r).Sprite(0, 0, art, 0, pixel.Ink, 2)
})
ui.Column(c).Gap(k.D(3)).Children(func() {
pixel.Text(c, say, pixel.TextOptions{})
res.Emptied = input.Button(c, k.Msg("empty_trash"), input.ButtonOptions{Size: input.Small, Variant: input.Danger, Disabled: o.Disabled || count == 0}).Clicked
})
})
if res.Emptied {
slog.Debug("8bit: trash emptied", "label", text, "count", count)
}
return res
}