Squeak
  links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
How do I center a child morph object within the parent object?
Last updated at 8:36 am UTC on 14 January 2022
Open a Workspace and paste the following code into it.

 parent := Morph new.
 parent extent: 480@320.
 parent color: Color white.
 parent borderWidth: 50.
 parent borderColor: Color lightBlue.

 child := EllipseMorph new.
 child color: Color red.
 child extent: 180@180.
 child borderWidth: 0.

 parent addMorph: child.

 "CENTER THE CHILD MORPH"
 child center: parent center.

 parent openInHand

Select the code and choose do-it.
RedEllipseMorphCenteredInRectangleMorph.png

In Cuis


 parent := BorderedRectMorph new.
  parent morphExtent: 480@320.
  parent color: Color white.
  parent borderWidth: 50.
  parent borderColor: Color lightBlue.
 
  child := EllipseMorph new.
  child color: Color red.
  child morphExtent: 180@180.
  child borderWidth: 0.
 
  parent addMorph: child.

  "CENTER THE CHILD MORPH"
  child referencePosition: parent referencePosition.
 
  parent openInHand

For an application of #center: method see A4 and A3 sheets in Morphic.

tagBeginner