[GOODIE] ColumnsMorph

Matej Kosik kosik at decef.elf.stuba.sk
Thu Jan 29 13:04:46 UTC 2004


Follows the spirit of the RowsMorph I have sent before.
It facilitates adding some morphs in several columns.
-- 
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:48 pm'!
AlignmentMorph subclass: #ColumnsMorph
	instanceVariableNames: 'currentColumn rowInset '
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Morphic-Basic'!
!ColumnsMorph commentStamp: 'mk 1/27/2004 12:11' prior: 0!
This morph facilitates aligning many morphs into one or more columns. The particular rows may 
contain arbitrary (themselves independent) number of morphs.

ExampleUsage:

	ColumnsMorph class example1
	ColumnsMorph class example2

Methods affecting the submorphs' layout
	Morph layoutInset:			--	Defines the minimal space left between the submorphs
									and the	(defaultly invisible) border of this morph.
	ColumnsMorph columnInset:	--	Defines the minimal horizontal space left between
									the particular rows.
	ColumnsMorph rowInset:		--	Defines the minimal vertical space left between
									the particular morphs in a column.
	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:
		
	currentColumn			--	AlignmentMorph (as row) which is the current row to which
								newly added morphs will go.
	rowInset				--	The distance between two adjacent morphs in the same column.

Symmetrical similarity: RowsMorph

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[(173 27 2 27 43 21 118 25 85 22 98 22 132 32 240 9 488)f1,f1LColumnsMorph class example1;,f1,!
f1LColumnsMorph class example2;,f1,f1LMorph layoutInset:;,f1,f1LColumnsMorph columnInset:;,f1,f1LColumnsMorph rowInset:;,f1,f1LMorph cellPositioning:;,f1,f1b,f1,f1LRowsMorph Comment;,f1!


!ColumnsMorph methodsFor: 'initialization' stamp: 'mk 1/27/2004 11:18'!
initialize
	super initialize.
	self layoutInset: 0.
	self cellInset: 0.
	rowInset _ 0.
	currentColumn _ self newColumn.
	super addMorphBack: currentColumn! !


!ColumnsMorph methodsFor: 'submorphs-add/remove' stamp: 'mk 1/27/2004 11:18'!
addColumn
	currentColumn _ self newColumn.
	super addMorphBack: currentColumn! !

!ColumnsMorph methodsFor: 'submorphs-add/remove' stamp: 'mk 1/27/2004 11:19'!
addMorph: aMorph
	currentColumn addMorphBack: aMorph! !


!ColumnsMorph methodsFor: 'layout-properties' stamp: 'mk 1/27/2004 11:17'!
cellInset: aNumber
	self rowInset: aNumber.
	self columnInset: aNumber! !

!ColumnsMorph methodsFor: 'layout-properties' stamp: 'mk 1/27/2004 11:17'!
columnInset: aNumber
	super cellInset: aNumber.!
! !

!ColumnsMorph methodsFor: 'layout-properties' stamp: 'mk 1/27/2004 11:17'!
rowInset: aNumber
	rowInset _ aNumber.
	self submorphsDo: [:columnMorph | columnMorph cellInset: rowInset]! !


!ColumnsMorph methodsFor: 'private' stamp: 'mk 1/27/2004 11:16'!
newColumn
	^ AlignmentMorph newColumn
		layoutInset: 0;
		cellInset: rowInset;
		hResizing: #shrinkWrap;
		vResizing: #shrinkWrap;
		setNameTo: 'Column'! !

"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

ColumnsMorph class
	instanceVariableNames: ''!

!ColumnsMorph class methodsFor: 'instance creation' stamp: 'mk 1/27/2004 11:22'!
new
	"The items of the new row will be particular columns which will actually contain
	the added morphs."
	
	^ super newRow
		hResizing: #shrinkWrap;
		vResizing: #shrinkWrap.! !


!ColumnsMorph class methodsFor: 'examples' stamp: 'mk 1/25/2004 00:05'!
example1
	| columnsMorph |
	
	"See also: RowsMorph class example1"
	
	columnsMorph _ ColumnsMorph new.
	columnsMorph addMorph: (Rectan!
gleMorph new color: Color red).
	columnsMorph addMorph: (RectangleMorph new color: Color green).
	columnsMorph addMorph: (RectangleMorph new color: Color blue).
	columnsMorph addColumn.
	columnsMorph addMorph: (EllipseMorph new color: Color red).
	columnsMorph addMorph: (EllipseMorph new color: Color green).
	columnsMorph addMorph: (EllipseMorph new color: Color blue).
	columnsMorph openInWorld.!
]style[(8 33 24 467)f1b,f1,f1LRowsMorph class example1;,f1! !

!ColumnsMorph class methodsFor: 'examples' stamp: 'mk 1/27/2004 11:35'!
example2
	| colors columnsMorph |
	
	"See also: RowsMorph class example2"

	columnsMorph _ ColumnsMorph new.
	
	"Horizontal space left between the two adjacent columns."
	columnsMorph columnInset: 15.

	"Vertical space left between the two adjacent morphs ini the same column."
	columnsMorph rowInset: 5.

	"RectangleMorphs in the same column will have the same color."

	colors _ Color wheel: 10.
	1 to: 10 do:
		[:column |
		| currentColor |
		currentC!
olor _ colors at: column.
		10 timesRepeat:
			[columnsMorph addMorph: (RectangleMorph new
				extent: 20 at 20; color: currentColor)].
		columnsMorph addColumn].
	columnsMorph openInWorld.!
]style[(8 40 24 568)f1b,f1,f1LRowsMorph class example2;,f1! !


More information about the Squeak-dev mailing list