[GOODIE] RowsMorph
Matej Kosik
kosik at decef.elf.stuba.sk
Thu Jan 29 13:01:55 UTC 2004
I have recently run into problems when I was trying to implement
my first real GUI thing.
http://squeakland.org/project.jsp?http://altair.dcs.elf.stuba.sk/~kosik/plugin/4/CellularAutomata.pr
There was no easy way how to put several morphs together in a way I have
required. I have looked how similar tasks are done in Tetris to look for some
inspiration. The code I have found worked but that was all in my opinion
cumbersome.
I am posting a by-product of my work which makes it possible to align
several morphs into several rows quite easily.
!!! The code works only with the changeset I have most recently submitted.
The same piece of the changeset can be found here:
http://altair.dcs.elf.stuba.sk/~kosik/cs/AlignmentMorph-fix-2.1.cs
If you load that changeset and the attached code, you can try:
RowsMorph example1.
RowsMorph example2.
There is also some class comment. RowsMorph lets you easily specify the horizontal and vertical inset of the added morphs. New rows are added fairly easily.
--
Matej Kosik <http://altair.dcs.elf.stuba.sk/wiki/Kosik/Main>
-------------- next part --------------
'From Squeak3.4 of 1 March 2003 [latest update: #5170] on 27 January 2004 at 5:21:54 pm'!
AlignmentMorph subclass: #RowsMorph
instanceVariableNames: 'currentRow columnInset '
classVariableNames: ''
poolDictionaries: ''
category: 'Morphic-Basic'!
!RowsMorph commentStamp: 'mk 1/27/2004 12:10' prior: 0!
This morph facilitates aligning many morphs into one or more rows. The particular rows may
contain arbitrary (themselves independent) number of morphs.
ExampleUsage:
RowsMorph example1.
RowsMorph example2.
Methods affecting the submorphs' layout:
Morph layoutInset: -- Defines the minimal space left between the submorphs
and the (defaultly invisible) border of this morph.
RowsMorph rowInset: -- Sets the minimal vertical space left between particular rows.
RowsMorph columnInset: -- Set the minimal horizontal space left between particular
morphs in the row.
Morph cellPositioning: -- Rows are centered within single column.
You can change !
this default behavior with this method
as for example morph cellPositioning: #topLeft.
Instance variables:
currentRow -- AlignmentMorph (as column) which is the current row to which
newly added morphs will go.
columnInset -- The distance between two adjacent morphs in the same row.
Symmetrical similarity: ColumnsMorph
Possible enhancement which can be made to this morph:
- This morph does not currently support change in its structure (the submorphs
it contains).
- It is for example not possible to throw away a single already added morph.
- It is now not possible to throw away a whole row of morphs.
- It is not possible to add new morph somewhere in between already added morphs.
- It is not possible to add new row in between already added rows.
- Directions in which things are added.!
]style[(170 19 2 19 44 18 121 19 68 22 90 22 132 32 239 12 488)f1,f1dRowsMorph example1.;;,f1,f1dRowsMorph example2.;;,f1,f1LMorph layoutInset:;,f1,f1LRo!
wsMorph rowInset:;,f1,f1LRowsMorph columnInset:;,f1,f1LMorph cellPositioning:;,f1,f1b,f1,f1LColumnsMorph Comment;,f1!
!RowsMorph methodsFor: 'initialization' stamp: 'mk 1/27/2004 10:58'!
initialize
super initialize.
self layoutInset: 0.
self cellInset: 0.
columnInset _ 0.
currentRow _ self newRow.
super addMorphBack: currentRow! !
!RowsMorph methodsFor: 'submorphs-add/remove' stamp: 'mk 1/27/2004 10:44'!
addMorph: aMorph
currentRow addMorphBack: aMorph! !
!RowsMorph methodsFor: 'submorphs-add/remove' stamp: 'mk 1/27/2004 10:47'!
addRow
currentRow _ self newRow.
super addMorphBack: currentRow! !
!RowsMorph methodsFor: 'layout-properties' stamp: 'mk 1/27/2004 10:55'!
cellInset: aNumber
self rowInset: aNumber.
self columnInset: aNumber! !
!RowsMorph methodsFor: 'layout-properties' stamp: 'mk 1/27/2004 11:00'!
columnInset: aNumber
columnInset _ aNumber.
self submorphsDo: [:rowMorph | rowMorph cellInset: columnInset]! !
!RowsMorph methodsFor: 'layout-propert!
ies' stamp: 'mk 1/27/2004 10:57'!
rowInset: aNumber
super cellInset: aNumber.! !
!RowsMorph methodsFor: 'private' stamp: 'mk 1/27/2004 10:58'!
newRow
^ AlignmentMorph newRow
layoutInset: 0;
cellInset: columnInset;
hResizing: #shrinkWrap;
vResizing: #shrinkWrap;
setNameTo: 'Row'! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
RowsMorph class
instanceVariableNames: ''!
!RowsMorph class methodsFor: 'instance creation' stamp: 'mk 1/27/2004 11:05'!
new
"The items of the new column will be particular rows which will actually contain
the added morphs."
^ super newColumn
hResizing: #shrinkWrap;
vResizing: #shrinkWrap.! !
!RowsMorph class methodsFor: 'examples' stamp: 'mk 1/24/2004 23:58'!
example1
| rowsMorph |
"See also: ColumnsMorph class example1"
rowsMorph _ RowsMorph new openInWorld.
rowsMorph addMorph: (RectangleMorph new color: Color red).
rowsMorph addMorph: (RectangleMorph new color: Color green).
rowsMorph addMorph: (Rect!
angleMorph new color: Color blue).
rowsMorph addRow.
rowsMorph addMorph: (EllipseMorph new color: Color red).
rowsMorph addMorph: (EllipseMorph new color: Color green).
rowsMorph addMorph: (EllipseMorph new color: Color blue).!
]style[(8 30 27 422)f1b,f1,f1LColumnsMorph class example1;,f1! !
!RowsMorph class methodsFor: 'examples' stamp: 'mk 1/27/2004 11:33'!
example2
| rowsMorph colors |
"See also: ColumnsMorph class example2"
rowsMorph _ RowsMorph new.
"Vertical space left between the two adjacent rows."
rowsMorph rowInset: 15.
"Horizontal space left between the two adjacent morphs in a row."
rowsMorph columnInset: 5.
"RectangleMorphs in the same row will have the same color."
colors _ Color wheel: 10.
1 to: 10 do:
[:row |
| currentColor |
currentColor _ colors at: row.
10 timesRepeat:
[rowsMorph addMorph: (RectangleMorph new extent: 20 at 20; color: currentColor)].
rowsMorph addRow].
rowsMorph openInWorld.!
]style[(8 37 27 519)f1b,f1,f1!
LColumnsMorph class example2;,f1! !
More information about the Squeak-dev
mailing list
|