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>
53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
package overlay
|
|
|
|
import (
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
|
)
|
|
|
|
type PopoverOptions struct {
|
|
// Width is the panel's in dots; zero fits the content.
|
|
Width int
|
|
}
|
|
|
|
// notch is the pointer's height in dots.
|
|
const notch = 4
|
|
|
|
// Popover opens a panel below anchor, notched toward it.
|
|
func Popover(c *ui.Context, text string, anchor ui.Element, open *bool, o PopoverOptions, content func()) ui.Element {
|
|
k := pixel.K(c)
|
|
w := pixel.Or("Popover Width", o.Width, 0)
|
|
ab := anchor.Bounds()
|
|
return ui.PopoverBase(c, anchor, open, func(panel ui.Element) {
|
|
if w > 0 {
|
|
panel.Width(k.D(w))
|
|
}
|
|
panel.Label(text).Padding(k.D(notch+5), k.D(7)).Draw(func(p *ui.Painter, r ui.Rect) {
|
|
g := k.Canvas(p, r)
|
|
// Flipped above its anchor, the notch points down.
|
|
up := r.Y >= ab.Y
|
|
top := notch
|
|
if !up {
|
|
top = 0
|
|
}
|
|
g.Frame(0, top, g.W, g.H-notch, pixel.Window, pixel.Face)
|
|
x := max(notch+1, min(g.W-notch-2, int((ab.X+ab.W/2-r.X)/k.Dot())))
|
|
for j := range notch {
|
|
y := j
|
|
if !up {
|
|
y = g.H - 1 - j
|
|
}
|
|
g.HLine(x-j, y, 2*j+1, pixel.Face)
|
|
g.Dot(x-j, y, pixel.Edge)
|
|
g.Dot(x+j, y, pixel.Edge)
|
|
}
|
|
edge := notch
|
|
if !up {
|
|
edge = g.H - notch - 1
|
|
}
|
|
g.HLine(x-notch+1, edge, 2*notch-1, pixel.Face)
|
|
}).Children(content)
|
|
})
|
|
}
|