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.
This commit is contained in:
30 files changed
+2496
-7
No files matched your search
+8
-2
@@ -33,7 +33,13 @@ type CheckboxResult struct {
|
||||
// Checkbox is a labeled 8×8 box with a hand-placed check.
|
||||
func Checkbox(c *ui.Context, text string, checked *bool, o CheckboxOptions) CheckboxResult {
|
||||
k := pixel.K(c)
|
||||
shell, base, st := pixel.Shell(c, func() *ui.Element { return ui.CheckboxBase(c, checked).Label(text).Disabled(o.Disabled) })
|
||||
// The base turns before it learns it is off.
|
||||
on := *checked
|
||||
shell, base, st := pixel.Shell(c, func() *ui.Element { return ui.CheckboxBase(c, &on).Label(text).Disabled(o.Disabled) })
|
||||
changed := on != *checked && !base.IsDisabled()
|
||||
if changed {
|
||||
*checked = on
|
||||
}
|
||||
mark := check
|
||||
if !*checked {
|
||||
mark = nil
|
||||
@@ -41,7 +47,7 @@ func Checkbox(c *ui.Context, text string, checked *bool, o CheckboxOptions) Chec
|
||||
shell.Size(k.D(12+pixel.Measure(text)), k.D(pixel.LineHeight)).Draw(func(p *ui.Painter, r ui.Rect) {
|
||||
box(k.Canvas(p, r), text, mark, st)
|
||||
})
|
||||
res := CheckboxResult{Element: shell, Changed: base.Changed()}
|
||||
res := CheckboxResult{Element: shell, Changed: changed}
|
||||
if res.Changed {
|
||||
slog.Debug("8bit: checkbox", "label", text, "checked", *checked)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package input_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/egoist/mygo/ui"
|
||||
|
||||
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/input"
|
||||
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
||||
)
|
||||
|
||||
func TestCheckboxIgnoresAKeyAsItTurnsOff(t *testing.T) {
|
||||
for _, inert := range []bool{false, true} {
|
||||
on, off, changed := false, false, false
|
||||
tt := ui.NewTester(func(c *ui.Context) {
|
||||
pixel.Use(c, pixel.Settings{Palette: pixel.SpringDay, Now: (&clock{time.Unix(3_000_000, 0)}).now, Inert: off && inert})
|
||||
changed = input.Checkbox(c, "Box", &on, input.CheckboxOptions{Disabled: off && !inert}).Changed || changed
|
||||
}, 300, 100)
|
||||
tt.Key(0, ui.KeyTab)
|
||||
// Space, sent while on, lands as the box turns off.
|
||||
off = true
|
||||
tt.Key(0, ui.KeySpace)
|
||||
if on || changed {
|
||||
t.Errorf("inert %v: Space turned the box to %v, changed %v", inert, on, changed)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user