class: DSVColumnView
authorca
Mon, 23 Sep 2013 14:54:54 +0200
changeset 4415 474bed6d8e60
parent 4414 3ec865b931a3
child 4416 ebb04dca4484
class: DSVColumnView changed: #fitColumns #preferredExtent
DSVColumnView.st
--- a/DSVColumnView.st	Mon Sep 23 14:54:37 2013 +0200
+++ b/DSVColumnView.st	Mon Sep 23 14:54:54 2013 +0200
@@ -3339,7 +3339,7 @@
     "fit columns to view; "
 
     |selectedColumn columnsWithRelativeWidth 
-     overallMinWidth restWidth anyChange dX sz oldOrgX newOrgX oldWidth|
+     overallMinWidth restWidth anyChange oldOrgX newOrgX oldWidth|
 
     realized ifFalse:[
         needFitColumns := true.
@@ -3364,22 +3364,41 @@
         aCol canResize ifTrue:[
             anyChange := true.
             aCol invalidate.
-            aCol hasRelativeWidth ifFalse:[columnsWithRelativeWidth add:aCol].
         ].
+        aCol hasRelativeWidth ifTrue:[columnsWithRelativeWidth add:aCol].
         overallMinWidth := overallMinWidth + aCol minWidth.
     ].
+
     cachedPreferredExtent := width @(self preferredHeight).
     restWidth := self innerWidth - overallMinWidth.
 
     (columnsWithRelativeWidth notEmpty and:[restWidth > 0]) ifTrue:[
-        "/ distribute restwidth among remaining columns (cg: is this a good idea)
-        sz := columnsWithRelativeWidth size.
-        restWidth >= sz ifTrue:[
-            dX := restWidth // sz.
-            columnsWithRelativeWidth do:[:aCol|aCol growWidth:dX].
-            restWidth := restWidth - (dX * sz).
+        |sumOfAnnouncedRelativeWidths sumWeach|
+
+        "/ distribute restwidth among remaining columns according to
+        "/ their announced relative width's
+        sumOfAnnouncedRelativeWidths := columnsWithRelativeWidth sum:[:each | each description width].
+        sumWeach := 0.
+        columnsWithRelativeWidth do:[:each |
+            |eachRel wEach|
+
+            eachRel := each description width / sumOfAnnouncedRelativeWidths.
+            each == columnsWithRelativeWidth last ifTrue:[
+                wEach := restWidth - sumWeach.
+            ] ifFalse:[
+                wEach := (eachRel * restWidth) truncated.
+                sumWeach := sumWeach + wEach.
+            ].
+            each setWidth:wEach.
         ].
-        restWidth ~~ 0 ifTrue:[columnsWithRelativeWidth last growWidth:restWidth].
+
+"/        sz := columnsWithRelativeWidth size.
+"/        restWidth >= sz ifTrue:[
+"/            dX := restWidth // sz.
+"/            columnsWithRelativeWidth do:[:aCol|aCol growWidth:dX].
+"/            restWidth := restWidth - (dX * sz).
+"/        ].
+"/        restWidth ~~ 0 ifTrue:[columnsWithRelativeWidth last growWidth:restWidth].
     ].
 
     shown ifTrue:[
@@ -3426,8 +3445,6 @@
             self contentsChanged.
         ].
     ].
-
-    "Modified: / 07-01-2012 / 16:55:58 / cg"
 !
 
 hasSelectables
@@ -3598,7 +3615,7 @@
 
 preferredExtent
     "return my preferred extent"
-    
+
     |numRows prefWidth prefHeight|
 
     "/ If I have an explicit preferredExtent..
@@ -3616,9 +3633,10 @@
     ].
     "/ cg: ????? why 3
     prefWidth := 3.
+    prefWidth := columnDescriptors size - 1.  "/ for the separators
     columnDescriptors do:[:aCol | 
         minRowHeight := (aCol heightOfHighestRow) max:minRowHeight.
-        prefWidth := prefWidth + (aCol minWidth).
+        prefWidth := prefWidth + (aCol minWidth max:5).
     ].
 "/    rowHeight := (minRowHeight + separatorSize + verticalSpacing 
 "/                + verticalSpacing + 1) 
@@ -4727,10 +4745,10 @@
 !DSVColumnView class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/DSVColumnView.st,v 1.287 2013-08-31 23:44:37 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/DSVColumnView.st,v 1.288 2013-09-23 12:54:54 ca Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libwidg2/DSVColumnView.st,v 1.287 2013-08-31 23:44:37 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/DSVColumnView.st,v 1.288 2013-09-23 12:54:54 ca Exp $'
 ! !