Sorry folks. One more time with attachment renamed to foil the filters. On Wed, Sep 3, 2008 at 10:28 AM, Richard Rodseth <[EMAIL PROTECTED]> wrote:
> Cross-posting to flexcoders... > > > On Wed, Sep 3, 2008 at 9:34 AM, Richard Rodseth <[EMAIL PROTECTED]>wrote: > >> On Tue, Sep 2, 2008 at 9:51 PM, Alex Harui <[EMAIL PROTECTED]> wrote: >> >>> If you post a test case, I might get a chance to look at it >>> . >>> sdf >>> >> >> Thanks, that would be great. A Flex project archive is attached, and the >> complete code is also below. There's an HBox with two instances of the >> ScaledContent component. The button on the right scales and centers >> properly. The one on the left doesn't. >> >> TestScaledContent.mxml >> >> <?xml version="1.0" encoding="utf-8"?> >> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" >> layout="vertical" >> xmlns:comp="comp.*" >> > >> <mx:HBox width="90%" height="90%" borderStyle="solid"> >> <comp:ScaledContent width="50%" height="100%" borderStyle="solid" >> > >> <mx:Button label="This is a button" /> >> </comp:ScaledContent> >> <comp:ScaledContent width="50%" height="100%" borderStyle="solid" >> > >> <mx:Button label="This is a button" width="1400" >> height="1400" cornerRadius="100"/> >> </comp:ScaledContent> >> </mx:HBox> >> >> </mx:Application> >> >> >> ScaledContent.mxml: >> >> <?xml version="1.0" encoding="utf-8"?> >> <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:comp="comp.*" >> horizontalScrollPolicy="off" verticalScrollPolicy="off" >> > >> >> <mx:Metadata> >> [DefaultProperty("contents")] >> </mx:Metadata> >> >> <mx:Script> >> <![CDATA[ >> import mx.core.UIComponent; >> >> private var _contents:UIComponent; >> private var _contentsChanged:Boolean = false; >> >> public function set contents(value:UIComponent):void { >> _contents = value; >> _contentsChanged = true; >> this.invalidateProperties(); >> } >> >> override protected function commitProperties():void { >> super.commitProperties(); >> >> if (_contentsChanged) { >> contentHolder.content = _contents; >> _contentsChanged = false; >> } >> } >> >> >> override protected function measure():void { >> super.measure(); >> minWidth = measuredWidth = 0; // >> _contents.getExplicitOrMeasuredWidth(); >> minHeight = measuredHeight = 0; // >> _contents.getExplicitOrMeasuredHeight(); >> } >> >> override protected function >> updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void { >> super.updateDisplayList(unscaledWidth, unscaledHeight); >> contentHolder.scaleContentToFit(unscaledWidth, >> unscaledHeight); >> contentHolder.setActualSize(unscaledWidth, >> unscaledHeight); >> } >> ]]> >> </mx:Script> >> >> <comp:ScaledContentHolder id="contentHolder" width="100%" >> height="100%"> >> </comp:ScaledContentHolder> >> >> </mx:Canvas> >> >> ScaledContentHolder.as: >> >> package comp >> { >> import mx.core.Container; >> import mx.core.UIComponent; >> >> >> public class ScaledContentHolder extends UIComponent >> { >> public function ScaledContentHolder() >> { >> } >> >> private var _allowInvalidateSize:Boolean = true; >> private var _content:UIComponent; >> private var _contentChanged:Boolean = false; >> >> override protected function measure():void >> { >> super.measure(); >> minWidth = measuredWidth = 0; // >> _content.getExplicitOrMeasuredWidth(); >> minHeight = measuredHeight = 0; >> //_content.getExplicitOrMeasuredHeight(); >> } >> >> public function set content(value:UIComponent):void { >> _content = value; >> _contentChanged = true; >> this.invalidateProperties(); >> } >> >> override protected function commitProperties():void { >> super.commitProperties(); >> if (_contentChanged) { >> this.removeAllChildren(); >> this.addChild(_content); >> _contentChanged = false; >> } >> } >> >> >> private function removeAllChildren():void >> { >> while (numChildren> 0) >> { >> removeChildAt(0); >> } >> } >> >> >> override public function invalidateSize():void >> { >> if (_allowInvalidateSize) >> super.invalidateSize(); >> } >> >> public function scaleContentToFit(unscaledWidth:Number, >> unscaledHeight:Number):void { >> var contentWidth:Number = >> _content.getExplicitOrMeasuredWidth(); >> var contentHeight:Number = >> _content.getExplicitOrMeasuredHeight(); >> >> var xScale:Number = (unscaledWidth / contentWidth); >> var yScale:Number = (unscaledHeight / contentHeight); >> var finalScale:Number = Math.min(xScale, yScale); // Preserve >> aspect ratio >> >> _allowInvalidateSize = false; >> this.scaleX = finalScale; >> this.scaleY = finalScale; >> _allowInvalidateSize = true; >> >> var scaledContentWidth:Number = contentWidth * finalScale; >> var scaledContentHeight:Number = contentHeight * finalScale; >> >> this.move(unscaledWidth/2 - scaledContentWidth/2 , >> unscaledHeight/2 - scaledContentHeight/2); >> >> } >> >> override protected function >> updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void >> { >> super.updateDisplayList(unscaledWidth, unscaledHeight); >> } >> } >> >> } >> > >
TestScaledContent.zp
Description: Binary data