Merge branch 'main' into worktree-agent-ab9ba373bc47c2352
This commit is contained in:
11 files changed
+193
-25
No files matched your search
@@ -1,7 +1,8 @@
|
|||||||
# AGENTS.md
|
# AGENTS.md
|
||||||
|
|
||||||
MujicaUI: court-gothic components for MyGo native UI. Go library, package `mujica`, module `mujicaui`.
|
MujicaUI: court-gothic components for MyGo native UI. Go library, package `mujica`, module `mujicaui`.
|
||||||
Progress truth: `TASKS.md`. Requirements: `PRD.md`.
|
Progress truth: `TASKS.md`. Requirements: `PRD.md` and `docs/prd/ext-*.md` (101–500).
|
||||||
|
Planned: once 001–500 land, the root package splits into category sub-packages (TASKS T22). Until then everything stays in the root package.
|
||||||
|
|
||||||
## Stack
|
## Stack
|
||||||
|
|
||||||
|
|||||||
@@ -43,4 +43,5 @@ Ordered by PRD sections. Check an item only after its codex review passes. Revie
|
|||||||
- [ ] T19 §8 Docs: install, minimal example, theme, compat; 100 component pages; examples compile
|
- [ ] T19 §8 Docs: install, minimal example, theme, compat; 100 component pages; examples compile
|
||||||
- [ ] T20 §9 Snapshots, density baselines, large-data and lifecycle tests
|
- [ ] T20 §9 Snapshots, density baselines, large-data and lifecycle tests
|
||||||
- [ ] T21 §9 CI workflow
|
- [ ] T21 §9 CI workflow
|
||||||
- [ ] T22 §10 Acceptance checklist
|
- [ ] T22 §6.3 Split into category sub-packages after 001–500 land (user decision 2026-10-05); update PRD §6.3, docs, Gallery, CI
|
||||||
|
- [ ] T23 §10 Acceptance checklist
|
||||||
@@ -31,6 +31,7 @@ type mirror struct {
|
|||||||
urls int
|
urls int
|
||||||
clip string
|
clip string
|
||||||
copied bool
|
copied bool
|
||||||
|
probes int
|
||||||
cursor ui.Cursor
|
cursor ui.Cursor
|
||||||
down *input
|
down *input
|
||||||
enc png.Encoder
|
enc png.Encoder
|
||||||
|
|||||||
@@ -154,7 +154,9 @@ keys.addEventListener("keydown", (e) => {
|
|||||||
if (cmd && commands[e.code] && !e.altKey) {
|
if (cmd && commands[e.code] && !e.altKey) {
|
||||||
send({ type: "command", text: e.code === "KeyZ" && e.shiftKey ? "redo" : commands[e.code] });
|
send({ type: "command", text: e.code === "KeyZ" && e.shiftKey ? "redo" : commands[e.code] });
|
||||||
} else {
|
} else {
|
||||||
send({ type: "key", code: e.code, text: e.key.length === 1 ? e.key : "", mods: mods(e) });
|
// NumLock off: numpad keys act as navigation keys, named by e.key.
|
||||||
|
const code = e.code.startsWith("Numpad") && e.key.length > 1 && e.key !== "Enter" ? e.key : e.code;
|
||||||
|
send({ type: "key", code, text: e.key.length === 1 ? e.key : "", mods: mods(e) });
|
||||||
}
|
}
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ func (m *mirror) serveInput(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
m.mu.Lock()
|
m.mu.Lock()
|
||||||
err := m.apply(in)
|
err := m.applyWatchingClipboard(in)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
m.capture()
|
m.capture()
|
||||||
}
|
}
|
||||||
@@ -67,7 +67,8 @@ func (m *mirror) apply(in input) error {
|
|||||||
if d := m.down; d != nil {
|
if d := m.down; d != nil {
|
||||||
m.down = nil
|
m.down = nil
|
||||||
if dx, dy := in.X-d.X, in.Y-d.Y; dx*dx+dy*dy <= 16 {
|
if dx, dy := in.X-d.X, in.Y-d.Y; dx*dx+dy*dy <= 16 {
|
||||||
m.tt.ClickAtWith(modifiers(d.Mods), d.X, d.Y)
|
// The click lands where it is released, as a real press and release would.
|
||||||
|
m.tt.ClickAtWith(modifiers(d.Mods), in.X, in.Y)
|
||||||
} else {
|
} else {
|
||||||
slog.Info("gallery: modified drag ignored; tester clicks only", "mods", modifiers(d.Mods))
|
slog.Info("gallery: modified drag ignored; tester clicks only", "mods", modifiers(d.Mods))
|
||||||
}
|
}
|
||||||
@@ -124,3 +125,21 @@ func modifiers(m []bool) ui.Modifiers {
|
|||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// applyWatchingClipboard applies in and notes any clipboard write it caused, even of equal text.
|
||||||
|
func (m *mirror) applyWatchingClipboard(in input) error {
|
||||||
|
if in.Type == "paste" || in.Type == "command" && in.Text == "paste" {
|
||||||
|
return m.apply(in)
|
||||||
|
}
|
||||||
|
before := m.tt.Clipboard()
|
||||||
|
m.probes++
|
||||||
|
probe := fmt.Sprintf("\x00mujica-mirror-probe-%d", m.probes)
|
||||||
|
m.tt.SetClipboard(probe)
|
||||||
|
err := m.apply(in)
|
||||||
|
if m.tt.Clipboard() == probe {
|
||||||
|
m.tt.SetClipboard(before)
|
||||||
|
} else {
|
||||||
|
m.copied = true
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
@@ -260,3 +260,62 @@ func TestMirrorForwardsEveryAnnouncement(t *testing.T) {
|
|||||||
t.Fatalf("announcements forwarded %d times, want 2", heard)
|
t.Fatalf("announcements forwarded %d times, want 2", heard)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMirrorModifiedClickReleasedJustOutsideDoesNotClick(t *testing.T) {
|
||||||
|
clicks := 0
|
||||||
|
var box ui.Rect
|
||||||
|
m, srv := mirrorWith(t, func(c *ui.Context) {
|
||||||
|
mujica.Use(c, mujica.Settings{})
|
||||||
|
ui.Column(c).Padding(20).AlignItems(ui.Start).Children(func() {
|
||||||
|
b := mujica.Button(c, "Seal", mujica.ButtonOptions{})
|
||||||
|
box = b.Bounds()
|
||||||
|
if b.Clicked() {
|
||||||
|
clicks++
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
m.mu.Lock()
|
||||||
|
m.tt.Frame()
|
||||||
|
r := box
|
||||||
|
m.mu.Unlock()
|
||||||
|
shift := []bool{true}
|
||||||
|
y := r.Y + r.H/2
|
||||||
|
postInput(t, srv, input{Type: "down", X: r.X + r.W - 1, Y: y, Mods: shift})
|
||||||
|
postInput(t, srv, input{Type: "up", X: r.X + r.W + 2, Y: y, Mods: shift})
|
||||||
|
if clicks != 0 {
|
||||||
|
t.Fatalf("clicks %d after releasing 2 DIP outside", clicks)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMirrorNotifiesEveryCopyOfEqualText(t *testing.T) {
|
||||||
|
m, srv := mirrorWith(t, func(c *ui.Context) {
|
||||||
|
mujica.Use(c, mujica.Settings{})
|
||||||
|
ui.Column(c).Padding(20).Children(func() {
|
||||||
|
if mujica.Button(c, "Copy", mujica.ButtonOptions{}).Clicked() {
|
||||||
|
c.WriteClipboard("snippet")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
ch := make(chan []byte, 64)
|
||||||
|
m.mu.Lock()
|
||||||
|
m.subs[ch] = struct{}{}
|
||||||
|
m.mu.Unlock()
|
||||||
|
for range 2 {
|
||||||
|
postInput(t, srv, input{Type: "down", X: 40, Y: 35})
|
||||||
|
postInput(t, srv, input{Type: "up", X: 40, Y: 35})
|
||||||
|
}
|
||||||
|
copies := 0
|
||||||
|
for len(ch) > 0 {
|
||||||
|
if bytes.Contains(<-ch, []byte(`"clipboard":"snippet"`)) {
|
||||||
|
copies++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if copies != 2 {
|
||||||
|
t.Fatalf("copies forwarded %d, want 2", copies)
|
||||||
|
}
|
||||||
|
m.mu.Lock()
|
||||||
|
defer m.mu.Unlock()
|
||||||
|
if got := m.tt.Clipboard(); got != "snippet" {
|
||||||
|
t.Fatalf("clipboard %q", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -293,7 +293,7 @@ func FormItem[T any](c *ui.Context, f *FormScope, name string, value *T, opts Fo
|
|||||||
desc = msg(c, "form.checking")
|
desc = msg(c, "form.checking")
|
||||||
}
|
}
|
||||||
var ctrl *ui.Element
|
var ctrl *ui.Element
|
||||||
field := formFieldBuild(c, opts.Label, FormFieldOptions{Required: opts.Required, Description: desc, Error: st.Error(name)}, f.horizontal, func() *ui.Element {
|
field := formFieldBuild(c, name, opts.Label, FormFieldOptions{Required: opts.Required, Description: desc, Error: st.Error(name)}, f.horizontal, func() *ui.Element {
|
||||||
ctrl = control()
|
ctrl = control()
|
||||||
return ctrl
|
return ctrl
|
||||||
})
|
})
|
||||||
|
|||||||
+19
-6
@@ -20,10 +20,10 @@ type FormFieldOptions struct {
|
|||||||
// FormField labels the element control returns and shows help and error text for it.
|
// FormField labels the element control returns and shows help and error text for it.
|
||||||
func FormField(c *ui.Context, label string, opts FormFieldOptions, control func() *ui.Element) *ui.Element {
|
func FormField(c *ui.Context, label string, opts FormFieldOptions, control func() *ui.Element) *ui.Element {
|
||||||
if !opts.Horizontal {
|
if !opts.Horizontal {
|
||||||
return formFieldBuild(c, label, opts, false, control)
|
return formFieldBuild(c, "", label, opts, false, control)
|
||||||
}
|
}
|
||||||
var f *ui.Element
|
var f *ui.Element
|
||||||
formFieldGrid(c, func() { f = formFieldBuild(c, label, opts, true, control) })
|
formFieldGrid(c, func() { f = formFieldBuild(c, "", label, opts, true, control) })
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,7 +35,8 @@ func formFieldGrid(c *ui.Context, fields func()) *ui.Element {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// formFieldBuild builds the label and the control column; beside makes them two grid cells.
|
// formFieldBuild builds the label and the control column; beside makes them two grid cells.
|
||||||
func formFieldBuild(c *ui.Context, label string, opts FormFieldOptions, beside bool, control func() *ui.Element) *ui.Element {
|
// formFieldBuild keys its cells by key when set, so focus follows a reordered field.
|
||||||
|
func formFieldBuild(c *ui.Context, key, label string, opts FormFieldOptions, beside bool, control func() *ui.Element) *ui.Element {
|
||||||
if label == "" {
|
if label == "" {
|
||||||
panic("mujica: FormField needs a label")
|
panic("mujica: FormField needs a label")
|
||||||
}
|
}
|
||||||
@@ -43,7 +44,11 @@ func formFieldBuild(c *ui.Context, label string, opts FormFieldOptions, beside b
|
|||||||
d := Density(c)
|
d := Density(c)
|
||||||
var head, content, ctrl *ui.Element
|
var head, content, ctrl *ui.Element
|
||||||
body := func() {
|
body := func() {
|
||||||
head = ui.Row(c).Gap(d.Unit()).AlignItems(ui.Center)
|
head = ui.Row(c)
|
||||||
|
if key != "" && beside {
|
||||||
|
head.Key(key + "/label")
|
||||||
|
}
|
||||||
|
head.Gap(d.Unit()).AlignItems(ui.Center)
|
||||||
if beside {
|
if beside {
|
||||||
head.MinHeight(d.ControlHeight()).Justify(ui.End)
|
head.MinHeight(d.ControlHeight()).Justify(ui.End)
|
||||||
}
|
}
|
||||||
@@ -55,7 +60,11 @@ func formFieldBuild(c *ui.Context, label string, opts FormFieldOptions, beside b
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
clicked := head.Clicked()
|
clicked := head.Clicked()
|
||||||
content = ui.Column(c).Gap(d.Unit() * 1.5).MinWidth(0)
|
content = ui.Column(c)
|
||||||
|
if key != "" && beside {
|
||||||
|
content.Key(key + "/control")
|
||||||
|
}
|
||||||
|
content.Gap(d.Unit() * 1.5).MinWidth(0)
|
||||||
content.Children(func() {
|
content.Children(func() {
|
||||||
ctrl = control()
|
ctrl = control()
|
||||||
if ctrl == nil {
|
if ctrl == nil {
|
||||||
@@ -82,5 +91,9 @@ func formFieldBuild(c *ui.Context, label string, opts FormFieldOptions, beside b
|
|||||||
body()
|
body()
|
||||||
return content
|
return content
|
||||||
}
|
}
|
||||||
return ui.Column(c).Gap(d.Unit() * 1.5).Children(body)
|
root := ui.Column(c)
|
||||||
|
if key != "" {
|
||||||
|
root.Key(key)
|
||||||
|
}
|
||||||
|
return root.Gap(d.Unit() * 1.5).Children(body)
|
||||||
}
|
}
|
||||||
+11
-6
@@ -51,12 +51,7 @@ func RadioGroup[T comparable](c *ui.Context, value *T, items []RadioItem[T], opt
|
|||||||
wrap.Children(func() {
|
wrap.Children(func() {
|
||||||
r.Element = ui.RadioGroup(c, func() {
|
r.Element = ui.RadioGroup(c, func() {
|
||||||
for _, it := range items {
|
for _, it := range items {
|
||||||
key := slices.Index(*known, it.Value)
|
if radioGroupItem(c, k, d, value, it, stableKey(known, it.Value)) {
|
||||||
if key < 0 {
|
|
||||||
key = len(*known)
|
|
||||||
*known = append(*known, it.Value)
|
|
||||||
}
|
|
||||||
if radioGroupItem(c, k, d, value, it, key) {
|
|
||||||
r.changed = true
|
r.changed = true
|
||||||
slog.Debug("mujica: radio_group choose", "label", it.Label)
|
slog.Debug("mujica: radio_group choose", "label", it.Label)
|
||||||
}
|
}
|
||||||
@@ -103,3 +98,13 @@ func radioGroupItem[T comparable](c *ui.Context, k theme.Tokens, d theme.Density
|
|||||||
})
|
})
|
||||||
return row.Changed()
|
return row.Changed()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// stableKey keys v by its first appearance in *known, so equal-looking values stay apart.
|
||||||
|
func stableKey[T comparable](known *[]T, v T) int {
|
||||||
|
i := slices.Index(*known, v)
|
||||||
|
if i < 0 {
|
||||||
|
i = len(*known)
|
||||||
|
*known = append(*known, v)
|
||||||
|
}
|
||||||
|
return i
|
||||||
|
}
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
package mujica
|
||||||
|
|
||||||
|
import (
|
||||||
|
"slices"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/egoist/mygo/ui"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestFormFocusFollowsFieldAfterReorder(t *testing.T) {
|
||||||
|
var st FormState
|
||||||
|
first, second := "", ""
|
||||||
|
swapped := false
|
||||||
|
tt := ui.NewTester(func(c *ui.Context) {
|
||||||
|
Use(c, Settings{})
|
||||||
|
Form(c, &st, FormOptions{}, func(f *FormScope) {
|
||||||
|
fields := []func(){
|
||||||
|
func() {
|
||||||
|
FormItem(c, f, "first", &first, FormItemOptions[string]{Label: "First"}, func() *ui.Element {
|
||||||
|
return TextInput(c, &first, TextInputOptions{Label: "First"}).Input
|
||||||
|
})
|
||||||
|
},
|
||||||
|
func() {
|
||||||
|
FormItem(c, f, "second", &second, FormItemOptions[string]{Label: "Second"}, func() *ui.Element {
|
||||||
|
return TextInput(c, &second, TextInputOptions{Label: "Second"}).Input
|
||||||
|
})
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if swapped {
|
||||||
|
slices.Reverse(fields)
|
||||||
|
}
|
||||||
|
for _, fn := range fields {
|
||||||
|
fn()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}, 500, 400)
|
||||||
|
if err := tt.Click("First"); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
tt.Type("a")
|
||||||
|
swapped = true
|
||||||
|
tt.Frame()
|
||||||
|
tt.Type("b")
|
||||||
|
if first != "ab" || second != "" {
|
||||||
|
t.Fatalf("first %q second %q, want typing to stay in First", first, second)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestToggleGroupFocusFollowsValueAfterReorder(t *testing.T) {
|
||||||
|
var on []string
|
||||||
|
items := []ToggleItem[string]{{Value: "left", Label: "Left"}, {Value: "right", Label: "Right"}}
|
||||||
|
tt := ui.NewTester(func(c *ui.Context) {
|
||||||
|
Use(c, Settings{})
|
||||||
|
ToggleGroup(c, &on, items, ToggleGroupOptions{Multiple: true, Label: "Align"})
|
||||||
|
}, 400, 200)
|
||||||
|
tt.Key(0, ui.KeyTab)
|
||||||
|
slices.Reverse(items)
|
||||||
|
tt.Frame()
|
||||||
|
tt.Key(0, ui.KeySpace)
|
||||||
|
if !slices.Equal(on, []string{"left"}) {
|
||||||
|
t.Fatalf("pressed %v, want [left]", on)
|
||||||
|
}
|
||||||
|
}
|
||||||
+11
-7
@@ -59,17 +59,21 @@ func ToggleGroup[T comparable](c *ui.Context, value *[]T, items []ToggleItem[T],
|
|||||||
}
|
}
|
||||||
g.Dividers(theme.BorderWidth, k.ControlBorder)
|
g.Dividers(theme.BorderWidth, k.ControlBorder)
|
||||||
changed := false
|
changed := false
|
||||||
|
known := ui.Local(g, "values", func() []T { return nil })
|
||||||
g.Children(func() {
|
g.Children(func() {
|
||||||
for _, it := range items {
|
for _, it := range items {
|
||||||
on := slices.Contains(*value, it.Value)
|
on := slices.Contains(*value, it.Value)
|
||||||
pressed := on
|
pressed := on
|
||||||
b := ui.ToggleBase(c, &pressed).Disabled(it.Disabled)
|
// Keyed by value so focus follows the item, not its position.
|
||||||
// The base took input before Disabled applied: drop a disabled item's press.
|
ui.Box(c).Key(stableKey(known, it.Value)).Children(func() {
|
||||||
if b.Changed() && !it.Disabled && !opts.Disabled && toggleGroupApply(value, it.Value, pressed, opts) {
|
b := ui.ToggleBase(c, &pressed).Disabled(it.Disabled)
|
||||||
changed = true
|
// The base took input before Disabled applied: drop a disabled item's press.
|
||||||
on = pressed
|
if b.Changed() && !it.Disabled && !opts.Disabled && toggleGroupApply(value, it.Value, pressed, opts) {
|
||||||
}
|
changed = true
|
||||||
toggleGroupLook(c, k, b, on, it)
|
on = pressed
|
||||||
|
}
|
||||||
|
toggleGroupLook(c, k, b, on, it)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if changed {
|
if changed {
|
||||||
|
|||||||
Reference in new issue
Block a user