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>
74 lines
2.6 KiB
Go
74 lines
2.6 KiB
Go
package project
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"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"
|
|
)
|
|
|
|
// Milestone holds a goal, due date and completion counts.
|
|
type Milestone struct {
|
|
Title string
|
|
Due core.Date
|
|
Done, Total int
|
|
}
|
|
|
|
// MilestoneProgressOptions configure a MilestoneProgress.
|
|
type MilestoneProgressOptions struct {
|
|
// Today anchors the date note; zero uses the system clock.
|
|
Today core.Date
|
|
}
|
|
|
|
// MilestoneProgress shows completion counts, progress and due dates.
|
|
func MilestoneProgress(c *ui.Context, m Milestone, opts MilestoneProgressOptions) ui.Element {
|
|
core.DatetimeCheckDate("MilestoneProgress Due", m.Due)
|
|
if m.Total < 0 || m.Done < 0 || m.Done > m.Total {
|
|
panic(fmt.Sprintf("mujica: MilestoneProgress %d of %d is not valid", m.Done, m.Total))
|
|
}
|
|
k := core.Tokens(c)
|
|
d := core.Density(c)
|
|
today := core.DatetimeToday(c, opts.Today)
|
|
frac := 0.0
|
|
if m.Total > 0 {
|
|
frac = float64(m.Done) / float64(m.Total)
|
|
}
|
|
reached := m.Total > 0 && m.Done == m.Total
|
|
pct := fmt.Sprintf("%d%%", int(frac*100))
|
|
col := ui.Column(c).Gap(d.Unit()*2).Padding(d.Unit()*3).Radius(theme.CardRadius).Border(theme.BorderWidth, k.Border).
|
|
Background(k.Surface).Role(ui.RoleGroup).Label(m.Title).Description(pct)
|
|
col.Children(func() {
|
|
ui.Row(c).Gap(d.Unit() * 2).AlignItems(ui.Center).Children(func() {
|
|
ui.Box(c).Size(12, 12).Shrink(0).Draw(func(p *ui.Painter, r ui.Rect) {
|
|
p.FillPath(internal.Diamond(r.X+r.W/2, r.Y+r.H/2, r.W), k.Ornament)
|
|
})
|
|
ui.Text(c, m.Title).Font(theme.SerifFont).TextColor(k.Text).Grow(1).SingleLine().Ellipsis("…")
|
|
ui.Text(c, pct).TextColor(k.AccentText).FontFeatures("tnum")
|
|
})
|
|
projectBar(c, frac, m.Title)
|
|
ui.Row(c).Gap(d.Unit() * 2).AlignItems(ui.Center).Children(func() {
|
|
ui.Text(c, fmt.Sprintf(core.Msg(c, "milestone_progress.count"), m.Done, m.Total)).FontSize(core.FontSize(c, theme.CaptionSize)).
|
|
TextColor(k.TextMuted).Grow(1).FontFeatures("tnum")
|
|
text, late := projectDueText(c, m.Due, today, reached)
|
|
fg, icon := k.TextMuted, "calendar"
|
|
switch {
|
|
case reached:
|
|
text, fg, icon = core.Msg(c, "milestone_progress.reached"), k.Success, "circle-check"
|
|
case late:
|
|
fg, icon = k.Danger, "triangle-alert"
|
|
}
|
|
if text != "" {
|
|
ui.Row(c).Gap(d.Unit()).AlignItems(ui.Center).TextColor(fg).Role(ui.RoleStatus).Children(func() {
|
|
ui.Icon(c, icons.Must(icon)).Size(14, 14)
|
|
ui.Text(c, text).FontSize(core.FontSize(c, theme.CaptionSize))
|
|
})
|
|
}
|
|
})
|
|
})
|
|
return col
|
|
}
|