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
3 changes: 3 additions & 0 deletions toggle.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ func (t *ToggleButton) Draw(p painter.Painter, theme *Theme) {
face = theme.SurfaceAlt
}
ink, border := theme.OnSurface, theme.Border
if t.Pressed().Get() {
ink = accentInk(theme) // the label on the accent face, not OnSurface (dark on dark in a light theme)
}
if t.Disabled().Get() {
face, ink, border = mutedFace(theme), mutedInk(theme), mutedInk(theme)
}
Expand Down
38 changes: 38 additions & 0 deletions toggle_ink_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) 2026 the go-widgets/toolkit authors. All rights reserved.
// Use of this source code is governed by a BSD-3-Clause license that can be
// found in the LICENSE file at the root of this repository.

package toolkit

import "testing"

// A pressed ToggleButton's label sits on the accent face: it is drawn in the
// accent ink, not OnSurface, which is dark on dark in a light theme.
func TestPressedToggleLabelContrastsWithTheAccentFace(t *testing.T) {
for name, th := range popupThemes() {
tb := NewToggleButton("Minimap", true)
tb.SetBounds(Rect{W: 90, H: 28})
buf := makeSurface(90, 28)
tb.Draw(newP(buf, 90), th)
face := pixelAt(buf, 90, 3, 3)
if face != th.Accent {
t.Fatalf("%s: pressed face = %v, want Accent", name, face)
}
ink := accentInk(th)
found := false
for y := 0; y < 28 && !found; y++ {
for x := 0; x < 90; x++ {
if pixelAt(buf, 90, x, y) == ink {
found = true
break
}
}
}
if !found {
t.Errorf("%s: the label was not drawn in the accent ink %v", name, ink)
}
if r := contrastRatio(ink, th.Accent); r < 3 {
t.Errorf("%s: label vs accent face = %.2f:1, want >= 3:1", name, r)
}
}
}
Loading