Skip to content

Commit 51a7e8b

Browse files
committed
gitk: Improve appearance of radiobuttons and checkbuttons
Commit 5497f7a ("gitk: Add configuration for UI colour scheme") added a call to tk_setPalette at startup. Unfortunately, tk_setPalette always chooses a dark red color for the selectColor value if none is given explicitly, and this makes checkbuttons and radiobuttons look rather bad. This restores the previous appearance by specifying selectColor explicitly. For light backgrounds we use white for selectColor, and for dark backgrounds we use black. The formula and threshold for distinguishing light from dark are the same as used in tk_setPalette for choosing the foreground color. Signed-off-by: Paul Mackerras <[email protected]>
1 parent 8d84995 commit 51a7e8b

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

gitk

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10596,8 +10596,18 @@ proc setselbg {c} {
1059610596
allcanvs itemconf secsel -fill $c
1059710597
}
1059810598

10599+
# This sets the background color and the color scheme for the whole UI.
10600+
# For some reason, tk_setPalette chooses a nasty dark red for selectColor
10601+
# if we don't specify one ourselves, which makes the checkbuttons and
10602+
# radiobuttons look bad. This chooses white for selectColor if the
10603+
# background color is light, or black if it is dark.
1059910604
proc setui {c} {
10600-
tk_setPalette $c
10605+
set bg [winfo rgb . $c]
10606+
set selc black
10607+
if {[lindex $bg 0] + 1.5 * [lindex $bg 1] + 0.5 * [lindex $bg 2] > 100000} {
10608+
set selc white
10609+
}
10610+
tk_setPalette background $c selectColor $selc
1060110611
}
1060210612

1060310613
proc setbg {c} {
@@ -11159,7 +11169,7 @@ eval font create textfontbold [fontflags textfont 1]
1115911169
parsefont uifont $uifont
1116011170
eval font create uifont [fontflags uifont]
1116111171

11162-
tk_setPalette $uicolor
11172+
setui $uicolor
1116311173

1116411174
setoptions
1116511175

0 commit comments

Comments
 (0)