MyGo v0.5.5 returns ui.Element as a checked value handle instead of a
pointer. Migrated with `mygo migrate-ui`, then fixed what the codemod
leaves to review:
- Element nil checks become .Valid(); absent elements are ui.Element{}.
- Input handlers and paint callbacks run outside the build pass, where
elements expire and Context methods are inert: read IsDisabled into a
local during the build, keep a ui.Handle for Focus, use c.Services()
for clipboard access, create ui.Local state during the build.
- Add core.AutoFocus: v0.5.5 records an overlay's opener after its
content builds, so same-frame autofocus lost focus restore on close.
It focuses one frame later; cascader rows defer their focus likewise.
- core.OverlayLayer identifies build passes by the root element, not
c.Now(), which repeats across passes and under the Tester clock.
- Context menus survive the opening press counted as PressedOutside;
split button tooltip no longer reorders its open menu; disabled
menubar rows pass presses to the panel; Form defers blur-started
async checks so the growing message no longer moves Submit away
from the release; Combobox drops its disabled copy now that MyGo
blocks typing under a disabled wrapper (canary flipped to a guard).
- The Tester clock is virtual: tests use Advance/Now instead of
time.Sleep/time.Now and read element state inside the view. The web
mirror advances the clock to wall time before each frame and input.
- AGENTS.md and docs describe the value Element API and the new pin.
Snapshot goldens are darwin-only and were not re-verified here.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
82 lines
2.5 KiB
Go
82 lines
2.5 KiB
Go
package datetime
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/core"
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/internal"
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/theme"
|
|
)
|
|
|
|
// EventChipOptions configure an EventChip.
|
|
type EventChipOptions struct {
|
|
// Location is the zone the time shows in; required.
|
|
Location *time.Location
|
|
Hour12 bool
|
|
// Inline puts the start time and title on one line.
|
|
Inline bool
|
|
Selected bool
|
|
Disabled bool
|
|
}
|
|
|
|
// EventChip is a clickable, truncating event block.
|
|
func EventChip(c *ui.Context, ev CalendarEvent, opts EventChipOptions) ui.Element {
|
|
loc := eventLocation("EventChip", opts.Location)
|
|
k := core.Tokens(c)
|
|
d := core.Density(c)
|
|
col := EventTone(k, ev.Color)
|
|
when := eventTimeText(c, ev, loc, opts.Hour12)
|
|
title := ev.Title
|
|
if title == "" {
|
|
title = core.Msg(c, "event_chip.untitled")
|
|
}
|
|
b := ui.ButtonBase(c).MinHeight(theme.MinHitSize).MinWidth(theme.MinHitSize).Justify(ui.Start).AlignItems(ui.Start).
|
|
Radius(theme.ControlRadius).Padding(d.Unit(), d.Unit()*2).PaddingX(d.Unit() * 2).Gap(d.Unit()).
|
|
Label(title + ", " + when).Disabled(opts.Disabled).Clip()
|
|
internal.Ring(b, k.Focus, theme.ControlRadius)
|
|
bg := col.Alpha(0.14).Over(k.Surface)
|
|
switch {
|
|
case opts.Selected:
|
|
bg = k.Selection
|
|
case b.Pressed():
|
|
bg = col.Alpha(0.24).Over(k.Surface)
|
|
case b.Hovered():
|
|
bg = col.Alpha(0.2).Over(k.Surface)
|
|
}
|
|
b.Background(bg).Transition(core.ColorFade)
|
|
if !opts.Inline {
|
|
b.Column()
|
|
}
|
|
b.Draw(func(p *ui.Painter, r ui.Rect) {
|
|
p.Fill(ui.Rect{X: r.X, Y: r.Y, W: 3, H: r.H}, col, 0)
|
|
})
|
|
selected := opts.Selected
|
|
b.DrawOver(func(p *ui.Painter, r ui.Rect) {
|
|
if selected {
|
|
core.DatetimeSelectedMark(p, r, col)
|
|
}
|
|
})
|
|
b.Children(func() {
|
|
small := core.FontSize(c, theme.CaptionSize)
|
|
if opts.Inline {
|
|
ui.Text(c, eventStartText(c, ev, loc, opts.Hour12)).FontSize(small).TextColor(k.TextMuted).SingleLine().Shrink(0).FontFeatures("tnum")
|
|
}
|
|
ui.Text(c, title).FontSize(small).Bold().TextColor(k.Text).SingleLine().Ellipsis("…").Shrink(1)
|
|
if !opts.Inline {
|
|
ui.Text(c, when).FontSize(small).TextColor(k.TextMuted).SingleLine().Ellipsis("…").FontFeatures("tnum")
|
|
}
|
|
})
|
|
return b
|
|
}
|
|
|
|
// eventStartText is the start time alone, or "All day".
|
|
func eventStartText(c *ui.Context, ev CalendarEvent, loc *time.Location, hour12 bool) string {
|
|
if ev.AllDay {
|
|
return core.Msg(c, "event_chip.all_day")
|
|
}
|
|
s := ev.Start.In(loc)
|
|
return timeText(c, TimeOfDay{s.Hour(), s.Minute(), 0}, timeConfig{hour12: hour12})
|
|
}
|