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>
71 lines
2.2 KiB
Go
71 lines
2.2 KiB
Go
package overlay
|
||
|
||
import (
|
||
"fmt"
|
||
"log/slog"
|
||
|
||
"github.com/egoist/mygo/ui"
|
||
|
||
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/icon"
|
||
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/input"
|
||
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
||
)
|
||
|
||
type LightboxOptions struct {
|
||
Disabled bool
|
||
}
|
||
|
||
type LightboxResult struct {
|
||
Element ui.Element
|
||
// Changed turns the picture; Closed is ×, Escape or outside.
|
||
Changed, Closed bool
|
||
}
|
||
|
||
// Lightbox shows pictures over a dark veil, with ◀ ▶.
|
||
func Lightbox(c *ui.Context, text string, n int, at *int, open *bool, o LightboxOptions, picture func(i int)) LightboxResult {
|
||
k := pixel.K(c)
|
||
if n < 1 || *at < 0 || *at >= n {
|
||
panic(fmt.Sprintf("overlay: Lightbox picture %d of %d", *at, n))
|
||
}
|
||
was, old := *open, *at
|
||
off := o.Disabled || pixel.Current(c).Inert
|
||
turn := func(d int) { *at = (*at + d + n) % n }
|
||
var res LightboxResult
|
||
res.Element = ui.DialogBase(c, open, func(back, panel ui.Element) {
|
||
deep, light := dark(k)
|
||
dim(k, back, deep, 13)
|
||
left, right := pixel.Shortcut(panel, 0, ui.KeyLeft), pixel.Shortcut(panel, 0, ui.KeyRight)
|
||
switch {
|
||
case off:
|
||
case left:
|
||
turn(-1)
|
||
case right:
|
||
turn(1)
|
||
}
|
||
panel.Label(text).Focusable().FocusRing(false).AlignItems(ui.Center).Gap(k.D(6)).Children(func() {
|
||
pixel.Harbor(c, panel, func() {
|
||
ui.Row(c).Gap(k.D(6)).AlignItems(ui.Center).Children(func() {
|
||
if input.IconButton(c, icon.ChevronLeft, k.Msg("prev"), input.IconButtonOptions{Disabled: o.Disabled}).Clicked {
|
||
turn(-1)
|
||
}
|
||
ui.Box(c).Key(*at).Children(func() { picture(*at) })
|
||
if input.IconButton(c, icon.ChevronRight, k.Msg("next"), input.IconButtonOptions{Disabled: o.Disabled}).Clicked {
|
||
turn(1)
|
||
}
|
||
})
|
||
ui.Row(c).Gap(k.D(8)).AlignItems(ui.Center).Children(func() {
|
||
pixel.Text(c, fmt.Sprintf("%d / %d", *at+1, n), pixel.TextOptions{Slot: light})
|
||
if input.IconButton(c, icon.Close, k.Msg("close"), input.IconButtonOptions{Size: input.Small, Disabled: o.Disabled}).Clicked {
|
||
*open = false
|
||
}
|
||
})
|
||
})
|
||
})
|
||
})
|
||
res.Changed, res.Closed = *at != old, was && !*open
|
||
if res.Changed || res.Closed {
|
||
slog.Debug("8bit: lightbox", "label", text, "at", *at, "closed", res.Closed)
|
||
}
|
||
return res
|
||
}
|