--- a/HorizontalPanelView.st Mon Jul 03 04:34:22 1995 +0200
+++ b/HorizontalPanelView.st Sun Jul 23 05:03:13 1995 +0200
@@ -21,7 +21,7 @@
COPYRIGHT (c) 1989 by Claus Gittinger
All Rights Reserved
-$Header: /cvs/stx/stx/libwidg/HorizontalPanelView.st,v 1.13 1995-06-27 02:23:06 claus Exp $
+$Header: /cvs/stx/stx/libwidg/HorizontalPanelView.st,v 1.14 1995-07-23 03:01:42 claus Exp $
'!
!HorizontalPanelView class methodsFor:'documentation'!
@@ -42,7 +42,7 @@
version
"
-$Header: /cvs/stx/stx/libwidg/HorizontalPanelView.st,v 1.13 1995-06-27 02:23:06 claus Exp $
+$Header: /cvs/stx/stx/libwidg/HorizontalPanelView.st,v 1.14 1995-07-23 03:01:42 claus Exp $
"
!
@@ -57,6 +57,9 @@
in addition to
horizontalSpace and verticalSpace.
+ HorizontalSpace and verticalSpace control the spacing between elements;
+ they default to some 1mm.
+
The horizontal layout can be any of:
#left arrange elements at the left
@@ -68,10 +71,18 @@
#center arrange elements in the center
#spread spread elements evenly
#spreadSpace spread elements evenly with spacing at the ends
- #fit like spread, but resize elements for tight packing
- #fitSpace like fit, with additional spacing at the far ends
- #leftFit like left, but extend the last element to the right
- #leftSpaceFit like leftSpace, but extend the last element to the right
+ #fit like #spread, but resize elements for tight packing
+ #fitSpace like #fit, with additional spacing at the far ends
+ #leftFit like #left, but extend the last element to the right
+ #leftSpaceFit like #leftSpace, but extend the last element to the right
+
+ #leftMax like corresponding non-Max layouts,
+ #leftSpaceMax but resize all components to width of widest components
+ #rightMax
+ #rightSpaceMax
+ #centerMax
+ #spreadMax
+ #spreadSpaceMax
the vertical layout can be:
@@ -81,22 +92,29 @@
#bottom place it at the bottom
#bottomSpace place it at the bottom, offset by verticalSpace
#fit resize elements vertically to fit this panel
- #fitSpace like fit, but with spacing
+ #fitSpace like #fit, but with spacing
+
+ #topMax like #top, but resize all views vertically to max height
+ #topSpaceMax like #topSpace, but resize all views vertically to max height
+ #bottomMax like #bottom, but resize all views vertically to max height
+ #bottomSpaceMax like #bottomSpace, but resize all views vertically to max height
+ #centerMax like #center, but resize all views vertically to max height
The defaults is #center for both directions.
The layout is changed by the messages #verticalLayout: and #horizontalLayout:.
For backward compatibility (to times, where only hLayout existed), the simple
- #layout: does the same as #horizontalLayout:. Do not use this old method.
+ #layout: does the same as #horizontalLayout:.
+ Do not use this old method; it will vanish and currently outpus a warning.
The panel assumes, that the elements do not resize themselfes, after it
became visible. This is not true for all widgets (buttons or labels may
like to change). If you have changing elements, tell this to the panel
with 'aPanel elementsChangeSize:true'. In that case, the panel will react
- to size changes, and reorganize things.
+ to size changes of its elements, and reorganize things.
By combining Horizontal- and VerticalPanels (i.e. place a hPanel into a
vPanel), most layouts should be implementable.
- However, ff none of these layout/space combinations is exactly what you need
+ However, iff none of these layout/space combinations is exactly what you need
in your application, create a subclass, and redefine the setChildPositions
method there.
@@ -104,8 +122,10 @@
#rightFit, #rightSpaceFit layouts
CAVEAT: this class started with #left and no vertical alignments;
- as time went by, more layouts were added and the setup should be changed
- to use different selectors for space, max-resize and alignment
+ as time went by, more layouts were added (by users requests)
+ and noew, many layout combinations are possible.
+ Reflecting this, the setup should be changed to use different selectors
+ for space-on/off, max-resize and alignment
(i.e. having more and more layout symbols makes things a bit confusing ...)
"
!
@@ -138,6 +158,102 @@
v open
+ example: same (default center layout) with different sized elements
+
+ |v p b1 b2 b3|
+
+ v := StandardSystemView new.
+ v label:'default: center'.
+
+ p := HorizontalPanelView in:v.
+ p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
+ b1 := Button label:'but1' in:p. b1 font:(b1 font size:8).
+ b2 := Button label:'b2' in:p. b2 font:(b1 font size:24).
+ b3 := Button label:'button3' in:p.
+ v extent:300 @ 100.
+ v open
+
+
+ example: horizontal default (center); vertical centerMax
+
+ |v p b1 b2 b3|
+
+ v := StandardSystemView new.
+ v label:'vL=centerMax'.
+ p := HorizontalPanelView in:v.
+ p verticalLayout:#centerMax.
+ p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
+ b1 := Button label:'but1' in:p. b1 font:(b1 font size:8).
+ b2 := Button label:'b2' in:p. b2 font:(b1 font size:24).
+ b3 := Button label:'button3' in:p.
+ v extent:300 @ 100.
+ v open
+
+
+ example: horizontal default (center); vertical topMax
+
+ |v p b1 b2 b3|
+
+ v := StandardSystemView new.
+ v label:'vL=topMax'.
+ p := HorizontalPanelView in:v.
+ p verticalLayout:#topMax.
+ p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
+ b1 := Button label:'but1' in:p. b1 font:(b1 font size:8).
+ b2 := Button label:'b2' in:p. b2 font:(b1 font size:24).
+ b3 := Button label:'button3' in:p.
+ v extent:300 @ 100.
+ v open
+
+
+ example: horizontal default (center); vertical topSpaceMax
+
+ |v p b1 b2 b3|
+
+ v := StandardSystemView new.
+ v label:'vL=topSpaceMax'.
+ p := HorizontalPanelView in:v.
+ p verticalLayout:#topSpaceMax.
+ p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
+ b1 := Button label:'but1' in:p. b1 font:(b1 font size:8).
+ b2 := Button label:'b2' in:p. b2 font:(b1 font size:24).
+ b3 := Button label:'button3' in:p.
+ v extent:300 @ 100.
+ v open
+
+
+ example: horizontal default (center); vertical bottomMax
+
+ |v p b1 b2 b3|
+
+ v := StandardSystemView new.
+ v label:'vL=bottomMax'.
+ p := HorizontalPanelView in:v.
+ p verticalLayout:#bottomMax.
+ p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
+ b1 := Button label:'but1' in:p. b1 font:(b1 font size:8).
+ b2 := Button label:'b2' in:p. b2 font:(b1 font size:24).
+ b3 := Button label:'button3' in:p.
+ v extent:300 @ 100.
+ v open
+
+
+ example: horizontal default (center); vertical bottomSpaceMax
+
+ |v p b1 b2 b3|
+
+ v := StandardSystemView new.
+ v label:'vL=bottomSpaceMax'.
+ p := HorizontalPanelView in:v.
+ p verticalLayout:#bottomSpaceMax.
+ p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
+ b1 := Button label:'but1' in:p. b1 font:(b1 font size:8).
+ b2 := Button label:'b2' in:p. b2 font:(b1 font size:24).
+ b3 := Button label:'button3' in:p.
+ v extent:300 @ 100.
+ v open
+
+
example: left-layout (vertical is default -> center)
|v p b1 b2 b3|
@@ -508,6 +624,143 @@
v extent:300 @ 100.
v open
+ example: leftMax - vertical default
+
+ |v p b1 b2 b3|
+
+ v := StandardSystemView new.
+ p := HorizontalPanelView in:v.
+ v label:'hL=leftMax; vL=default'.
+
+ p horizontalLayout:#leftMax.
+ p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
+ b1 := Button label:'button1' in:p.
+ b2 := Button label:'b2' in:p.
+ b3 := Button label:'but3' in:p.
+ v extent:300 @ 100.
+ v open
+
+
+ example: leftSpaceMax - vertical default
+
+ |v p b1 b2 b3|
+
+ v := StandardSystemView new.
+ p := HorizontalPanelView in:v.
+ v label:'hL=leftSpaceMax; vL=default'.
+
+ p horizontalLayout:#leftSpaceMax.
+ p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
+ b1 := Button label:'button1' in:p.
+ b2 := Button label:'b2' in:p.
+ b3 := Button label:'but3' in:p.
+ v extent:300 @ 100.
+ v open
+
+
+ example: rightMax - vertical default
+
+ |v p b1 b2 b3|
+
+ v := StandardSystemView new.
+ p := HorizontalPanelView in:v.
+ v label:'hL=rightMax; vL=default'.
+
+ p horizontalLayout:#rightMax.
+ p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
+ b1 := Button label:'button1' in:p.
+ b2 := Button label:'b2' in:p.
+ b3 := Button label:'but3' in:p.
+ v extent:300 @ 100.
+ v open
+
+
+ example: rightSpaceMax - vertical default
+
+ |v p b1 b2 b3|
+
+ v := StandardSystemView new.
+ p := HorizontalPanelView in:v.
+ v label:'hL=rightSpaceMax; vL=default'.
+
+ p horizontalLayout:#rightSpaceMax.
+ p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
+ b1 := Button label:'button1' in:p.
+ b2 := Button label:'b2' in:p.
+ b3 := Button label:'but3' in:p.
+ v extent:300 @ 100.
+ v open
+
+
+ example: centerMax - vertical default
+
+ |v p b1 b2 b3|
+
+ v := StandardSystemView new.
+ p := HorizontalPanelView in:v.
+ v label:'hL=centerMax; vL=default'.
+
+ p horizontalLayout:#centerMax.
+ p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
+ b1 := Button label:'button1' in:p.
+ b2 := Button label:'b2' in:p.
+ b3 := Button label:'but3' in:p.
+ v extent:300 @ 100.
+ v open
+
+
+ example: spreadMax - vertical default
+
+ |v p b1 b2 b3|
+
+ v := StandardSystemView new.
+ p := HorizontalPanelView in:v.
+ v label:'hL=spreadMax; vL=default'.
+
+ p horizontalLayout:#spreadMax.
+ p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
+ b1 := Button label:'button1' in:p.
+ b2 := Button label:'b2' in:p.
+ b3 := Button label:'but3' in:p.
+ v extent:300 @ 100.
+ v open
+
+
+ example: spreadSpaceMax - vertical default
+
+ |v p b1 b2 b3|
+
+ v := StandardSystemView new.
+ p := HorizontalPanelView in:v.
+ v label:'hL=spreadSpaceMax; vL=default'.
+
+ p horizontalLayout:#spreadSpaceMax.
+ p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
+ b1 := Button label:'button1' in:p.
+ b2 := Button label:'b2' in:p.
+ b3 := Button label:'but3' in:p.
+ v extent:300 @ 100.
+ v open
+
+
+ example: maximize elements in both directions and center
+
+ |v p b1 b2 b3|
+
+ v := StandardSystemView new.
+ v label:'hL=centerMax; vL=centerMax'.
+
+ p := HorizontalPanelView in:v.
+ p horizontalLayout:#centerMax.
+ p verticalLayout:#centerMax.
+ p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
+ b1 := Button label:'but1' in:p. b1 font:(b1 font size:8).
+ b2 := Button label:'b2' in:p. b2 font:(b1 font size:24).
+ b3 := Button label:'button3' in:p.
+ v extent:300 @ 100.
+ v open
+
+
example: placing hPanels into a vPanel
|v vP hP1 hP2 hP3 b1 b2 b3 b4 b5 b6 b7 b8 b9|
@@ -625,15 +878,19 @@
horizontalLayout
"return the horizontal layout as symbol.
the returned value is one of
- #left
- #leftSpace
- #leftFit
- #leftSpaceFit
- #center
- #spread
- #fit
- #right
- #rightSpace
+ #left arrange elements at the left
+ #leftSpace arrange elements at the left, start with spacing
+ #fixLeft same as #left, but do not reduce spacing in case of no fit
+ #fixLeftSpace same as #leftSpace, but do not reduce spacing in case of no fit
+ #right arrange elements at the right
+ #rightSpace arrange elements at the right, start with spacing
+ #center arrange elements in the center
+ #spread spread elements evenly
+ #spreadSpace spread elements evenly with spacing at the ends
+ #fit like #spread, but resize elements for tight packing
+ #fitSpace like #fit, with additional spacing at the far ends
+ #leftFit like #left, but extend the last element to the right
+ #leftSpaceFit like #leftSpace, but extend the last element to the right
the default is #center
See the class documentation for the meanings.
"
@@ -644,10 +901,19 @@
verticalLayout
"return the vertical layout as a symbol.
the returned value is one of
- #top / #topSpace
- #center
- #bottom / #bottomSpace
- #fit
+ #top place element at the top
+ #topSpace place element at the top, offset by verticalSpace
+ #center place it horizontally centered
+ #bottom place it at the bottom
+ #bottomSpace place it at the bottom, offset by verticalSpace
+ #fit resize elements vertically to fit this panel
+ #fitSpace like #fit, but with spacing
+
+ #topMax like #top, but resize all views vertically to max height
+ #topSpaceMax like #topSpace, but resize all views vertically to max height
+ #bottomMax like #bottom, but resize all views vertically to max height
+ #bottomSpaceMax like #bottomSpace, but resize all views vertically to max height
+ #centerMax like #center, but resize all views vertically to max height
the default is #center
See the class documentation for the meanings.
"
@@ -658,12 +924,19 @@
horizontalLayout:aSymbol
"change the horizontal layout as symbol.
The argument, aSymbol must be one of:
- #left / #leftSpace
- #leftFit / #leftSpaceFit
- #center
- #spread / spreadSpace
- #fit / fitSpace
- #right / #rightSpace
+ #left arrange elements at the left
+ #leftSpace arrange elements at the left, start with spacing
+ #fixLeft same as #left, but do not reduce spacing in case of no fit
+ #fixLeftSpace same as #leftSpace, but do not reduce spacing in case of no fit
+ #right arrange elements at the right
+ #rightSpace arrange elements at the right, start with spacing
+ #center arrange elements in the center
+ #spread spread elements evenly
+ #spreadSpace spread elements evenly with spacing at the ends
+ #fit like #spread, but resize elements for tight packing
+ #fitSpace like #fit, with additional spacing at the far ends
+ #leftFit like #left, but extend the last element to the right
+ #leftSpaceFit like #leftSpace, but extend the last element to the right
the default (if never changed) is #center.
See the class documentation for the meanings.
"
@@ -677,10 +950,19 @@
verticalLayout:aSymbol
"change the vertical layout as a symbol.
The argument, aSymbol must be one of:
- #top / #topSpace
- #center
- #bottom / #bottomSpace
- #fit
+ #top place element at the top
+ #topSpace place element at the top, offset by verticalSpace
+ #center place it horizontally centered
+ #bottom place it at the bottom
+ #bottomSpace place it at the bottom, offset by verticalSpace
+ #fit resize elements vertically to fit this panel
+ #fitSpace like #fit, but with spacing
+
+ #topMax like #top, but resize all views vertically to max height
+ #topSpaceMax like #topSpace, but resize all views vertically to max height
+ #bottomMax like #bottom, but resize all views vertically to max height
+ #bottomSpaceMax like #bottomSpace, but resize all views vertically to max height
+ #centerMax like #center, but resize all views vertically to max height
the default (if never changed) is #center
See the class documentation for the meanings.
"
@@ -724,11 +1006,14 @@
subViews do:[:child |
|childsPreference|
+ "/ better to use component's preferredExtent ...
+
childsPreference := child preferredExtent.
sumOfWidths := sumOfWidths + childsPreference x.
maxHeight := maxHeight max:childsPreference y.
maxWidth := maxWidth max:childsPreference x.
+ "/ ... instead of actual extent
"/ sumOfWidths := sumOfWidths + child widthIncludingBorder.
"/ maxHeight := maxHeight max:(child heightIncludingBorder).
"/ maxWidth := maxWidth max:(child widthIncludingBorder).
@@ -737,7 +1022,9 @@
sumOfWidths := sumOfWidths + (horizontalSpace * 2).
maxHeight := maxHeight + (verticalSpace * 2).
].
- (hLayout == #fit or:[hLayout == #fitSpace]) ifTrue:[
+ (hLayout == #fit
+ or:[hLayout == #fitSpace
+ or:[hLayout endsWith:'Max']]) ifTrue:[
sumOfWidths := maxWidth * subViews size.
borderWidth ~~ 0 ifTrue:[
sumOfWidths := sumOfWidths + (horizontalSpace * 2).
@@ -770,7 +1057,8 @@
"(re)compute position of every child whenever childs are added or
my size has changed"
- |xpos space sumOfWidths numChilds l wEach wInside hL vL|
+ |xpos space sumOfWidths numChilds l wEach wInside hL vL resizeToMaxV
+ resizeToMaxH maxHeight maxWidth|
subViews isNil ifTrue:[^ self].
@@ -781,6 +1069,13 @@
hL := hLayout.
vL := vLayout.
+ resizeToMaxH := false.
+ (hL endsWith:'Max') ifTrue:[
+ wEach := maxWidth := subViews inject:0 into:[:maxSoFar :child | maxSoFar max:child widthIncludingBorder].
+ hL := (hL copyWithoutLast:3) asSymbol.
+ resizeToMaxH := true.
+ ].
+
hL == #fitSpace ifTrue:[
"
adjust childs extents and set origins.
@@ -800,7 +1095,11 @@
"
compute net width needed
"
- sumOfWidths := subViews inject:0 into:[:sumSoFar :child | sumSoFar + child widthIncludingBorder].
+ resizeToMaxH ifTrue:[
+ sumOfWidths := subViews inject:0 into:[:sumSoFar :child | sumSoFar + maxWidth + (child borderWidth*2)].
+ ] ifFalse:[
+ sumOfWidths := subViews inject:0 into:[:sumSoFar :child | sumSoFar + child widthIncludingBorder].
+ ].
l := hL.
((l == #center) and:[numChilds == 1]) ifTrue:[
@@ -896,10 +1195,29 @@
].
].
+ vL := vLayout.
+ resizeToMaxV := false.
+ (vLayout endsWith:'Max') ifTrue:[
+ resizeToMaxV := true.
+ maxHeight := subViews inject:0 into:[:maxSoFar :child | maxSoFar max:child heightIncludingBorder].
+ vL == #centerMax ifTrue:[vL := #center].
+ vL == #bottomMax ifTrue:[vL := #bottom].
+ vL == #bottomSpaceMax ifTrue:[vL := #bottomSpace].
+ vL == #topMax ifTrue:[vL := #top].
+ vL == #topSpaceMax ifTrue:[vL := #topSpace].
+ ].
+
"now set positions"
subViews keysAndValuesDo:[:index :child |
- |ypos advance|
+ |ypos advance bwChild hChild|
+
+ hChild := child heightIncludingBorder.
+ bwChild := child borderWidth.
+
+ resizeToMaxV ifTrue:[
+ child height:(hChild := maxHeight - (bwChild * 2)).
+ ].
vL == #top ifTrue:[
ypos := 0
@@ -915,11 +1233,11 @@
] ifFalse:[
vL == #fitSpace ifTrue:[
ypos := verticalSpace.
- child height:(height - (verticalSpace + child borderWidth * 2))
+ child height:(height - (verticalSpace + bwChild * 2))
] ifFalse:[
vL == #fit ifTrue:[
ypos := 0.
- child height:(height - (child borderWidth * 2))
+ child height:(height - (bwChild * 2))
] ifFalse:[
"centered"
ypos := (height - child heightIncludingBorder) // 2.
@@ -931,7 +1249,9 @@
].
(ypos < 0) ifTrue:[ypos := 0].
- (hL == #fit or:[hL == #fitSpace]) ifTrue:[
+ (hL == #fit
+ or:[hL == #fitSpace
+ or:[resizeToMaxH]]) ifTrue:[
child origin:(xpos truncated @ ypos)
corner:(xpos + wEach - (child borderWidth)) truncated
@ (ypos + child height).