From 2e5c4dcb67f3783d83bac8da7155fefc82a6af19 Mon Sep 17 00:00:00 2001 From: tannevaled Date: Wed, 18 Nov 2026 22:18:13 +0100 Subject: [PATCH] Chip: a pill with no text is not drawn Co-Authored-By: Claude Sonnet 5.5 --- chip.go | 5 +++++ slate_widgets_test.go | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/chip.go b/chip.go index d9ac730..1509073 100644 --- a/chip.go +++ b/chip.go @@ -101,6 +101,11 @@ func (c *Chip) Draw(p painter.Painter, theme *Theme) { } c.SetBounds(r) } + if c.Text == "" && c.Style != ChipDefault { + // A pill with nothing in it is not drawn: a row of fixed chip slots + // bound to counts shows only the slots that have one. + return + } ink := theme.OnSurface closeInk := theme.Border switch c.Style { diff --git a/slate_widgets_test.go b/slate_widgets_test.go index 101e283..96c6eb7 100644 --- a/slate_widgets_test.go +++ b/slate_widgets_test.go @@ -117,6 +117,18 @@ func TestChipStyles(t *testing.T) { if themeChipBg(bare, ChipBrand) != blendRGBA(bare.Accent, bare.Surface, 0.10) || themeChipInk(bare, ChipBrand) != bare.Accent { t.Error("brand chip fallback") } + // An empty pill is not drawn at all; an empty default chip still is. + for _, st := range []ChipStyle{ChipPlain, ChipBrand} { + e := NewChip("") + e.Style = st + e.SetBounds(Rect{X: 2, Y: 2, W: 60, H: 16}) + surf := make([]byte, w*h*4) + fillRect(newP(surf, w), 0, 0, w, h, light.Surface) + e.Draw(newP(surf, w), light) + if pixelAt(surf, w, 30, 4) != light.Surface { + t.Errorf("style %d: an empty pill was drawn", st) + } + } // A closable pill draws its x in the chip's ink. cc := NewClosableChip("ok", nil) cc.Style = ChipBrand