From 9006056a15f7b769a4271eb9fdb34b6f5ccb53cd Mon Sep 17 00:00:00 2001 From: R0ck Date: Sun, 25 Oct 2026 01:09:27 +0000 Subject: [PATCH 1/2] nodes panel: draw the filter once Closes #770. --- CHANGELOG.md | 3 +++ internal/ui/comp/buttonfloor_test.go | 20 ++++++++++++++++++++ internal/ui/comp/table.go | 6 +++++- internal/ui/comp/tablerows.go | 8 ++++++++ internal/ui/workbench/nodeview/nodespanel.go | 1 + 5 files changed, 37 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a38e02b4..950b6ac2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,9 @@ had changed in them - which is the gap this file exists to close. ### Fixed +- **The Nodes panel shows its filter once.** The panel drew the table's + filter in its own box and the table drew it again underneath, so typing + showed the text twice with two carets. - **Adding a scheduled send no longer repeats the ones already said.** Any `schedule.add` made every one-shot send whose moment had passed go out again. diff --git a/internal/ui/comp/buttonfloor_test.go b/internal/ui/comp/buttonfloor_test.go index c3f9835f..ab55ac1a 100644 --- a/internal/ui/comp/buttonfloor_test.go +++ b/internal/ui/comp/buttonfloor_test.go @@ -37,3 +37,23 @@ func TestAButtonNeverMeasuresZero(t *testing.T) { } } } + +// A table whose caller draws the filter does not draw it again: one editor +// laid out twice is two boxes with the same text and two carets (#770). +func TestATableDoesNotDrawAFilterItsCallerOwns(t *testing.T) { + th := theme.New(theme.Dark, theme.Default, + text.NewShaper(text.WithCollection(brandfont.Collection()))) + gtx := layout.Context{ + Ops: new(op.Ops), + Metric: unit.Metric{PxPerDp: 1, PxPerSp: 1}, + Constraints: layout.Constraints{Max: image.Pt(400, 100)}, + } + tb := &Table{} + if d := tb.searchRow(th, gtx); d.Size.Y == 0 { + t.Fatal("a table with its own search drew no search box") + } + tb.OwnFilter = true + if d := tb.searchRow(th, gtx); d.Size.Y != 0 { + t.Errorf("the table drew the caller's filter again, %d px tall", d.Size.Y) + } +} diff --git a/internal/ui/comp/table.go b/internal/ui/comp/table.go index 923aab45..741e1a62 100644 --- a/internal/ui/comp/table.go +++ b/internal/ui/comp/table.go @@ -65,6 +65,10 @@ type Table struct { SortDesc bool // FilterHint is what the search box says when it is empty. FilterHint string + // OwnFilter is set by a caller that draws Filter in a box of its own, so + // the table does not draw it again: one editor laid out twice is two boxes + // showing the same text, each with a caret (#770). + OwnFilter bool // OnCell is called when a Menu column's cell is clicked, with the row's // key and the column index. OnCell func(key string, col int) @@ -164,7 +168,7 @@ func (tb *Table) Layout(t *theme.Theme, gtx layout.Context, onSelect func(key st // drew. The filtering worked; there was simply no way to type into it, // so every table in the interface looked as though it had no search. layout.Rigid(func(gtx layout.Context) layout.Dimensions { - return tb.search(t, gtx) + return tb.searchRow(t, gtx) }), layout.Rigid(func(gtx layout.Context) layout.Dimensions { return tb.header(t, gtx) }), layout.Rigid(HRule(t)), diff --git a/internal/ui/comp/tablerows.go b/internal/ui/comp/tablerows.go index 41458744..0c805719 100644 --- a/internal/ui/comp/tablerows.go +++ b/internal/ui/comp/tablerows.go @@ -268,6 +268,14 @@ func numericValue(s string) float64 { return v } +// searchRow is the filter box, unless the caller draws it. +func (tb *Table) searchRow(t *theme.Theme, gtx layout.Context) layout.Dimensions { + if tb.OwnFilter { + return layout.Dimensions{} + } + return tb.search(t, gtx) +} + // search is the filter box above the header. // // Its hint says what it matches on rather than "search", because a box that diff --git a/internal/ui/workbench/nodeview/nodespanel.go b/internal/ui/workbench/nodeview/nodespanel.go index 07ae2825..19772283 100644 --- a/internal/ui/workbench/nodeview/nodespanel.go +++ b/internal/ui/workbench/nodeview/nodespanel.go @@ -86,6 +86,7 @@ func (np *Panel) Draw(t *theme.Theme, gtx layout.Context, s *state.Snapshot) lay // The table's own editor, drawn with the field's chrome. One // widget at one address, which is what focus is keyed on. np.filter.Hint = "filter by name or kind" + np.tbl.OwnFilter = true return np.filter.LayoutEditor(t, gtx, &np.tbl.Filter) }), layout.Rigid(layout.Spacer{Height: t.Sp.S}.Layout), From 9d32b1618b7bc6450492359bb4e3e66b1d125cb4 Mon Sep 17 00:00:00 2001 From: R0ck Date: Fri, 30 Oct 2026 17:03:25 +0000 Subject: [PATCH 2/2] Move the table filter test into a file named for it, and drop the ticket number. --- internal/ui/comp/buttonfloor_test.go | 20 ---------------- internal/ui/comp/table.go | 2 +- internal/ui/comp/tablefilter_test.go | 34 ++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 21 deletions(-) create mode 100644 internal/ui/comp/tablefilter_test.go diff --git a/internal/ui/comp/buttonfloor_test.go b/internal/ui/comp/buttonfloor_test.go index ab55ac1a..c3f9835f 100644 --- a/internal/ui/comp/buttonfloor_test.go +++ b/internal/ui/comp/buttonfloor_test.go @@ -37,23 +37,3 @@ func TestAButtonNeverMeasuresZero(t *testing.T) { } } } - -// A table whose caller draws the filter does not draw it again: one editor -// laid out twice is two boxes with the same text and two carets (#770). -func TestATableDoesNotDrawAFilterItsCallerOwns(t *testing.T) { - th := theme.New(theme.Dark, theme.Default, - text.NewShaper(text.WithCollection(brandfont.Collection()))) - gtx := layout.Context{ - Ops: new(op.Ops), - Metric: unit.Metric{PxPerDp: 1, PxPerSp: 1}, - Constraints: layout.Constraints{Max: image.Pt(400, 100)}, - } - tb := &Table{} - if d := tb.searchRow(th, gtx); d.Size.Y == 0 { - t.Fatal("a table with its own search drew no search box") - } - tb.OwnFilter = true - if d := tb.searchRow(th, gtx); d.Size.Y != 0 { - t.Errorf("the table drew the caller's filter again, %d px tall", d.Size.Y) - } -} diff --git a/internal/ui/comp/table.go b/internal/ui/comp/table.go index 741e1a62..1bc83b3d 100644 --- a/internal/ui/comp/table.go +++ b/internal/ui/comp/table.go @@ -67,7 +67,7 @@ type Table struct { FilterHint string // OwnFilter is set by a caller that draws Filter in a box of its own, so // the table does not draw it again: one editor laid out twice is two boxes - // showing the same text, each with a caret (#770). + // showing the same text, each with a caret. OwnFilter bool // OnCell is called when a Menu column's cell is clicked, with the row's // key and the column index. diff --git a/internal/ui/comp/tablefilter_test.go b/internal/ui/comp/tablefilter_test.go new file mode 100644 index 00000000..a086e6e6 --- /dev/null +++ b/internal/ui/comp/tablefilter_test.go @@ -0,0 +1,34 @@ +package comp + +import ( + "image" + "testing" + + "gioui.org/layout" + "gioui.org/op" + "gioui.org/text" + "gioui.org/unit" + + "github.com/MeshBench/meshbench/internal/ui/theme" + "github.com/MeshBench/meshbench/internal/ui/theme/brandfont" +) + +// A table whose caller draws the filter does not draw it again: one editor +// laid out twice is two boxes with the same text and two carets. +func TestATableDoesNotDrawAFilterItsCallerOwns(t *testing.T) { + th := theme.New(theme.Dark, theme.Default, + text.NewShaper(text.WithCollection(brandfont.Collection()))) + gtx := layout.Context{ + Ops: new(op.Ops), + Metric: unit.Metric{PxPerDp: 1, PxPerSp: 1}, + Constraints: layout.Constraints{Max: image.Pt(400, 100)}, + } + tb := &Table{} + if d := tb.searchRow(th, gtx); d.Size.Y == 0 { + t.Fatal("a table with its own search drew no search box") + } + tb.OwnFilter = true + if d := tb.searchRow(th, gtx); d.Size.Y != 0 { + t.Errorf("the table drew the caller's filter again, %d px tall", d.Size.Y) + } +}