{"thread":{"id":"20129","subject":"[PATCH] gitk: Fix units in resize logic","startedAt":"2009-07-16T02:12:23Z","lastAt":"2009-07-16T02:12:23Z","messageCount":1,"participants":["Nelson Elhage"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"118064","messageId":"1247710343-19096-1-git-send-email-nelhage@mit.edu","threadId":"20129","inReplyTo":null,"subject":"[PATCH] gitk: Fix units in resize logic","fromName":"Nelson Elhage","fromEmail":"nelhage@mit.edu","sentAt":"2009-07-16T02:12:23Z","receivedAt":"2009-07-16T02:12:23Z","isPatch":true,"sender":{"key":"nelhage@mit.edu","avatar":"https://avatars.githubusercontent.com/u/16725?v=4"},"body":"`resizeclistpanes' and `resizedetpanes' both contain logic that\nclearly means to work in terms of columns of text, but are using APIs\nthat return pixels. Scale their inputs and outputs by $charspc\nappropriately, resulting in much saner resize behavior.\n\nIn addition, keep the widths as floats through intermediate\ncalculations, which is necessary for smooth resizing behavior now that\nwe are working in columns.\n\nSigned-off-by: Nelson Elhage <nelhage@mit.edu>\n---\n gitk-git/gitk |   28 +++++++++++++++-------------\n 1 files changed, 15 insertions(+), 13 deletions(-)\n\ndiff --git a/gitk-git/gitk b/gitk-git/gitk\nindex 4604c83..29e9442 100644\n--- a/gitk-git/gitk\n+++ b/gitk-git/gitk\n@@ -2575,17 +2575,18 @@ proc savestuff {w} {\n }\n \n proc resizeclistpanes {win w} {\n-    global oldwidth\n+    global oldwidth charspc\n     if {[info exists oldwidth($win)]} {\n \tset s0 [$win sash coord 0]\n \tset s1 [$win sash coord 1]\n+\tset w [expr {1.0 * $w / $charspc}]\n \tif {$w < 60} {\n-\t    set sash0 [expr {int($w/2 - 2)}]\n-\t    set sash1 [expr {int($w*5/6 - 2)}]\n+\t    set sash0 [expr {$w/2 - 2}]\n+\t    set sash1 [expr {$w*5/6 - 2}]\n \t} else {\n-\t    set factor [expr {1.0 * $w / $oldwidth($win)}]\n-\t    set sash0 [expr {int($factor * [lindex $s0 0])}]\n-\t    set sash1 [expr {int($factor * [lindex $s1 0])}]\n+\t    set factor [expr {$w / $oldwidth($win)}]\n+\t    set sash0 [expr {$factor * [lindex $s0 0] / $charspc}]\n+\t    set sash1 [expr {$factor * [lindex $s1 0] / $charspc}]\n \t    if {$sash0 < 30} {\n \t\tset sash0 30\n \t    }\n@@ -2599,21 +2600,22 @@ proc resizeclistpanes {win w} {\n \t\t}\n \t    }\n \t}\n-\t$win sash place 0 $sash0 [lindex $s0 1]\n-\t$win sash place 1 $sash1 [lindex $s1 1]\n+\t$win sash place 0 [expr {int($charspc * $sash0)}] [lindex $s0 1]\n+\t$win sash place 1 [expr {int($charspc * $sash1)}] [lindex $s1 1]\n     }\n     set oldwidth($win) $w\n }\n \n proc resizecdetpanes {win w} {\n-    global oldwidth\n+    global oldwidth charspc\n     if {[info exists oldwidth($win)]} {\n \tset s0 [$win sash coord 0]\n+\tset w [expr {1.0 * $w / $charspc}]\n \tif {$w < 60} {\n-\t    set sash0 [expr {int($w*3/4 - 2)}]\n+\t    set sash0 [expr {$w*3/4 - 2}]\n \t} else {\n-\t    set factor [expr {1.0 * $w / $oldwidth($win)}]\n-\t    set sash0 [expr {int($factor * [lindex $s0 0])}]\n+\t    set factor [expr {$w / $oldwidth($win)}]\n+\t    set sash0 [expr {$factor * [lindex $s0 0] / $charspc}]\n \t    if {$sash0 < 45} {\n \t\tset sash0 45\n \t    }\n@@ -2621,7 +2623,7 @@ proc resizecdetpanes {win w} {\n \t\tset sash0 [expr {$w - 15}]\n \t    }\n \t}\n-\t$win sash place 0 $sash0 [lindex $s0 1]\n+\t$win sash place 0 [expr {int($charspc * $sash0)}] [lindex $s0 1]\n     }\n     set oldwidth($win) $w\n }\n-- \n1.6.3.3\n"}]}