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

64 lines
1.7 KiB
Go

package overlay
import (
"log/slog"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/display"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
type DrawerOptions struct {
// Side is the edge it slides from.
Side display.Side
// Size is its depth in dots; zero means 160.
Size int
// Disabled makes the content inert.
Disabled bool
}
type DrawerResult struct {
Element ui.Element
// Closed is Escape or a click outside.
Closed bool
}
// Drawer slides a panel in from an edge in steps.
func Drawer(c *ui.Context, text string, open *bool, o DrawerOptions, content func()) DrawerResult {
k := pixel.K(c)
if o.Side > display.Right {
panic("overlay: unknown Drawer Side")
}
size := pixel.Or("Drawer Size", o.Size, 160)
home := ui.Box(c)
off := k.D(arriving(c, home, *open) * size / 4)
was := *open
var res DrawerResult
res.Element = ui.DialogBase(c, open, func(back, panel ui.Element) {
dim(k, back, pixel.Back, 8)
panel.Absolute().Label(text).Padding(k.D(8)).Focusable().FocusRing(false)
switch o.Side {
case display.Left:
panel.Top(0).Bottom(0).Left(-off).Width(k.D(size))
case display.Right:
panel.Top(0).Bottom(0).Right(-off).Width(k.D(size))
case display.Top:
panel.Left(0).Right(0).Top(-off).Height(k.D(size))
case display.Bottom:
panel.Left(0).Right(0).Bottom(-off).Height(k.D(size))
}
panel.Draw(func(p *ui.Painter, r ui.Rect) {
g := k.Canvas(p, r)
g.Frame(0, 0, g.W, g.H, pixel.Window, pixel.Face)
}).Children(func() {
pixel.Harbor(c, panel, func() { body(c, o.Disabled, content) })
})
})
res.Closed = was && !*open
if res.Closed {
slog.Debug("8bit: drawer closed", "label", text)
}
return res
}