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>
46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
package datetime
|
||
|
||
import (
|
||
"fmt"
|
||
"time"
|
||
|
||
"github.com/egoist/mygo/ui"
|
||
|
||
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
||
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/text"
|
||
)
|
||
|
||
type DigitalClockOptions struct {
|
||
// Scale is 1–4; zero means 2.
|
||
Scale int
|
||
}
|
||
|
||
// DigitalClock shows HH:MM:SS in seven segments; colons blink.
|
||
func DigitalClock(c *ui.Context, o DigitalClockOptions) ui.Element {
|
||
k := pixel.K(c)
|
||
sc := pixel.Or("DigitalClock Scale", o.Scale, 2)
|
||
if sc > 4 {
|
||
panic(fmt.Sprintf("datetime: DigitalClock Scale %d outside 1–4", sc))
|
||
}
|
||
// Wake on the next whole second.
|
||
now := k.Now()
|
||
k.At(c, now.Truncate(time.Second).Add(time.Second))
|
||
colon := func() {
|
||
ui.Box(c).Size(k.D(3*sc), k.D(11*sc)).Role(ui.RoleNone).Draw(func(p *ui.Painter, r ui.Rect) {
|
||
g := k.Canvas(p, r)
|
||
// The colon blinks each half second, unless reduced.
|
||
if k.Reduce() || g.Step(4)%4 < 2 {
|
||
g.Rect(sc, 3*sc, sc, sc, pixel.Bad)
|
||
g.Rect(sc, 7*sc, sc, sc, pixel.Bad)
|
||
}
|
||
})
|
||
}
|
||
return ui.Row(c).Gap(k.D(2 * sc)).Role(ui.RoleText).Label(now.Format("15:04:05")).Children(func() {
|
||
text.SevenSegment(c, now.Format("15"), text.SevenSegmentOptions{Scale: sc})
|
||
colon()
|
||
text.SevenSegment(c, now.Format("04"), text.SevenSegmentOptions{Scale: sc})
|
||
colon()
|
||
text.SevenSegment(c, now.Format("05"), text.SevenSegmentOptions{Scale: sc})
|
||
})
|
||
}
|