0
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1989-92 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
PanelView subclass:#HorizontalPanelView
|
|
14 |
instanceVariableNames:''
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Views-Layout'
|
|
18 |
!
|
|
19 |
|
|
20 |
HorizontalPanelView comment:'
|
|
21 |
|
|
22 |
COPYRIGHT (c) 1989-92 by Claus Gittinger
|
|
23 |
All Rights Reserved
|
|
24 |
|
|
25 |
a View for childViews oriented horizontal
|
|
26 |
all real work is done in PanelView - just redefine layout
|
|
27 |
|
|
28 |
%W% %E%
|
|
29 |
|
|
30 |
written spring/summer 89 by claus
|
|
31 |
'!
|
|
32 |
|
|
33 |
!HorizontalPanelView methodsFor:'queries'!
|
|
34 |
|
|
35 |
preferedExtent
|
|
36 |
"return a good extent, one that makes subviews fit"
|
|
37 |
|
|
38 |
|sumOfWidths maxHeight|
|
|
39 |
|
|
40 |
subViews isNil ifTrue:[^ horizontalSpace @ verticalSpace].
|
|
41 |
|
|
42 |
"compute net height needed"
|
|
43 |
|
|
44 |
sumOfWidths := 0.
|
|
45 |
maxHeight := 0.
|
|
46 |
|
|
47 |
subViews do:[:child |
|
|
48 |
sumOfWidths := sumOfWidths + child widthIncludingBorder.
|
|
49 |
maxHeight := maxHeight max:(child heightIncludingBorder)
|
|
50 |
].
|
|
51 |
borderWidth ~~ 0 ifTrue:[
|
|
52 |
sumOfWidths := sumOfWidths + (horizontalSpace * 2).
|
|
53 |
maxHeight := maxHeight + (verticalSpace * 2).
|
|
54 |
].
|
|
55 |
sumOfWidths := sumOfWidths + ((subViews size - 1) * horizontalSpace).
|
|
56 |
|
|
57 |
^ sumOfWidths @ maxHeight
|
|
58 |
! !
|
|
59 |
|
|
60 |
!HorizontalPanelView methodsFor:'layout'!
|
|
61 |
|
|
62 |
setChildPositions
|
|
63 |
"(re)compute position of every child whenever childs are added or
|
|
64 |
my size has changed"
|
|
65 |
|
|
66 |
|xpos ypos space sumOfChildWidths numChilds l|
|
|
67 |
|
|
68 |
subViews isNil ifTrue:[^ self].
|
|
69 |
|
|
70 |
space := horizontalSpace.
|
|
71 |
|
|
72 |
"compute net width needed"
|
|
73 |
|
|
74 |
sumOfChildWidths := 0.
|
|
75 |
numChilds := subViews size.
|
|
76 |
subViews do:[:child |
|
|
77 |
sumOfChildWidths := sumOfChildWidths + child widthIncludingBorder.
|
|
78 |
].
|
|
79 |
|
|
80 |
l := layout.
|
|
81 |
((l == #center) and:[numChilds == 1]) ifTrue:[
|
|
82 |
l := #spread
|
|
83 |
].
|
|
84 |
|
|
85 |
"compute position of leftmost subview and space between them;
|
|
86 |
if they do hardly fit, leave no space between them "
|
|
87 |
|
|
88 |
(sumOfChildWidths >= width) ifTrue:[
|
|
89 |
xpos := 0.
|
|
90 |
space := 0
|
|
91 |
] ifFalse: [
|
|
92 |
(l == #right) ifTrue:[
|
|
93 |
xpos := width - (horizontalSpace * numChilds)
|
|
94 |
- sumOfChildWidths.
|
|
95 |
borderWidth == 0 ifTrue:[
|
|
96 |
xpos := xpos + horizontalSpace
|
|
97 |
].
|
|
98 |
] ifFalse:[
|
|
99 |
(l == #spread) ifTrue:[
|
|
100 |
space := (width - sumOfChildWidths) // (numChilds + 1).
|
|
101 |
xpos := space.
|
|
102 |
(space == 0) ifTrue:[
|
|
103 |
xpos := (width - sumOfChildWidths) // 2
|
|
104 |
]
|
|
105 |
] ifFalse:[
|
|
106 |
(l == #center) ifTrue:[
|
|
107 |
xpos := (width - (sumOfChildWidths
|
|
108 |
+ ((numChilds - 1) * space))) // 2
|
|
109 |
] ifFalse:[
|
|
110 |
borderWidth == 0 ifTrue:[
|
|
111 |
xpos := 0
|
|
112 |
] ifFalse:[
|
|
113 |
xpos := horizontalSpace
|
|
114 |
]
|
|
115 |
]
|
|
116 |
]
|
|
117 |
]
|
|
118 |
].
|
|
119 |
|
|
120 |
"now set positions"
|
|
121 |
|
|
122 |
subViews do:[:child |
|
|
123 |
ypos := (height - child heightIncludingBorder) // 2.
|
|
124 |
(ypos < 0) ifTrue:[ypos := 0].
|
|
125 |
|
|
126 |
child origin:(xpos @ ypos).
|
|
127 |
xpos := xpos + (child widthIncludingBorder) + space
|
|
128 |
]
|
|
129 |
! !
|