Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reset a flex label width to "auto" after setting an explicit width?

Once I've set either the width or percentWidth property on a flex label, is there a way to reset the width to its default (i.e., the width of the text plus padding)?

I'm using the label as a renderer. In some cases, I'd like it to automatically size to the text, and in other cases, I'd like it to be a percentage width of its container. Obviously, I could use two separate labels, one for each of the above cases, but I'm curious if it's possible to reset the label to its default behavior.

like image 374
Sam Martin Avatar asked Oct 12 '09 14:10

Sam Martin


2 Answers

label.width = NaN;
//not sure if the following lines are required
label.invalidateSize();
label.width = label.measuredWidth;

From flex livedocs

When you set a specific height and width of a component, Flex does not call the measure() method, even if you explicitly call the invalidateSize() method. That is, Flex only calls the measure() method if the explicitWidth property or the explicitHeight property of the component is NaN.

like image 118
Amarghosh Avatar answered Sep 23 '22 06:09

Amarghosh


Set the width to undefined:

yourLabelId.width = undefined;

like image 42
Stefan Avatar answered Sep 23 '22 06:09

Stefan