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>
52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
// Package layout arranges screens, windows and panes on dots.
|
|
package layout
|
|
|
|
import (
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
|
)
|
|
|
|
// box frames the canvas unless it is too small.
|
|
func box(g pixel.Canvas, style pixel.FrameStyle, fill pixel.Slot) {
|
|
if g.W >= 3 && g.H >= 3 {
|
|
g.Frame(0, 0, g.W, g.H, style, fill)
|
|
}
|
|
}
|
|
|
|
// rule draws n dots on an axis in on/off runs.
|
|
func rule(g pixel.Canvas, x, y, n int, vertical bool, on, off int, s pixel.Slot) {
|
|
for i := 0; i < n; i += on + off {
|
|
run := min(on, n-i)
|
|
if vertical {
|
|
g.VLine(x, y+i, run, s)
|
|
} else {
|
|
g.HLine(x+i, y, run, s)
|
|
}
|
|
}
|
|
}
|
|
|
|
type dragKey struct{}
|
|
|
|
// drag is enabled e's pointer travel this frame, in dots.
|
|
func drag(k pixel.Kit, e ui.Element) (dx, dy int, ok bool) {
|
|
rest := ui.Local(e, dragKey{}, func() [2]float32 { return [2]float32{} })
|
|
fx, fy, ok := e.Dragged()
|
|
if !ok || e.IsDisabled() {
|
|
*rest = [2]float32{}
|
|
return 0, 0, false
|
|
}
|
|
x, y := rest[0]+fx/k.Dot(), rest[1]+fy/k.Dot()
|
|
dx, dy = int(x), int(y)
|
|
*rest = [2]float32{x - float32(dx), y - float32(dy)}
|
|
return dx, dy, true
|
|
}
|
|
|
|
// label is o's label, or the built-in copy for key.
|
|
func label(k pixel.Kit, s, key string) string {
|
|
if s != "" {
|
|
return s
|
|
}
|
|
return k.Msg(key)
|
|
}
|