git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] gitk: Improve readability of highlighted text

From
Paul Mackerras <paulus@samba.org>
Date
May 17, 2015, 04:21 UTC
Message-ID
<20150517042155.GD21039@iris.ozlabs.ibm.com>
In-Reply-To
<BLU436-SMTP165FCB03C8F3B79226DB3F093080@phx.gbl>
On Thu, Mar 26, 2015 at 12:48:45AM -0500, Mark Ventimiglia wrote:
Show 11 quoted lines
> Selected text is indicated by displaying a rectangle under the selected
> text. When the default background color of dark blue is used for the
> selection rectangle, it does not have sufficient contrast with the default
> text color of black, and the highlighted text cannot be read easily.
> 
> To fix this, determine the HSV value of the selection background color.
> Then, set the color of the selected text based on that value -- white if
> the value is less than 0.6, black otherwise. This ensures that there is
> sufficent contrast to make the text readable over the background color.
> Also tag all selected text with secseltext, so that it can be reverted to
> the default color on a change of selection.
Finally got back to looking at this again...
> +    foreach t [$canv find withtag secseltext] {
> +	$canv itemconf $t -fill $fgcolor
> +	$canv dtag $t secseltext
> +    }
Why not just:
	$canv itemconf secseltext -fill $fgcolor
	$canv dtag secseltext
Show 7 quoted lines
> +proc getseltextcolor {c} {
> +    # Get the largest RGB value -- this is the V in HSV
> +    set value [lindex [lsort -integer [winfo rgb . $c]] end]
> +
> +    # If the normalized value is darker than 0.6 use white text,
> +    # otherwise use black text
> +    return [expr ($value < (65535 * .6))?"white":"black"]

The HSV value doesn't correlate very well with perceived lightness, and this will use black text when the background is R=0 G=0 B=153, which is very hard to read. It would probably be better to use a weighted sum of R, G and B, maybe something like 0.3R + 0.6G + 0.1B.

Paul.
Previous: Mark Ventimiglia
Message 2 of 2 in “gitk: Improve readability of highlighted text”
  1. gitk: Improve readability of highlighted textMark Ventimiglia, Mar 26, 2015
  2. Paul MackerrasMay 17, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.