[PATCH] gitk: Fix units in resize logic

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



`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@xxxxxxx>
---
 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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]