HorizontalPanelView.st
changeset 38 4b9b70b2cc87
parent 5 7b4fb1b170e5
child 59 450ce95a72a4
--- a/HorizontalPanelView.st	Sun Aug 07 15:22:53 1994 +0200
+++ b/HorizontalPanelView.st	Sun Aug 07 15:23:42 1994 +0200
@@ -18,17 +18,99 @@
 !
 
 HorizontalPanelView comment:'
-
 COPYRIGHT (c) 1989 by Claus Gittinger
               All Rights Reserved
 
-a View for childViews oriented horizontal
-all real work is done in PanelView - just redefine layout
+$Header: /cvs/stx/stx/libwidg/HorizontalPanelView.st,v 1.4 1994-08-07 13:22:03 claus Exp $
+'!
+
+!HorizontalPanelView class methodsFor:'documentation'!
+
+copyright
+"
+ COPYRIGHT (c) 1989 by Claus Gittinger
+              All Rights Reserved
+
+ This software is furnished under a license and may be used
+ only in accordance with the terms of that license and with the
+ inclusion of the above copyright notice.   This software may not
+ be provided or otherwise made available to, or used by, any
+ other person.  No title to or ownership of the software is
+ hereby transferred.
+"
+!
+
+version
+"
+$Header: /cvs/stx/stx/libwidg/HorizontalPanelView.st,v 1.4 1994-08-07 13:22:03 claus Exp $
+"
+!
+
+documentation
+"
+    a View which arranges its child-views in a horizontal row.
+    All real work is done in PanelView - only the layout computation is
+    redefined here.
+
+    example: default layout (centered)
+
+        |v p b1 b2 b3|
+
+        v := StandardSystemView new.
+        p := HorizontalPanelView in:v.
+        p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
+        b1 := Button label:'button1' in:p.
+        b2 := Button label:'button2' in:p.
+        b3 := Button label:'button3' in:p.
+        v extent:300 @ 100.
+        v open
+
 
-$Header: /cvs/stx/stx/libwidg/HorizontalPanelView.st,v 1.3 1993-10-13 02:47:53 claus Exp $
+    example: left-layout
+
+        |v p b1 b2 b3|
+
+        v := StandardSystemView new.
+        p := HorizontalPanelView in:v.
+        p layout:#left.
+        p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
+        b1 := Button label:'button1' in:p.
+        b2 := Button label:'button2' in:p.
+        b3 := Button label:'button3' in:p.
+        v extent:300 @ 100.
+        v open
+
+
+    example: right-layout
+
+        |v p b1 b2 b3|
 
-written spring/summer 89 by claus
-'!
+        v := StandardSystemView new.
+        p := HorizontalPanelView in:v.
+        p layout:#right.
+        p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
+        b1 := Button label:'button1' in:p.
+        b2 := Button label:'button2' in:p.
+        b3 := Button label:'button3' in:p.
+        v extent:300 @ 100.
+        v open
+
+
+    example: spread-layout
+
+        |v p b1 b2 b3|
+
+        v := StandardSystemView new.
+        p := HorizontalPanelView in:v.
+        p layout:#spread.
+        p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
+        b1 := Button label:'button1' in:p.
+        b2 := Button label:'button2' in:p.
+        b3 := Button label:'button3' in:p.
+        v extent:300 @ 100.
+        v open
+"
+! !
 
 !HorizontalPanelView methodsFor:'queries'!
 
@@ -63,7 +145,7 @@
     "(re)compute position of every child whenever childs are added or
      my size has changed"
 
-    |xpos ypos space sumOfChildWidths numChilds l|
+    |xpos ypos space sumOfWidths numChilds l|
 
     subViews isNil ifTrue:[^ self].
 
@@ -71,11 +153,8 @@
 
     "compute net width needed"
 
-    sumOfChildWidths := 0.
+    sumOfWidths := subViews inject:0 into:[:sumSoFar :child | sumSoFar + child widthIncludingBorder].
     numChilds := subViews size.
-    subViews do:[:child |
-        sumOfChildWidths := sumOfChildWidths + child widthIncludingBorder.
-    ].
 
     l := layout.
     ((l == #center) and:[numChilds == 1]) ifTrue:[
@@ -85,33 +164,46 @@
     "compute position of leftmost subview and space between them;
      if they do hardly fit, leave no space between them "
 
-    (sumOfChildWidths >= width) ifTrue:[
+    (sumOfWidths >= (width - (margin * 2))) ifTrue:[
         xpos := 0.
         space := 0
     ] ifFalse: [
         (l == #right) ifTrue:[
-            xpos := width - (horizontalSpace * numChilds)
-                          - sumOfChildWidths.
+            xpos := width - (space * numChilds) - sumOfWidths.
+"
             borderWidth == 0 ifTrue:[
-                xpos := xpos + horizontalSpace 
+                xpos := xpos + space 
             ].
+"
+            xpos < 0 ifTrue:[
+                space := space min:(width - sumOfWidths) // (numChilds + 1).
+                xpos := width - (space * numChilds) - sumOfWidths.
+            ]
         ] ifFalse:[
             (l == #spread) ifTrue:[
-                space := (width - sumOfChildWidths) // (numChilds + 1).
+                space := (width - sumOfWidths) // (numChilds + 1).
                 xpos := space.
                 (space == 0) ifTrue:[
-                    xpos := (width - sumOfChildWidths) // 2
+                    xpos := (width - sumOfWidths) // 2
                 ]
             ] ifFalse:[
                 (l == #center) ifTrue:[
-                    xpos := (width - (sumOfChildWidths
-                                      + ((numChilds - 1) * space))) // 2
+                    xpos := (width - (sumOfWidths
+                                      + ((numChilds - 1) * space))) // 2.
+                    xpos < 0 ifTrue:[
+                        space := (width - sumOfWidths) // (numChilds + 1).
+                        xpos := (width - (sumOfWidths
+                                       + ((numChilds - 1) * space))) // 2.
+                    ]
                 ] ifFalse:[
+                    "left"
+                    space := space min:(width - sumOfWidths) // (numChilds + 1).
+                    xpos := space.
+"
                     borderWidth == 0 ifTrue:[
                         xpos := 0 
-                    ] ifFalse:[
-                        xpos := horizontalSpace
-                    ]
+                    ].
+"
                 ]
             ]
         ]