gitk: Improve appearance of radiobuttons and checkbuttons
Commit 5497f7a23ac11f9b230892220d5ed80263eedd1f ("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 <paulus@samba.org>
Paul Mackerras committed
Nov 14, 2009 at 21:15 UTC
51a7e8b654a0f06dde6f66ae89a35297cea09168
1 file changed
+12
-2
gitk
+12
-2
@@ -10596,8 +10596,18 @@ proc setselbg {c} {
10596
allcanvs itemconf secsel -fill $c
10597
}
10598
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.
10604
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
10611
}
10612
10613
proc setbg {c} {
@@ -11159,7 +11169,7 @@ eval font create textfontbold [fontflags textfont 1]
11169
parsefont uifont $uifont
11170
eval font create uifont [fontflags uifont]
11171
11162
-tk_setPalette $uicolor
11172
+setui $uicolor
11173
11174
setoptions
11175