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>
49 lines
1.5 KiB
Go
49 lines
1.5 KiB
Go
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
|
|
}
|