[Cuis-dev] adding a morph to start of LayoutMorph

Mark Volkmann r.mark.volkmann at gmail.com
Sat Aug 10 16:45:59 PDT 2024


On Sat, Aug 10, 2024 at 12:18 PM <ken.dickey at whidbey.com> wrote:

> On 2024-08-09 17:54, Mark Volkmann via Cuis-dev wrote:
>
> > I want to add a morph as the first submorph in a LayoutMorph that
> > already has submorphs.
> > I thought the addMorphFront: method would do that, but it doesn't.
>
> No.  addMorph{,Front,Back}: work with Z-Order (drawn back to front), not
> morphPosition.
>
> Comments in the code indicate morphs are always added to the
> right/bottom.
>
> As LayoutMorphs are typically setup in code when a window/panel is
> initialized, no one has asked for a convenience function to specify
> where you want a submorph in left-to-right/top-to-bottom spatial order.
>
> In writing code to do this you should learn about how submorphs are
> managed.
>

Okay, I did a deeper dive into the code and discovered the following:

LayoutMorph addMorph: calls
LayoutMorph addMorphFront: which calls
Morph addMorphFront: which calls
Morph privateAddMorph:atIndex: (with 1 for atIndex:) which calls
Morph privateAddMorph:atIndex:position: (with nil for position:)
This replaces the submorphs array with a new array where the morph being
added is added at the beginning of the new array.
It's not clear to me yet when adding it there is better than adding it at
the end.

For a vertical LayoutMorph, LayoutMorph layoutSubmorphs calls LayoutMorph
layoutSubmorphsVerticallyIn:.
That iterates over the visible morphs in reverse order (from first added to
last added)
and assigns a position to each visible submorph.
Here is where I don't get the claim that addMorphFront and addMorphBack are
all about Z-order.
>From this code, for a vertical LayoutMorph, those methods seem to be all
about Y-order
since they control the order of the submorphs array
and that is used to assign y coordinates to each of the submorphs.

The main thing I learned is that if you want to add a morph to a vertical
LayoutMorph
and you want it to appear at the beginning of the vertical list of morphs,
you need to use addMorphBack:.
That last bit is what I was looking for all along.

-- 
R. Mark Volkmann
Object Computing, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20240810/0cea1143/attachment.htm>


More information about the Cuis-dev mailing list