[squeak-dev] Morphic equivalent of 'display: none'?

Stéphane Rollandin lecteur at zogotounga.net
Fri Apr 3 15:48:16 UTC 2020


> #show/#hide/#visible: reserve space for the hidden morph. However, there 
> are other scenarios where you do not want to reserve space. (A simple 
> example would be a list that should only appear iff it has items.)

You could have such a "removed morph" temporarily #become: a collapsed 
representation (like a flat invisible morph for a list item), and then 
swap it back when you need it. I have used that pattern; #become: is fast.

> 
> In JS, you can use 'display: none' instead of 'visibility: hidden' to 
> give the space back to the element's remaining siblings.
> 
> But in Morphic, is there currently any better option than #delete (and 
> #addMorph:) later?
> 
> 
> (IMO, delete'n'add is not always the best pattern to do this. You 
> need to remember the index and owner of the relevant morph for adding it 
> later.)
> 
> 
> Provided that I did not overlook any existing features, would you 
> consider this a useful extension for Morphic?

No. I think this should be implemented either via specific mophs or via 
specific layout (probably yet to be invented).

> 
> I was thinking of a property (#skipLayout, if you do not have any better 
> idea) and a convenience method (#nonSkippedSubmorphs) that 
> rejects suppressed submorphs. TableLayout would need to use this 
> selector instead of regular #submorphs.
> 
> Or would this break too many existing things that rely on #submorphs?

Oh, yes, please do not add any logic to #submorphs. It is a plain array 
and a lot of things rely on this. You can implement a wrapper Morph with 
all that logic, instead.

> 
> 
> Another approach would be a selector in the TableLayoutProperties 
> to have all submorphs skipped that are hidden via classical #visible. 
> But this would be less powerful as you couldn't combine both kinds of 
> hiding in the same morph. But maybe this would be even better in terms 
> of avoiding complexity?

Not a good idea IMO to use a property tag to represent another property. 
#visible should just be about visibility.

Best,

Stef


More information about the Squeak-dev mailing list