Files
ZacharyZhang-NYandClaude Opus 5.5 bcce34cda1 Upgrade MyGo to v0.5.5
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>
2026-10-17 01:37:54 -04:00

150 lines
3.7 KiB
Go

package project
import (
"fmt"
"slices"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/core"
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/datetime"
)
// Priority describes urgency; zero means no priority.
type Priority int
const (
PriorityNone Priority = iota
PriorityLow
PriorityMedium
PriorityHigh
PriorityUrgent
)
// ProjectMember is a person tasks can be assigned to.
type ProjectMember struct {
ID string
Name string
}
// TaskLabel is a colored tag tasks carry.
type TaskLabel struct {
ID string
Name string
Color datetime.EventColor
}
// Subtask is one checklist step of a task.
type Subtask struct {
ID string
Title string
Done bool
}
// Task is one unit of project work.
type Task struct {
// ID is the issue key, as ENG-123.
ID string
Title string
Done bool
Priority Priority
Due core.Date
Status string
Assignees []string
Labels []string
Subtasks []Subtask
}
// StatusGroup is the workflow stage a status belongs to.
type StatusGroup int
const (
StatusBacklog StatusGroup = iota
StatusUnstarted
StatusStarted
StatusCompleted
StatusCanceled
)
// WorkflowStatus is one workflow state.
type WorkflowStatus struct {
ID string
Name string
Group StatusGroup
}
// ProjectResult exposes the element and task events.
type ProjectResult struct {
Element ui.Element
changed string
opened string
}
// Changed returns the edited task ID.
func (r ProjectResult) Changed() (string, bool) { return r.changed, r.changed != "" }
// Opened returns the activated task ID.
func (r ProjectResult) Opened() (string, bool) { return r.opened, r.opened != "" }
// projectCheckPriority panics on an unknown priority.
func projectCheckPriority(p Priority) {
if p < PriorityNone || p > PriorityUrgent {
panic(fmt.Sprintf("mujica: Priority %d out of range", p))
}
}
// projectMember resolves a member ID or panics.
func projectMember(members []ProjectMember, id string) ProjectMember {
i := slices.IndexFunc(members, func(m ProjectMember) bool { return m.ID == id })
if i < 0 {
panic(fmt.Sprintf("mujica: unknown member %q", id))
}
return members[i]
}
// projectLabel resolves a label ID or panics.
func projectLabel(labels []TaskLabel, id string) TaskLabel {
i := slices.IndexFunc(labels, func(l TaskLabel) bool { return l.ID == id })
if i < 0 {
panic(fmt.Sprintf("mujica: unknown label %q", id))
}
return labels[i]
}
// projectStatus resolves a status ID or panics.
func projectStatus(statuses []WorkflowStatus, id string) WorkflowStatus {
i := slices.IndexFunc(statuses, func(s WorkflowStatus) bool { return s.ID == id })
if i < 0 {
panic(fmt.Sprintf("mujica: unknown status %q", id))
}
return statuses[i]
}
// projectDueText formats a date relative to today.
func projectDueText(c *ui.Context, due, today core.Date, done bool) (string, bool) {
core.DatetimeCheckDate("project due", due)
if due.IsZero() {
return "", false
}
days := int(due.Civil().Sub(today.Civil()).Hours() / 24)
switch {
case days < 0 && !done:
return core.CalendarCount(c, "projects.overdue", -days), true
case days == 0:
return core.Msg(c, "projects.due_today"), false
case days == 1:
return core.Msg(c, "projects.due_tomorrow"), false
}
return fmt.Sprintf(core.Msg(c, "projects.due"), core.DatetimeMonthName(c, due.Month), due.Day), false
}
// projectBar draws a named completion bar.
func projectBar(c *ui.Context, frac float64, label string) ui.Element {
k := core.Tokens(c)
return ui.Box(c).Height(6).FillWidth().Role(ui.RoleProgress).Label(label).Description(fmt.Sprintf("%d%%", int(frac*100))).
Draw(func(p *ui.Painter, r ui.Rect) {
p.Fill(r, k.Border, 3)
p.Fill(ui.Rect{X: r.X, Y: r.Y, W: r.W * float32(frac), H: r.H}, k.AccentText, 3)
})
}