[Pharo-project] Making layouts using anchors
siguctua at gmail.com
Fri Apr 8 10:41:47 CEST 2011
On 8 April 2011 09:41, Fernando Olivero <fernando.olivero at usi.ch> wrote:
> In the current LayoutPolicy scheme there's no knowledge between the
> brothers, for the anchors this would present a potential problem.
> What about moving this dependency to the parent, which knows all the
> morphs, instead of introducing this knowledge in the brothers?
> In your example:
> window anchorMorph: morph at: left
> window anchorMorph: morph2 rightTo: morph.
Well, in the above you expressed same relationship just using different terms.
You still want morph2 to align to right edge of morph. And for you, as
a UI designer,
it doesn't really matters where framework keeps this information - in
parent morph or in morph itself.
You just want morphs to obey specified rules, right?
> Then it would be transparent to the current LayoutPolicy scheme, and
> IMO the responsibilities are better distributed.
> Eliminating the knowledge between brothers greatly simplifies the UI framework.
You can't eliminate such knowledge, otherwise you won't be able to
maintain such kind of relationship between morphs.
You may encode it using different means, but still as i said, if you
want such kind of relationship,
then you have to put this dependency "knowledge" somewhere.
I prefer that morph controlling own layout by himself (parent could
instruct child morph to follow specific layout,
but the final decision where to put itself should be up to morph iself).
Because, for example, if you let parent to control the bounds of its
child morphs, then you have a problem.
Suppose that you have a string morph, which knows that he has fixed
width and height,
but its positioning could be arbitrary.
So, you setting either right or left anchor:
stringMorph anchorLeft: window leftAnchor.
stringMorph anchorRight: window rightAnchor.
but not both, because morph could calculate the opposite edge based on
its own width.
Or, maybe you could do that..
You could set things up like following:
| leftAnchor |
leftAnchor := window leftAnchor + 10.
stringMorph anchorLeft: leftAnchor.
stringMorph anchorRight: leftAnchor + stringMorph widthAnchor
then in this case, a position of morph is controlled by its parent,
while width is maintained by himself.
(a morphs which know that they having rigid width or height
properties, could simply override
widthAnchor/heightAnchor and maintain own constraints in this way).
Igor Stasenko AKA sig.
More information about the Pharo-project