[Cuis-dev] How do I "pack" morphs?
Weslleymberg Lisboa
weslleym.lisboa at gmail.com
Wed Mar 26 19:21:05 PDT 2025
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.
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
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."
>
--
Wéslleymberg Lisboa
Graduado em Sistemas de Informação
Docente no IFFluminense - Campus Itaboraí
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ImageScalingMorph.png
Type: image/png
Size: 267495 bytes
Desc: not available
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20250326/9d6df9a3/attachment-0001.png>
-------------- next part --------------
'From Cuis7.3 [latest update: #7092] on 26 March 2025 at 10:49:36 pm'!
!ImageMorph methodsFor: 'drawing' stamp: 'wbsl 3/26/2025 22:17:04'!
minimumExtent
^ image extent + (2 * self interiorOrigin) * location scale! !
More information about the Cuis-dev
mailing list