All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paul Mackerras <paulus@samba.org>
To: Mark Ventimiglia <Mark.Ventimiglia@hotmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] gitk: Improve readability of highlighted text
Date: Sun, 17 May 2015 14:21:55 +1000	[thread overview]
Message-ID: <20150517042155.GD21039@iris.ozlabs.ibm.com> (raw)
In-Reply-To: <BLU436-SMTP165FCB03C8F3B79226DB3F093080@phx.gbl>

On Thu, Mar 26, 2015 at 12:48:45AM -0500, Mark Ventimiglia wrote:
> 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

> +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.

      reply	other threads:[~2015-05-17  4:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-26  5:48 [PATCH] gitk: Improve readability of highlighted text Mark Ventimiglia
2015-05-17  4:21 ` Paul Mackerras [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150517042155.GD21039@iris.ozlabs.ibm.com \
    --to=paulus@samba.org \
    --cc=Mark.Ventimiglia@hotmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.