A cross-cutting pass, each fix with a test that failed first. Veils: MyGo still hands a key to a base that turned off this frame, so every element key now goes through pixel.Shortcut, which an archtest enforces. Input handlers record and the build applies them only while enabled; the editor turns away a veil-frame letter or copy; value bases get a copy and keep only enabled turns. Popups give a held focus back to their opener when the veil lifts. Motion: S5 is enforced at the clock. Every Tick, Since, Step, Toward and Shot runs at 4-15 fps; blinks keep 1 Hz on 4 fps steps, fast animations step at 15, and drawn time is quantized to frames. Clocks stepping back: Since holds at zero without overflow, and k.Elapsed moves a stored start to now, so nothing goes negative, runs backward or indexes out of range. Also: logs count typed text instead of holding it, gallery names use glyphs the font has, removable rows are keyed, components take their own Options (archtest), and sweeps over all 508 demos check veiled keys, clicks, wheels, the clock stepping back and names.
81 lines
2.4 KiB
Go
81 lines
2.4 KiB
Go
package files
|
|
|
|
import (
|
|
"fmt"
|
|
"log/slog"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/input"
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
|
)
|
|
|
|
// Access is what a link lets its holder do.
|
|
type Access int
|
|
|
|
const (
|
|
CanView Access = iota
|
|
CanComment
|
|
CanEdit
|
|
)
|
|
|
|
type SharePanelOptions struct {
|
|
// Width is in dots; zero means 220.
|
|
Width int
|
|
Disabled bool
|
|
}
|
|
|
|
type SharePanelResult struct {
|
|
Element *ui.Element
|
|
Copied, Changed bool
|
|
}
|
|
|
|
type shareKey struct{}
|
|
|
|
// SharePanel shows a link to copy and its access.
|
|
func SharePanel(c *ui.Context, text, link string, access *Access, o SharePanelOptions) SharePanelResult {
|
|
k := pixel.K(c)
|
|
if link == "" || *access < CanView || *access > CanEdit {
|
|
panic(fmt.Sprintf("files: SharePanel link of %d bytes, access %d", len(link), *access))
|
|
}
|
|
var res SharePanelResult
|
|
res.Element = ui.Column(c).Width(k.D(pixel.Or("SharePanel Width", o.Width, 220))).Gap(k.D(4)).Role(ui.RoleGroup).Label(text).Children(func() {
|
|
ui.Row(c).FillWidth().Gap(k.D(4)).AlignItems(ui.Center).Children(func() {
|
|
// The link is cut to fit; readers hear it whole.
|
|
field := ui.Box(c).Grow(1).Height(k.D(pixel.LineHeight + 4)).Role(ui.RoleText).Label(k.Msg("link")).Description(link)
|
|
lw, fits := pixel.WrapWidth(c, field)
|
|
shown := pixel.Wrap(link, max(0, lw-6), 1)[0]
|
|
field.Draw(func(p *ui.Painter, r ui.Rect) {
|
|
fits(r)
|
|
g := k.Canvas(p, r)
|
|
g.Frame(0, 0, g.W, g.H, pixel.Sunken, pixel.Well)
|
|
g.Clip(2, 0, g.W-4, g.H, func() { g.Text(3, 2, shown, pixel.Ink, 1) })
|
|
})
|
|
e := ui.Box(c)
|
|
at := ui.Local(e, shareKey{}, func() time.Time { return time.Time{} })
|
|
// The button says COPIED! for two seconds.
|
|
label := k.Msg("copy")
|
|
if k.Since(c, *at, 4, 8) < 8 {
|
|
label = k.Msg("copied")
|
|
}
|
|
e.Children(func() {
|
|
if input.Button(c, label, input.ButtonOptions{Size: input.Small, Disabled: o.Disabled}).Clicked {
|
|
c.WriteClipboard(link)
|
|
*at, res.Copied = k.Now(), true
|
|
}
|
|
})
|
|
})
|
|
i := int(*access)
|
|
if input.Segmented(c, k.Msg("access"), strings.Fields(k.Msg("access_levels")), &i, input.SegmentedOptions{Disabled: o.Disabled}).Changed {
|
|
*access, res.Changed = Access(i), true
|
|
}
|
|
})
|
|
// A share link is a key; it never reaches logs.
|
|
if res.Copied || res.Changed {
|
|
slog.Debug("8bit: share panel", "label", text, "copied", res.Copied, "access", *access)
|
|
}
|
|
return res
|
|
}
|