Files
8bitMyGoUI/project/taskitem.go
T
ZacharyZhang-NY c8d058799d Add project components 421-435; Checkbox turns only when on
Fifteen project components: QuestBoard, TaskItem, TaskList, Milestones,
Burndown, Pomodoro, Priority, AssigneePicker, LabelPicker, TimeTracker,
Roadmap, SprintPanel, IssueCard, Checklist and WorkloadBar.

QuestBoard is one base that draws TODO, DOING and DONE; arrows move,
Alt with an arrow carries a card, and a drag carries it live. Priority
draws 12x12 bars, and Critical is on fire. Pomodoro banks time on PAUSE
and the tomato sleeps through the rest. Extreme inputs fail fast or
saturate instead of wrapping.

MyGo's CheckboxBase turns its value before Disabled is set, so
input.Checkbox now hands it a copy and keeps only turns of an enabled
base. The home scene test checks the sky row, not one pixel that
falling snow can cover.
2026-10-12 10:25:07 -04:00

56 lines
1.4 KiB
Go

package project
import (
"log/slog"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/display"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/input"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
// Task is a thing to do.
type Task struct {
Title string
Done bool
Priority Level
// Assignee is a party member's name; empty is nobody.
Assignee string
}
type TaskItemOptions struct {
Disabled bool
}
type TaskItemResult struct {
Element *ui.Element
Changed bool
}
// TaskItem is a checkbox, title, priority and assignee.
func TaskItem(c *ui.Context, t *Task, o TaskItemOptions) TaskItemResult {
k := pixel.K(c)
if t.Title == "" {
panic("project: TaskItem has no title")
}
var res TaskItemResult
res.Element = ui.Row(c).FillWidth().Gap(k.D(6)).AlignItems(ui.Center).Children(func() {
res.Changed = input.Checkbox(c, t.Title, &t.Done, input.CheckboxOptions{Disabled: o.Disabled}).Changed
ui.Box(c).Grow(1)
Priority(c, t.Priority, PriorityOptions{})
// Nobody shows as an empty dotted seat.
if t.Assignee == "" {
ui.Box(c).Size(k.D(16), k.D(16)).Role(ui.RoleImage).Label(k.Msg("nobody")).Draw(func(p *ui.Painter, r ui.Rect) {
k.Canvas(p, r).Veil(0, 0, 16, 16, pixel.Shade, 8)
})
return
}
display.Avatar(c, t.Assignee, display.AvatarOptions{})
})
if res.Changed {
slog.Debug("8bit: task", "done", t.Done)
}
return res
}