I'm trying to create a lightweight component (extends UIComponent) that supports auto-sizing (aka default sizing.) Many of the Flex component's do this, for instance mx:Button will, if you do not set a size, size itself to be "large enough to hold the label text, and any icon." How can I do this with my component?
I tried overriding measure() and setting the measured sizes (measuredWidth, measuredHeight, measuredMinWidth, measuredMinHeight) but updateDisplayList always gets called with values of 0, 0 for unscaledWidth and unscaledHeight, and the .width and .height properties always stay at 0, 0.
I've looked over the mx:Button code quite a bit and cannot figure out how it manages to perform default/auto-sizing. Can anyone help?
Yes measure() gets called and the measured values are set to the expected values by the time updateDisplayList() gets called. I never set the explicitWidth/Height (or the width/height), so if it's set to 0,0 that would be done by the Flex framework somewhere... which I would have thought it would set it to measuredMinWidth/Height at the least?
You could set breakpoints to see if explicitWidth/Height is getting set in some surprising way. Could maxWidth/maxHeight be set to 0? That could also mess it up.
One more thing is that the component is given its size by its parent. If the parent is 0x0 that could also cause trouble. Or some other part of the layout logic is trumping the measuredWidth/Height. In theory there should be a call to setActualSize or setLayoutBoundsSize. A breakpoint there should help you figure out the logic that determined the size.