[Cuis-dev] How do I "pack" morphs?

H. Hirzel hannes.hirzel at gmail.com
Wed Mar 26 16:14:14 PDT 2025


P.S. Maybe the answer is that scaling image morphs should be avoided.

If I remove the scaling of the morph it works fine

````

labelMorph := LabelMorph new
    contents: 'coffee';
    color: Color red;
    padding: 0.


  aForm := Form fromFileEntry: '20250326_coffee.jpg' asFileEntry.

aForm := aForm shrink: aForm boundingBox by: 1.5.

  imageMorph := ImageMorph newWith: aForm.
  imageMorph
     borderWidth: 20;
     borderColor: Color black;
     "scaleBy: 0.2;    <<<<<<< REMOVED"
     padding: 0.

  layoutMorph := LayoutMorph newColumn
      borderWidth: 2;
      borderColor: Color yellow;
      padding: 0;
      separation: 0;
      addMorph: labelMorph;
      addMorph: imageMorph;
      "morphExtent: 300 at 300;"
      openInWorld
````




On 26/03/2025 11:59 pm, H. Hirzel wrote:
> Hi
>
> I have a question related to the 'scaling morphs' discussion.
>
> Scaling a form and then opening it as an image morph works fine, see 
> [1a],[1b] and attachment '2025-03-25_scaling_a_form.gif' with example 
> image '20250326_coffee.jpg'.
>
> However if I add an image morph to a layout morph the layout morph 
> does not "shrink" to the necessary size given by the submorphs and I 
> did also not find which message I need to send to the layout morph or 
> which LayoutSpec to add to the submorphs. [2] and attachment 
> '2025-03-25_Adding_an_image_morph_to_a_layout'.
>
> What am I missing here, maybe it is something obvious?
>
> Additional question: what is the first argument of the #shrink:by: 
> message for?
>
> Kind regards
>
> Hannes
>
> -----------------------------
>
> "[1a] no scaling of Form object"
>
>  aForm := Form fromFileEntry: '20250326_coffee.jpg' asFileEntry.
>
>
>  imageMorph := ImageMorph newWith: aForm.
>  imageMorph
>     borderWidth: 20;
>     borderColor: Color white;
>     scaleBy: 0.2;
>     padding: 0.
>
> imageMorph openInWorld
>
>
> "[1b] scaling of Form object"
>
>  aForm := Form fromFileEntry: '20250326_coffee.jpg' asFileEntry.
>
>
> aForm := aForm shrink: aForm boundingBox by: 1.5.
>
>  imageMorph := ImageMorph newWith: aForm.
>  imageMorph
>     borderWidth: 20;
>     borderColor: Color black;
>     scaleBy: 0.2;
>     padding: 0.
>
> imageMorph openInWorld
>
>
> [2] Adding a LabelMorph and an ImageMorph object to a LayoutMorph object.
>
> labelMorph := LabelMorph new
>    contents: 'coffee';
>    color: Color red;
>    padding: 0.
>
>
>  aForm := Form fromFileEntry: '20250326_coffee.jpg' asFileEntry.
>
> aForm := aForm shrink: aForm boundingBox by: 1.5.
>
>  imageMorph := ImageMorph newWith: aForm.
>  imageMorph
>     borderWidth: 20;
>     borderColor: Color black;
>     scaleBy: 0.2;
>     padding: 0.
>
>  layoutMorph := LayoutMorph newColumn
>      borderWidth: 2;
>      borderColor: Color yellow;
>      padding: 0;
>      separation: 0;
>      addMorph: labelMorph;
>      addMorph: imageMorph;
>      "morphExtent: 300 at 300;"
>      openInWorld
>
> "changing the morph extent seems to have any effect on the morphExtent 
> of the layoutMorph."


More information about the Cuis-dev mailing list