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

[PATCH] gitk: Fix units in resize logic

From
Nelson Elhage <nelhage@mit.edu>
Date
Jul 16, 2009, 02:12 UTC
Message-ID
<1247710343-19096-1-git-send-email-nelhage@mit.edu>

`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
Message 1 of 1 in “gitk: Fix units in resize logic”
  1. gitk: Fix units in resize logicNelson Elhage, Jul 16, 2009

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.