Below is code for a scrolling container of one child - a highly
simplified version of the tiling container I've been wrestling with
off and on for way too long now. The component below sizes the
first/only child to fit within it, with some padding, but respects the
minimums of the child, adding scroll bars if necessary.

I discovered this evening that setting measuredMinWidth/Height in the
measure() method was what was messing things up. With that removed,
this component (and the more complex tiler) behaves properly, except
that the scollbars are drawn over the right/bottom padding.

What is the appropriate way to compensate for that? Adding a fudge
factor to the measured values, or removing it from the value passed to
setActualSize in UDL had no effect at all.

Thanks, I'm *really* close now...

- Richard


        public class MyContainer extends Container
        {
                private static const PADDING:Number = 10;
                
                public function MyContainer()
                {
                        super();
                }
                                
                
                override protected function measure():void
                {
                        var child:UIComponent = this.getChildren()[0] as 
UIComponent;
                        
                        var childWidth:Number = 
child.getExplicitOrMeasuredWidth();
                        var childHeight:Number = 
child.getExplicitOrMeasuredHeight();
                                                                
                        measuredWidth = childWidth + 2 * PADDING ;
                        measuredHeight = childHeight + 2 * PADDING ;
                }
                
        
                override protected function 
updateDisplayList(unscaledWidth:Number,
unscaledHeight:Number):void
                {
                super.updateDisplayList(unscaledWidth, unscaledHeight);
                
                var child:UIComponent = this.getChildren()[0] as UIComponent;
                                                        
                        var newWidth:Number = Math.max(unscaledWidth - (2 * 
PADDING) ,
child.minWidth);
                        var newHeight:Number = Math.max(unscaledHeight - (2 * 
PADDING) ,
child.minHeight);
                        
                child.setActualSize(newWidth, newHeight);
                child.move(PADDING, PADDING);
        }
        }
}

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
        layout="absolute" minHeight="0" minWidth="0"
        verticalScrollPolicy="off" horizontalScrollPolicy="off"
        xmlns:comp="comp.*"
        >

        <comp:MyContainer  width="95%" height="95%" borderStyle="solid"
horizontalScrollPolicy="auto" verticalScrollPolicy="auto">
                <mx:Button label="400x400" minWidth="400" minHeight="400"/>
        </comp:MyContainer>

</mx:Application>

Reply via email to