Actually, it works this way in Flex 3 as well.  A difference may be that
MX containers have built-in scrollbars so in the MX version of your test
case you'd see scrollbars and scroll to see the rest of the component.

You're right that setting measuredMinWidth to measuredWidth is the key
factor, and basically a guess.  IIRC, it was done to keep components from
collapsing down to nothing and becoming impossible to find on the screen.
And if you do know a better number to use, you should override measure()
and set a better number.  And that's also why this only happens when using
percentages: it is only when things can shrink or grow that it is
important to not shrink to nothing.

And you're right that it isn't intuitive.  This is easily one of the top
10 most frequently asked questions.

But anyway, that's how it works, and setting minWidth to a better number
is usually part or all of the solution.

-Alex


On 12/11/13 10:30 AM, "BorekB" <bor...@gmail.com> wrote:

>Hm I guess you're right, Flex 4 probably always worked this way, I just
>somehow never hit this "issue" and in Flex 3 / MX layouts work as expected
>(for example, if you put anything inside a Canvas and set a width and
>height
>of that something to 100%, it will always have the width and height equal
>to
>the Canvas dimensions).
>
>After some stepping through the Flex 4 layout code, it seems that you are
>right that `minWidth` is to "blame" here. What seems intuitively strange
>to
>me are these two things:
>
>1) The layout (BasicLayout in this case but other layouts do this too)
>sets
>the `measuredMinWidth` to be equal to `measuredWidth`. First, this feels
>intuitively wrong (how can a generic layout class possibly know what the
>right minWidth for a specific contents should be?; the value of
>measuredWidth is just one of the possible guesses and it is not correct in
>many cases). What is for sure is that the measuredMinWidth, when it's too
>high, later causes all the trouble with layouts.
>
>2) This issue only happens when sizing is done using percent values or
>constraints (left, right etc.), all is OK when using absolute sizes. This
>really surprises me as I am not aware about any note in the documentation
>or
>anywhere that would say that using % instead of px would have such deep
>layout consequences. At least in Flex 3, you can set the size either way
>and
>they are just equivalent (I hope; I always took that as granted).
>
>I guess there is no way this could be changed after Flex 4 has been
>released
>so long ago but if anyone who maintains the documentation is reading this,
>it would be great if this behavior could be documented and possibly
>advised
>to use `minWidth` explicitly to overcome this issue if someone hits it.
>
>Thanks,
>Borek
>
>
>
>--
>View this message in context:
>http://apache-flex-development.2333347.n4.nabble.com/Spark-and-percent-wid
>th-unexpected-behavior-tp33190p33256.html
>Sent from the Apache Flex Development mailing list archive at Nabble.com.

Reply via email to