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:
30 files changed
+2416
-2
No files matched your search
@@ -0,0 +1,48 @@
|
||||
package files
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"github.com/egoist/mygo/ui"
|
||||
|
||||
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/data"
|
||||
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/datetime"
|
||||
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
||||
)
|
||||
|
||||
type RecentFilesOptions struct {
|
||||
// Width and Height are dots; zeros mean 220, 120.
|
||||
Width, Height int
|
||||
Disabled bool
|
||||
}
|
||||
|
||||
type RecentFilesResult struct {
|
||||
Element *ui.Element
|
||||
// Opened is Enter or a double click on a file.
|
||||
Changed, Opened bool
|
||||
}
|
||||
|
||||
// RecentFiles lists files with how long since each changed.
|
||||
func RecentFiles(c *ui.Context, text string, files []File, selected *int, o RecentFilesOptions) RecentFilesResult {
|
||||
k := pixel.K(c)
|
||||
pick("RecentFiles", selected, len(files))
|
||||
for _, f := range files {
|
||||
check("RecentFiles", f)
|
||||
if f.Modified.IsZero() {
|
||||
panic(fmt.Sprintf("files: RecentFiles %q has no time", f.Name))
|
||||
}
|
||||
}
|
||||
var res RecentFilesResult
|
||||
res.Element = ui.Column(c).Width(k.D(pixel.Or("RecentFiles Width", o.Width, 220))).Children(func() {
|
||||
l := data.List(c, text, len(files), selected, data.ListOptions{Height: o.Height, Disabled: o.Disabled}, func(i int) string { return files[i].Name }, func(i int) {
|
||||
row(c, k, files[i], func() { datetime.RelativeTime(c, files[i].Modified, datetime.RelativeTimeOptions{}) })
|
||||
})
|
||||
l.Element.FillWidth()
|
||||
res.Changed, res.Opened = l.Changed, l.Submitted && *selected >= 0
|
||||
})
|
||||
if res.Opened {
|
||||
slog.Debug("8bit: recent files open", "label", text, "file", *selected)
|
||||
}
|
||||
return res
|
||||
}
|
||||
Reference in new issue
Block a user