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>
117 lines
3.3 KiB
Go
117 lines
3.3 KiB
Go
package data
|
|
|
|
import (
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/core"
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/icons"
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/internal"
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/theme"
|
|
)
|
|
|
|
// TimelineStatus marks an event's state with a shape and a word, not only color.
|
|
type TimelineStatus int
|
|
|
|
const (
|
|
TimelineDefault TimelineStatus = iota
|
|
TimelineDone
|
|
TimelineActive
|
|
TimelineWarning
|
|
TimelineError
|
|
)
|
|
|
|
// TimelineItem is one event of a Timeline.
|
|
type TimelineItem struct {
|
|
Time string
|
|
Title string
|
|
Content string
|
|
Status TimelineStatus
|
|
}
|
|
|
|
// Timeline lists events top to bottom with markers joined by a line; long text wraps.
|
|
func Timeline(c *ui.Context, items []TimelineItem) ui.Element {
|
|
k := core.Tokens(c)
|
|
u := core.Density(c).Unit()
|
|
return ui.Column(c).Role(ui.RoleList).Children(func() {
|
|
for i, it := range items {
|
|
last := i == len(items)-1
|
|
ui.Row(c).Gap(u * 3).AlignItems(ui.Stretch).Role(ui.RoleListItem).Children(func() {
|
|
ui.Column(c).Width(20).Shrink(0).AlignItems(ui.Center).Children(func() {
|
|
timelineMarker(c, it.Status)
|
|
if !last {
|
|
ui.Box(c).Width(1).Grow(1).MinHeight(u * 3).Background(k.Border)
|
|
}
|
|
})
|
|
ui.Column(c).Grow(1).MinWidth(0).Gap(u).Padding(0, 0, u*5, 0).Children(func() {
|
|
ui.Row(c).Gap(u * 2).AlignItems(ui.Center).Wrap().Children(func() {
|
|
if it.Time != "" {
|
|
ui.Text(c, it.Time).FontSize(core.FontSize(c, theme.CaptionSize)).TextColor(k.TextMuted)
|
|
}
|
|
if w := timelineWord(c, it.Status); w != "" {
|
|
ui.Text(c, w).FontSize(core.FontSize(c, theme.CaptionSize)).TextColor(timelineColor(k, it.Status)).FontWeight(600)
|
|
}
|
|
})
|
|
if it.Title != "" {
|
|
ui.Text(c, it.Title).FontWeight(600)
|
|
}
|
|
if it.Content != "" {
|
|
ui.Text(c, it.Content).TextColor(k.TextMuted)
|
|
}
|
|
})
|
|
})
|
|
}
|
|
})
|
|
}
|
|
|
|
func timelineColor(k theme.Tokens, s TimelineStatus) ui.Color {
|
|
switch s {
|
|
case TimelineDone:
|
|
return k.Success
|
|
case TimelineActive:
|
|
return k.AccentText
|
|
case TimelineWarning:
|
|
return k.Warning
|
|
case TimelineError:
|
|
return k.Danger
|
|
}
|
|
return k.TextMuted
|
|
}
|
|
|
|
func timelineWord(c *ui.Context, s TimelineStatus) string {
|
|
switch s {
|
|
case TimelineDone:
|
|
return core.Msg(c, "timeline.done")
|
|
case TimelineActive:
|
|
return core.Msg(c, "timeline.active")
|
|
case TimelineWarning:
|
|
return core.Msg(c, "timeline.warning")
|
|
case TimelineError:
|
|
return core.Msg(c, "timeline.error")
|
|
}
|
|
return ""
|
|
}
|
|
|
|
// timelineMarker draws a hollow diamond, or a status icon.
|
|
func timelineMarker(c *ui.Context, s TimelineStatus) {
|
|
k := core.Tokens(c)
|
|
col := timelineColor(k, s)
|
|
box := ui.Box(c).Size(20, 20).Shrink(0).Center().TextColor(col)
|
|
switch s {
|
|
case TimelineDone:
|
|
box.Children(func() { ui.Icon(c, icons.Must("circle-check")).Size(18, 18) })
|
|
case TimelineWarning:
|
|
box.Children(func() { ui.Icon(c, icons.Must("triangle-alert")).Size(18, 18) })
|
|
case TimelineError:
|
|
box.Children(func() { ui.Icon(c, icons.Must("circle-x")).Size(18, 18) })
|
|
default:
|
|
box.Draw(func(p *ui.Painter, r ui.Rect) {
|
|
cx, cy := internal.Snap(p, r.X+r.W/2), internal.Snap(p, r.Y+r.H/2)
|
|
if s == TimelineActive {
|
|
p.FillPath(internal.Diamond(cx, cy, 12), col)
|
|
} else {
|
|
p.StrokePath(internal.Diamond(cx, cy, 11), 1.5, col)
|
|
}
|
|
})
|
|
}
|
|
}
|