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>
37 lines
1007 B
Go
37 lines
1007 B
Go
package display
|
||
|
||
import (
|
||
"fmt"
|
||
|
||
"github.com/egoist/mygo/ui"
|
||
|
||
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
||
)
|
||
|
||
type PlaceholderOptions struct {
|
||
// W×H is zero for 64×48 dots.
|
||
W, H int
|
||
}
|
||
|
||
// Placeholder is a dithered box with a cross and size.
|
||
func Placeholder(c *ui.Context, o PlaceholderOptions) ui.Element {
|
||
k := pixel.K(c)
|
||
w, h := pixel.Or("Placeholder W", o.W, 64), pixel.Or("Placeholder H", o.H, 48)
|
||
size := fmt.Sprintf("%d×%d", w, h)
|
||
return art(c, k, size, w, h, func(g pixel.Canvas) {
|
||
if w < 3 || h < 3 {
|
||
g.Dither(0, 0, w, h, pixel.Face, pixel.Shade, 4)
|
||
return
|
||
}
|
||
g.Frame(0, 0, w, h, pixel.Flat, pixel.Face)
|
||
g.Dither(1, 1, w-2, h-2, pixel.Face, pixel.Shade, 4)
|
||
g.Line(1, 1, w-2, h-2, pixel.Shade)
|
||
g.Line(w-2, 1, 1, h-2, pixel.Shade)
|
||
tw := pixel.Measure(size)
|
||
if tw+4 <= w && pixel.LineHeight <= h {
|
||
g.Rect((w-tw)/2-2, (h-pixel.LineHeight)/2, tw+4, pixel.LineHeight, pixel.Face)
|
||
g.Text((w-tw)/2, (h-pixel.LineHeight)/2, size, pixel.Faint, 1)
|
||
}
|
||
})
|
||
}
|