Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions chip.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 12 additions & 0 deletions slate_widgets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading