Layout policy ignored for morphs w/o submorphs... ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Layout policy ignored for morphs w/o submorphs... ?

marcel.taeumel (old)
Hi! :)

There is something strange going on in Morphic land considering layout policies and their rights. :D Consider this excerpt from Morph >> #doLayoutIn:

...
submorphs isEmpty ifTrue: [^fullBounds := priorBounds].
...

Okay, the policy has no chance because this is not called then:

...
layout := self layoutPolicy.
layout ifNotNil: [layout layout: self in: layoutBounds].
...

Furthermore, Morph >> #layoutBounds dares to preprocess #layoutInset (which will be stored in an instance of TableProperties ... ?!) like this:

| inset box |
inset := self layoutInset.
box := self innerBounds.
inset isZero ifTrue:[^box].
^ box insetBy: inset

Phew. Obviously, the TableLayoutPolicy should access a morph's layout inset during actual layout (i.e., #layout:in:).

My questions:

- Why should a morph keep its prior extent by default when having no submorphs?
- Can we (I^^) give layout policies more control about whether to layout even w/o submorphs?
- Can we (I^^) move #layoutInset processing to TableLayout?
- Can we (I^^) move code about proportional layouting from Morph to ProportionalLayout?

Best,
Marcel
Reply | Threaded
Open this post in threaded view
|

Re: Layout policy ignored for morphs w/o submorphs... ?

marcel.taeumel (old)
After a small discussion with Bert, I realized that you normally do layouting *only* for your submorphs. This is fine for #rigid and #spaceFill behavior because you need your owner's data to layout. However, #shrinkWrap, as it is currently implemented in a similar way, has nothing to do with your owner.

I vote for being able to implement #shrinkWrap behavior in your own layout policy:

| shrinkWrappedMorph |
shrinkWrappedMorph := Morph new layoutPolicy: ShrinkWrapLayout new.
shrinkWrappedMorph addMorph: Morph new.
shrinkWrappedMorph addMorph: Morph new.
shrinkWrappedMorph addMorph: Morph new.
self assert: shrinkWrappedMorph fullBounds = shrinkWrappedMorph submorphBounds.

As for now, this would be against the concept of layout policies and how they are implemented in Morph. We should anticipate such behavior and thus allow policies to work -- even w/o any submorph present.

As I look through TableLayout >> #layoutTopToBottom:in:, this is already happening:

| shrinkWrappedMorph |
shrinkWrappedMorph := Morph new layoutPolicy: TableLayout new.
shrinkWrappedMorph vResizing: #shrinkWrap; hResizing: #shrinkWrap.
shrinkWrappedMorph addMorph: Morph new.
shrinkWrappedMorph addMorph: Morph new.
shrinkWrappedMorph addMorph: Morph new.
self assert: shrinkWrappedMorph fullBounds = shrinkWrappedMorph submorphBounds.

You don't need a parent with a layout policy that realizes your shrinkWrap-behavior. Thus, there is no reason for a morph to prevent a policy from working when there is no submorph present.

Best,
Marcel