From: Nelson Elhage <nelhage@MIT.EDU>
To: git@vger.kernel.org
Cc: Nelson Elhage <nelhage@mit.edu>
Subject: [PATCH] gitk: Fix units in resize logic
Date: Wed, 15 Jul 2009 22:12:23 -0400 [thread overview]
Message-ID: <1247710343-19096-1-git-send-email-nelhage@mit.edu> (raw)
`resizeclistpanes' and `resizedetpanes' both contain logic that
clearly means to work in terms of columns of text, but are using APIs
that return pixels. Scale their inputs and outputs by $charspc
appropriately, resulting in much saner resize behavior.
In addition, keep the widths as floats through intermediate
calculations, which is necessary for smooth resizing behavior now that
we are working in columns.
Signed-off-by: Nelson Elhage <nelhage@mit.edu>
---
gitk-git/gitk | 28 +++++++++++++++-------------
1 files changed, 15 insertions(+), 13 deletions(-)
diff --git a/gitk-git/gitk b/gitk-git/gitk
index 4604c83..29e9442 100644
--- a/gitk-git/gitk
+++ b/gitk-git/gitk
@@ -2575,17 +2575,18 @@ proc savestuff {w} {
}
proc resizeclistpanes {win w} {
- global oldwidth
+ global oldwidth charspc
if {[info exists oldwidth($win)]} {
set s0 [$win sash coord 0]
set s1 [$win sash coord 1]
+ set w [expr {1.0 * $w / $charspc}]
if {$w < 60} {
- set sash0 [expr {int($w/2 - 2)}]
- set sash1 [expr {int($w*5/6 - 2)}]
+ set sash0 [expr {$w/2 - 2}]
+ set sash1 [expr {$w*5/6 - 2}]
} else {
- set factor [expr {1.0 * $w / $oldwidth($win)}]
- set sash0 [expr {int($factor * [lindex $s0 0])}]
- set sash1 [expr {int($factor * [lindex $s1 0])}]
+ set factor [expr {$w / $oldwidth($win)}]
+ set sash0 [expr {$factor * [lindex $s0 0] / $charspc}]
+ set sash1 [expr {$factor * [lindex $s1 0] / $charspc}]
if {$sash0 < 30} {
set sash0 30
}
@@ -2599,21 +2600,22 @@ proc resizeclistpanes {win w} {
}
}
}
- $win sash place 0 $sash0 [lindex $s0 1]
- $win sash place 1 $sash1 [lindex $s1 1]
+ $win sash place 0 [expr {int($charspc * $sash0)}] [lindex $s0 1]
+ $win sash place 1 [expr {int($charspc * $sash1)}] [lindex $s1 1]
}
set oldwidth($win) $w
}
proc resizecdetpanes {win w} {
- global oldwidth
+ global oldwidth charspc
if {[info exists oldwidth($win)]} {
set s0 [$win sash coord 0]
+ set w [expr {1.0 * $w / $charspc}]
if {$w < 60} {
- set sash0 [expr {int($w*3/4 - 2)}]
+ set sash0 [expr {$w*3/4 - 2}]
} else {
- set factor [expr {1.0 * $w / $oldwidth($win)}]
- set sash0 [expr {int($factor * [lindex $s0 0])}]
+ set factor [expr {$w / $oldwidth($win)}]
+ set sash0 [expr {$factor * [lindex $s0 0] / $charspc}]
if {$sash0 < 45} {
set sash0 45
}
@@ -2621,7 +2623,7 @@ proc resizecdetpanes {win w} {
set sash0 [expr {$w - 15}]
}
}
- $win sash place 0 $sash0 [lindex $s0 1]
+ $win sash place 0 [expr {int($charspc * $sash0)}] [lindex $s0 1]
}
set oldwidth($win) $w
}
--
1.6.3.3
reply other threads:[~2009-07-16 2:12 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=1247710343-19096-1-git-send-email-nelhage@mit.edu \
--to=nelhage@mit.edu \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).