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

52 lines
1.4 KiB
Go

package files
import (
"strconv"
"time"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/data"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
type FileDetailsOptions struct {
// Width is in dots; zero means 220.
Width int
}
// FileDetails shows a file's icon, name, kind, size and dates.
func FileDetails(c *ui.Context, f File, o FileDetailsOptions) ui.Element {
k := pixel.K(c)
check("FileDetails", f)
return ui.Column(c).Width(k.D(pixel.Or("FileDetails Width", o.Width, 220))).Gap(k.D(6)).Role(ui.RoleGroup).Label(f.Name).Children(func() {
ui.Row(c).FillWidth().Gap(k.D(6)).AlignItems(ui.Center).Children(func() {
FileIcon(c, f.Kind, FileIconOptions{Scale: 3})
pixel.Text(c, f.Name, pixel.TextOptions{Wrap: true, MaxLines: 2}).Grow(1)
})
data.DescriptionList(c, [][2]string{
{k.Msg("kind"), k.Msg(look(f.Kind).msg)},
{k.Msg("size"), size(f.Size) + " (" + grouped(f.Size) + " B)"},
{k.Msg("created"), when(f.Created)},
{k.Msg("modified"), when(f.Modified)},
}, data.DescriptionListOptions{TermWidth: 64})
})
}
// when is a date and time, or a dash.
func when(t time.Time) string {
if t.IsZero() {
return "-"
}
return t.Format("2006-01-02 15:04")
}
// grouped writes n with commas between thousands.
func grouped(n int64) string {
s := strconv.FormatInt(n, 10)
for i := len(s) - 3; i > 0; i -= 3 {
s = s[:i] + "," + s[i:]
}
return s
}