Add files components 406-420; Tree opens to a known choice

Fifteen file components: FileExplorer, FileGrid, FileIcon, PathBar,
MemoryCard, DiskUsage, UploadQueue, Trash, RecentFiles, FilePreview,
ArchiveViewer, FileDetails, SharePanel, SyncStatus and QuotaMeter.

FileIcon draws six kinds as hand-placed 12x12 pages and a folder. The
browsers build on data.Tree, List, GridView and Table; ArchiveViewer
owns its sort and keeps the caller's index on its entry. UploadQueue
keys rows by name so focus stays on its row. SharePanel never logs the
link. SyncStatus turns its arrows on Busy steps, so syncing moves under
Reduce Motion.

data.Tree now opens the closed branches above a chosen path it knows,
so a caller's starting path survives the first frame.
This commit is contained in:
ZacharyZhang-NY committed 2026-10-12 09:27:26 -04:00
1 parent c745b082a9
commit 552b073e81
30 files changed
+2416 -2

No files matched your search

+51
View File
@@ -0,0 +1,51 @@
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
}