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

H. Hirzel hannes.hirzel at gmail.com
Thu Mar 27 00:44:43 PDT 2025


Hi Weslleymberg,

On 27/03/2025 3:21 am, Weslleymberg Lisboa via Cuis-dev wrote:
> Hi, Hannes
>
> I'm no expert in image transformations, but as you are not the first 
> to report this same behavior [1], I'm somewhat confident that there is 
> a bug in ImageMorph>>#minimumExtent.

Thank you for the confirmation that you consider this as a bug and the 
proposal of a solution.

> What happens is that at the moment #minimumExtent does not take into 
> account the scaling factor we apply to the morph. So when we scale an 
> ImageMorph the minimum size allowed to it will be the original extent 
> of the image plus margin and padding.
>
> Attached is a screenshot showing what happens when we change 
> ImageMorph>>#minimumExtent. Both of the ImagemMorphs were created from 
> your example 2. The only difference is that I changed #minimumExtent 
> before creating the second one.
>
> 1 - 
> https://lists.cuis.st/mailman/archives/cuis-dev/2025-March/010688.html

Yes, changing the ImageMorph>>minimumExtent implementation is what you 
propose in the 'scaling an ImageMorph' thread.

https://lists.cuis.st/mailman/archives/cuis-dev/2025-March/010706.html

--------------------------------------------------------------------

Current ImageMorph>>minimumExtent

````
minimumExtent

     ^ image extent + (2 * self interiorOrigin)
````

-------------------------------------------------------------------------------------------


Your proposal for ImageMorph>>minimumExtent

````
minimumExtent

     ^ image extent + (2 * self interiorOrigin) * self scale

-------------------------------------------------------------------------------------------



My example 2 (unnecessary methods invocations removed so that problem is 
minimal) from the first mail in this thread works fine now! (Cuis 7.3 
latest update #7092)

Example picture

'20250326_coffee.jpg'

here

https://lists.cuis.st/mailman/archives/cuis-dev/attachments/20250326/bd015a5f/attachment-0001.jpg 



"[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.

   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;
       openInWorld

So I suggest that this method change should be made.

Kind regards

Hannes

>
> Em 26/03/2025 19:59, H. Hirzel via Cuis-dev escreveu:
>> 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."
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20250327/73467d9e/attachment.htm>


More information about the Cuis-dev mailing list