"
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.
"
PanelView subclass:#VerticalPanelView
instanceVariableNames:''
classVariableNames:''
poolDictionaries:''
category:'Views-Layout'
!
VerticalPanelView comment:'
COPYRIGHT (c) 1989 by Claus Gittinger
All Rights Reserved
$Header: /cvs/stx/stx/libwidg/VerticalPanelView.st,v 1.4 1994-08-07 13:23:33 claus Exp $
'!
!VerticalPanelView 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/VerticalPanelView.st,v 1.4 1994-08-07 13:23:33 claus Exp $
"
!
documentation
"
a View which arranges its child-views in a vertical column.
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 := VerticalPanelView 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:100 @ 300.
v open
example: left-layout
|v p b1 b2 b3|
v := StandardSystemView new.
p := VerticalPanelView in:v.
p layout:#top.
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:100 @ 300.
v open
example: right-layout
|v p b1 b2 b3|
v := StandardSystemView new.
p := VerticalPanelView in:v.
p layout:#bottom.
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:100 @ 300.
v open
example: spread-layout
|v p b1 b2 b3|
v := StandardSystemView new.
p := VerticalPanelView 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:100 @ 300.
v open
"
! !
!VerticalPanelView methodsFor:'queries'!
preferedExtent
"return a good extent, one that makes subviews fit"
|sumOfHeights maxWidth|
subViews isNil ifTrue:[^ horizontalSpace @ verticalSpace].
"compute net height needed"
sumOfHeights := 0.
maxWidth := 0.
subViews do:[:child |
sumOfHeights := sumOfHeights + child heightIncludingBorder.
maxWidth := maxWidth max:(child widthIncludingBorder)
].
borderWidth ~~ 0 ifTrue:[
sumOfHeights := sumOfHeights + (horizontalSpace * 2).
maxWidth := maxWidth + (horizontalSpace * 2).
].
sumOfHeights := sumOfHeights + ((subViews size - 1) * verticalSpace).
^ maxWidth @ sumOfHeights
! !
!VerticalPanelView methodsFor:'layout'!
setChildPositions
"(re)compute position of every child"
|xpos ypos space sumOfHeights numChilds l|
subViews isNil ifTrue:[^ self].
space := verticalSpace.
"compute net height needed"
sumOfHeights := subViews inject:0 into:[:sumSoFar :child | sumSoFar + child heightIncludingBorder].
numChilds := subViews size.
l := layout.
((l == #center) and:[numChilds == 1]) ifTrue:[
l := #spread
].
"compute position of topmost subview and space between them;
if they do hardly fit, leave no space between them "
(sumOfHeights >= (height - (margin * 2))) ifTrue:[
ypos := 0.
space := 0
] ifFalse:[
(l == #bottom) ifTrue:[
ypos := height - (space * numChilds) - sumOfHeights.
"
borderWidth == 0 ifTrue:[
ypos := ypos + space
].
"
ypos < 0 ifTrue:[
space := space min:(height - sumOfHeights) // (numChilds + 1).
ypos := height - (space * numChilds) - sumOfHeights.
]
] ifFalse: [
(l == #spread) ifTrue:[
space := (height - sumOfHeights) // (numChilds + 1).
ypos := space.
(space == 0) ifTrue:[
ypos := (height - sumOfHeights) // 2
]
] ifFalse: [
(l == #center) ifTrue:[
ypos := (height - (sumOfHeights
+ ((numChilds - 1) * space))) // 2.
ypos < 0 ifTrue:[
space := (height - sumOfHeights) // (numChilds + 1).
ypos := (height - (sumOfHeights
+ ((numChilds - 1) * space))) // 2.
]
] ifFalse:[
"
borderWidth == 0 ifTrue:[
ypos := 0
] ifFalse:[
ypos := verticalSpace
].
"
space := space min:(height - sumOfHeights) // (numChilds + 1).
ypos := space.
]
]
]
].
"now set positions"
subViews do:[:childView |
xpos := (width - childView widthIncludingBorder) // 2.
(xpos < 0) ifTrue:[ xpos := 0 ].
childView origin:(xpos@ypos).
ypos := ypos + (childView heightIncludingBorder) + space
]
! !