Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions chapter-02/contents.texinfo
Original file line number Diff line number Diff line change
Expand Up @@ -176,26 +176,37 @@ all the available space.
@cindex layout @subentry @class{LayoutSpec}
Each morph can have a @class{LayoutSpec} that specifies how it should
be laid out within its owner, this ignored if the owner is not a
@class{LayoutMorph} instance.
@class{LayoutMorph} instance. @class{LayoutSpec} is abstract with two
subclasses:
@itemize
@item
@class{LayoutSizeSpec} - for rows/columns. Manages dimensions via
@smalltalk{fixedWidth}, @smalltalk{fixedHeight},
@smalltalk{proportionalWidth} and @smalltalk{proportionalHeight}
and alignment via @smalltalk{offAxisEdgeWeight}.

@item
@class{LayoutEdgesSpec} - for form layouts. Defines corner anchors
using @smalltalk{topLeftEdgesWeight},
@smalltalk{bottomRightEdgesWeight}, @smalltalk{topLeftOffset} and
@smalltalk{bottomRightOffset}.
@end itemize

Instances of @class{LayoutSpec} have the following instance variables:
@smalltalk{morph}, @smalltalk{fixedWidth}, @smalltalk{fixedHeight},
@smalltalk{offAxisEdgeWeight}, @smalltalk{proportionalWidth}, and
@smalltalk{proportionalHeight}. There are methods to set each of
these instance variables.
Instances of @class{LayoutSpec} have @smalltalk{morph} as instance
variable. There are methods to set each of these instance variables.

@smalltalkExample{box2 layoutSpec proportionalWidth: 1}

@figure{Using proportionalWidth, ch03-layoutmorph-example7, 6}

We could have added @smalltalk{box2} to @smalltalk{layout} using the
message @msg{add:proportionWidth:} which adds a submorph AND sets the
@smalltalk{proportionalWidth} property of its @class{LayoutSpec}.
@smalltalk{proportionalWidth} property of its @class{LayoutSizeSpec}.
However, an issue with this approach is that it creates a new instance
of @class{LayoutSpec} where the values of
of @class{LayoutSizeSpec} where the values of
@smalltalk{proportionalWidth} and @smalltalk{proportionalHeight} are
both 1. To only modify one of those properties, it's best to set it
directly on the @class{LayoutSpec} instance of the morph.
directly on the @class{LayoutSizedSpec} instance of the morph.

@cindex layout @subentry spacer
Let's modify our example @ref{layoutExample1} so the boxes are spread
Expand Down
4 changes: 2 additions & 2 deletions misc/MemoryGameV1-untabbed.pck.st
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ installStatusBar
borderWidth: 1;
borderColor: self borderColor twiceLighter ;
setHeightOnContent.
self addMorph: statusBar layoutSpec: LayoutSpec new useMorphHeight.
self addMorph: statusBar layoutSpec: LayoutSizeSpec new useMorphHeight.
self message: 'Welcome to ', 'Memory Game' bold! !

!MemoryGameWindow methodsFor: 'initialization' stamp: 'hlsf 3/18/2025 23:30:19'!
Expand All @@ -166,7 +166,7 @@ installToolbar
setBalloonText: 'Stop the game';
morphExtent: 32 asPoint.
toolbar addMorph: button.
self addMorph: toolbar layoutSpec: LayoutSpec new useMorphHeight
self addMorph: toolbar layoutSpec: LayoutSizeSpec new useMorphHeight
! !

!MemoryGameWindow methodsFor: 'updating' stamp: 'hlsf 3/19/2025 16:37:56'!
Expand Down
12 changes: 6 additions & 6 deletions misc/MemoryGameV1.pck.st
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'From Cuis7.3 [latest update: #7095] on 10 April 2025 at 10:53:03 am'!
'From Cuis7.5 [latest update: #7342] on 9 July 2025 at 1:15:16 pm'!
'Description '!
!provides: 'MemoryGameV1' 1 6!
!provides: 'MemoryGameV1' 1 7!
SystemOrganization addCategory: #MemoryGameV1!


Expand Down Expand Up @@ -137,18 +137,18 @@ installCards
cards at: x@y put: card ].
playground addMorph: row ]! !

!MemoryGameWindow methodsFor: 'initialization' stamp: 'hlsf 3/18/2025 23:14:00'!
!MemoryGameWindow methodsFor: 'initialization' stamp: 'tsl 7/9/2025 13:14:39'!
installStatusBar
statusBar := TextParagraphMorph new
padding: 2;
color: Color transparent;
borderWidth: 1;
borderColor: self borderColor twiceLighter ;
setHeightOnContent.
self addMorph: statusBar layoutSpec: LayoutSpec new useMorphHeight.
self addMorph: statusBar layoutSpec: LayoutSizeSpec new useMorphHeight.
self message: 'Welcome to ', 'Memory Game' bold! !

!MemoryGameWindow methodsFor: 'initialization' stamp: 'hlsf 3/18/2025 23:30:19'!
!MemoryGameWindow methodsFor: 'initialization' stamp: 'tsl 7/9/2025 13:14:32'!
installToolbar
| toolbar button |
toolbar := LayoutMorph newRow separation: 2.
Expand All @@ -166,7 +166,7 @@ installToolbar
setBalloonText: 'Stop the game';
morphExtent: 32 asPoint.
toolbar addMorph: button.
self addMorph: toolbar layoutSpec: LayoutSpec new useMorphHeight
self addMorph: toolbar layoutSpec: LayoutSizeSpec new useMorphHeight
! !

!MemoryGameWindow methodsFor: 'updating' stamp: 'hlsf 3/19/2025 16:37:56'!
Expand Down
4 changes: 2 additions & 2 deletions misc/MemoryGameV2-untabbed.pck.st
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ installStatusBar
borderWidth: 1;
borderColor: self borderColor twiceLighter ;
setHeightOnContent.
self addMorph: statusBar layoutSpec: LayoutSpec new useMorphHeight.
self addMorph: statusBar layoutSpec: LayoutSizeSpec new useMorphHeight.
self message: 'Welcome to ', 'Memory Game' bold! !

!MemoryGameWindow methodsFor: 'initialization' stamp: 'hlsf 3/22/2025 15:40:23'!
Expand All @@ -284,7 +284,7 @@ installToolbar
setBalloonText: 'Stop the game';
morphExtent: 32 asPoint.
toolbar addMorph: button.
self addMorph: toolbar layoutSpec: LayoutSpec new useMorphHeight
self addMorph: toolbar layoutSpec: LayoutSizeSpec new useMorphHeight
! !

!MemoryGameWindow class methodsFor: 'instance creation' stamp: 'hlsf 3/22/2025 15:37:23'!
Expand Down
30 changes: 15 additions & 15 deletions misc/MemoryGameV2.pck.st
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
'From Cuis7.3 [latest update: #7095] on 10 April 2025 at 10:56:43 am'!
'From Cuis7.5 [latest update: #7342] on 9 July 2025 at 1:21:51 pm'!
'Description '!
!provides: 'MemoryGameV2' 1 9!
SystemOrganization addCategory: 'MemoryGameV2'!
!provides: 'MemoryGameV2' 1 10!
SystemOrganization addCategory: #MemoryGameV2!


!classDefinition: #MemoryCardModel category: 'MemoryGameV2'!
!classDefinition: #MemoryCardModel category: #MemoryGameV2!
Object subclass: #MemoryCardModel
instanceVariableNames: 'flipped done color'
classVariableNames: ''
poolDictionaries: ''
category: 'MemoryGameV2'!
!classDefinition: 'MemoryCardModel class' category: 'MemoryGameV2'!
!classDefinition: 'MemoryCardModel class' category: #MemoryGameV2!
MemoryCardModel class
instanceVariableNames: ''!

!classDefinition: #MemoryGame category: 'MemoryGameV2'!
!classDefinition: #MemoryGame category: #MemoryGameV2!
Object subclass: #MemoryGame
instanceVariableNames: 'model view playing'
classVariableNames: ''
poolDictionaries: ''
category: 'MemoryGameV2'!
!classDefinition: 'MemoryGame class' category: 'MemoryGameV2'!
!classDefinition: 'MemoryGame class' category: #MemoryGameV2!
MemoryGame class
instanceVariableNames: ''!

!classDefinition: #MemoryGameModel category: 'MemoryGameV2'!
!classDefinition: #MemoryGameModel category: #MemoryGameV2!
Object subclass: #MemoryGameModel
instanceVariableNames: 'size tupleSize cards'
classVariableNames: ''
poolDictionaries: ''
category: 'MemoryGameV2'!
!classDefinition: 'MemoryGameModel class' category: 'MemoryGameV2'!
!classDefinition: 'MemoryGameModel class' category: #MemoryGameV2!
MemoryGameModel class
instanceVariableNames: ''!

!classDefinition: #MemoryGameWindow category: 'MemoryGameV2'!
!classDefinition: #MemoryGameWindow category: #MemoryGameV2!
SystemWindow subclass: #MemoryGameWindow
instanceVariableNames: 'presenter statusBar playground'
classVariableNames: ''
poolDictionaries: ''
category: 'MemoryGameV2'!
!classDefinition: 'MemoryGameWindow class' category: 'MemoryGameV2'!
!classDefinition: 'MemoryGameWindow class' category: #MemoryGameV2!
MemoryGameWindow class
instanceVariableNames: ''!

Expand Down Expand Up @@ -255,18 +255,18 @@ installCards
row addMorph: cardView].
playground addMorph: row ]! !

!MemoryGameWindow methodsFor: 'initialization' stamp: 'hlsf 3/18/2025 23:14:00'!
!MemoryGameWindow methodsFor: 'initialization' stamp: 'tsl 7/9/2025 13:21:19'!
installStatusBar
statusBar := TextParagraphMorph new
padding: 2;
color: Color transparent;
borderWidth: 1;
borderColor: self borderColor twiceLighter ;
setHeightOnContent.
self addMorph: statusBar layoutSpec: LayoutSpec new useMorphHeight.
self addMorph: statusBar layoutSpec: LayoutSizeSpec new useMorphHeight.
self message: 'Welcome to ', 'Memory Game' bold! !

!MemoryGameWindow methodsFor: 'initialization' stamp: 'hlsf 3/22/2025 15:40:23'!
!MemoryGameWindow methodsFor: 'initialization' stamp: 'tsl 7/9/2025 13:21:12'!
installToolbar
| toolbar button |
toolbar := LayoutMorph newRow separation: 2.
Expand All @@ -284,7 +284,7 @@ installToolbar
setBalloonText: 'Stop the game';
morphExtent: 32 asPoint.
toolbar addMorph: button.
self addMorph: toolbar layoutSpec: LayoutSpec new useMorphHeight
self addMorph: toolbar layoutSpec: LayoutSizeSpec new useMorphHeight
! !

!MemoryGameWindow class methodsFor: 'instance creation' stamp: 'hlsf 3/22/2025 15:37:23'!
Expand Down
4 changes: 2 additions & 2 deletions misc/MemoryGameV3-untabbed.pck.st
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ installStatusBar
borderWidth: 1;
borderColor: self borderColor twiceLighter ;
setHeightOnContent.
self addMorph: statusBar layoutSpec: LayoutSpec new useMorphHeight.
self addMorph: statusBar layoutSpec: LayoutSizeSpec new useMorphHeight.
self message: 'Welcome to ', 'Memory Game' bold! !

!MemoryGameWindow methodsFor: 'initialization' stamp: 'hlsf 5/24/2025 10:32:50'!
Expand Down Expand Up @@ -506,7 +506,7 @@ installToolbar
setBalloonText: 'Redo the last play';
morphExtent: 32 asPoint.
toolbar addMorph: button.
self addMorph: toolbar layoutSpec: LayoutSpec new useMorphHeight
self addMorph: toolbar layoutSpec: LayoutSizeSpec new useMorphHeight
! !

!MemoryGameWindow class methodsFor: 'instance creation' stamp: 'hlsf 3/22/2025 15:37:23'!
Expand Down
46 changes: 23 additions & 23 deletions misc/MemoryGameV3.pck.st
Original file line number Diff line number Diff line change
@@ -1,86 +1,86 @@
'From Cuis7.3 [latest update: #7158] on 24 May 2025 at 4:26:24 pm'!
'From Cuis7.5 [latest update: #7342] on 9 July 2025 at 1:20:31 pm'!
'Description '!
!provides: 'MemoryGameV3' 1 3!
SystemOrganization addCategory: 'MemoryGameV3'!
!provides: 'MemoryGameV3' 1 4!
SystemOrganization addCategory: #MemoryGameV3!


!classDefinition: #Command category: 'MemoryGameV3'!
!classDefinition: #Command category: #MemoryGameV3!
Object subclass: #Command
instanceVariableNames: 'presenter'
classVariableNames: ''
poolDictionaries: ''
category: 'MemoryGameV3'!
!classDefinition: 'Command class' category: 'MemoryGameV3'!
!classDefinition: 'Command class' category: #MemoryGameV3!
Command class
instanceVariableNames: ''!

!classDefinition: #PlayCardCommand category: 'MemoryGameV3'!
!classDefinition: #PlayCardCommand category: #MemoryGameV3!
Command subclass: #PlayCardCommand
instanceVariableNames: 'status position'
classVariableNames: ''
poolDictionaries: ''
category: 'MemoryGameV3'!
!classDefinition: 'PlayCardCommand class' category: 'MemoryGameV3'!
!classDefinition: 'PlayCardCommand class' category: #MemoryGameV3!
PlayCardCommand class
instanceVariableNames: ''!

!classDefinition: #CommandManager category: 'MemoryGameV3'!
!classDefinition: #CommandManager category: #MemoryGameV3!
Object subclass: #CommandManager
instanceVariableNames: 'stack presenter'
classVariableNames: ''
poolDictionaries: ''
category: 'MemoryGameV3'!
!classDefinition: 'CommandManager class' category: 'MemoryGameV3'!
!classDefinition: 'CommandManager class' category: #MemoryGameV3!
CommandManager class
instanceVariableNames: ''!

!classDefinition: #MemoryCardModel category: 'MemoryGameV3'!
!classDefinition: #MemoryCardModel category: #MemoryGameV3!
Object subclass: #MemoryCardModel
instanceVariableNames: 'flipped done color'
classVariableNames: ''
poolDictionaries: ''
category: 'MemoryGameV3'!
!classDefinition: 'MemoryCardModel class' category: 'MemoryGameV3'!
!classDefinition: 'MemoryCardModel class' category: #MemoryGameV3!
MemoryCardModel class
instanceVariableNames: ''!

!classDefinition: #MemoryGame category: 'MemoryGameV3'!
!classDefinition: #MemoryGame category: #MemoryGameV3!
Object subclass: #MemoryGame
instanceVariableNames: 'model view playing cmdManager'
classVariableNames: ''
poolDictionaries: ''
category: 'MemoryGameV3'!
!classDefinition: 'MemoryGame class' category: 'MemoryGameV3'!
!classDefinition: 'MemoryGame class' category: #MemoryGameV3!
MemoryGame class
instanceVariableNames: ''!

!classDefinition: #MemoryGameModel category: 'MemoryGameV3'!
!classDefinition: #MemoryGameModel category: #MemoryGameV3!
Object subclass: #MemoryGameModel
instanceVariableNames: 'size tupleSize cards'
classVariableNames: ''
poolDictionaries: ''
category: 'MemoryGameV3'!
!classDefinition: 'MemoryGameModel class' category: 'MemoryGameV3'!
!classDefinition: 'MemoryGameModel class' category: #MemoryGameV3!
MemoryGameModel class
instanceVariableNames: ''!

!classDefinition: #CommandStack category: 'MemoryGameV3'!
!classDefinition: #CommandStack category: #MemoryGameV3!
ReadWriteStream subclass: #CommandStack
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'MemoryGameV3'!
!classDefinition: 'CommandStack class' category: 'MemoryGameV3'!
!classDefinition: 'CommandStack class' category: #MemoryGameV3!
CommandStack class
instanceVariableNames: ''!

!classDefinition: #MemoryGameWindow category: 'MemoryGameV3'!
!classDefinition: #MemoryGameWindow category: #MemoryGameV3!
SystemWindow subclass: #MemoryGameWindow
instanceVariableNames: 'presenter statusBar playground'
classVariableNames: ''
poolDictionaries: ''
category: 'MemoryGameV3'!
!classDefinition: 'MemoryGameWindow class' category: 'MemoryGameV3'!
!classDefinition: 'MemoryGameWindow class' category: #MemoryGameV3!
MemoryGameWindow class
instanceVariableNames: ''!

Expand Down Expand Up @@ -467,18 +467,18 @@ installCards
row addMorph: cardView].
playground addMorph: row ]! !

!MemoryGameWindow methodsFor: 'initialization' stamp: 'hlsf 3/18/2025 23:14:00'!
!MemoryGameWindow methodsFor: 'initialization' stamp: 'tsl 7/9/2025 13:19:58'!
installStatusBar
statusBar := TextParagraphMorph new
padding: 2;
color: Color transparent;
borderWidth: 1;
borderColor: self borderColor twiceLighter ;
setHeightOnContent.
self addMorph: statusBar layoutSpec: LayoutSpec new useMorphHeight.
self addMorph: statusBar layoutSpec: LayoutSizeSpec new useMorphHeight.
self message: 'Welcome to ', 'Memory Game' bold! !

!MemoryGameWindow methodsFor: 'initialization' stamp: 'hlsf 5/24/2025 10:32:50'!
!MemoryGameWindow methodsFor: 'initialization' stamp: 'tsl 7/9/2025 13:19:20'!
installToolbar
| toolbar button |
toolbar := LayoutMorph newRow separation: 2.
Expand Down Expand Up @@ -506,7 +506,7 @@ installToolbar
setBalloonText: 'Redo the last play';
morphExtent: 32 asPoint.
toolbar addMorph: button.
self addMorph: toolbar layoutSpec: LayoutSpec new useMorphHeight
self addMorph: toolbar layoutSpec: LayoutSizeSpec new useMorphHeight
! !

!MemoryGameWindow class methodsFor: 'instance creation' stamp: 'hlsf 3/22/2025 15:37:23'!
Expand Down
Loading