Maybe I'm misunderstanding you, but that's what the scaling's all
about. The content is as big as it's going to be, but instead of
scrolling we want it to scale down to fit if larger than its
container, and center if smaller. I kinda wish there was something
like ScrollPolicy.NONEBUTSCALE :)
Or perhaps you're re-stating what Michael said, in which case I
responded by adding measure and updateDisplayList implementations to
the holder, so now the content does get sized (as well as scaled), as
follows.
Thanks.
public class ScaleToFitContentHolder extends UIComponent
{
public var allowInvalidateSize:Boolean = true;
public var content:UIComponent;
public function ScaleToFitContentHolder()
{
}
override protected function measure():void
{
super.measure();
minWidth = measuredWidth =
content.getExplicitOrMeasuredWidth();
minHeight = measuredHeight =
content.getExplicitOrMeasuredHeight();
}
override public function invalidateSize():void
{
if (allowInvalidateSize)
super.invalidateSize();
}
override protected function
updateDisplayList(unscaledWidth:Number,
unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
content.setActualSize(unscaledWidth, unscaledHeight);
}
}
On Sun, Jun 1, 2008 at 10:08 PM, Alex Harui <[EMAIL PROTECTED]> wrote:
> Parents size their children (and sometimes their grandchildren) I don't see
> anyone actually sizing the content, just the contentHolder.
>
>
>
> ________________________________
>
> From: [email protected] [mailto:[EMAIL PROTECTED]
> On Behalf Of Richard Rodseth
> Sent: Saturday, May 31, 2008 2:31 PM
> To: [email protected]
> Subject: Re: [flexcomponents] Fwd: Center/Shrink To Fit
>
>
>
> I'd love to wrap up this task. Does anyone have any other suggestions?
>
> On Tue, May 27, 2008 at 8:24 PM, Richard Rodseth <[EMAIL PROTECTED]> wrote:
>> I'm afraid I'm still struggling with this. The classes below work
>> (more or less) if I supply a large button as "content", but if I try a
>> VBox it appears to shrink to nothing. Any ideas? Hopefully the
>> formatting survived.
>>
>> <view:ScaleOrCenterView width="100%" height="100%" >
>> <mx:VBox borderStyle="solid" borderColor="red"
>> horizontalScrollPolicy="off" verticalScrollPolicy="off">
>> <mx:Button label="Test" width="400" height="400"/>
>> </mx:VBox>
>> </view:ScaleOrCenterView>
>>
>>
>> [DefaultProperty("content")]
>> public class ScaleOrCenterView extends UIComponent
>> {
>> private var _contentHolder:ScaleToFitContentHolder = new
>> ScaleToFitContentHolder();;
>> private var _content:UIComponent;
>>
>> public function ScaleOrCenterView()
>> {
>> super();
>> }
>>
>> override protected function createChildren():void {
>> super.createChildren();
>> this.addChild(_contentHolder);
>> }
>>
>> [Inspectable]
>> public function set content(value:UIComponent):void {
>> if (_content != null) {
>> _contentHolder.removeChild(_content);
>> }
>> _content = value;
>> if (_content != null) {
>> _contentHolder.addChild(_content);
>> }
>> this.invalidateSize();
>> }
>>
>> override protected function updateDisplayList(unscaledWidth:Number,
>> unscaledHeight:Number):void
>> {
>> super.updateDisplayList(unscaledWidth, unscaledHeight);
>>
>> var contentWidth:Number = _content.getExplicitOrMeasuredWidth();
>> var contentHeight:Number = _content.getExplicitOrMeasuredHeight();
>>
>> var xScale:Number = (unscaledWidth / contentWidth);
>> var yScale:Number = (unscaledHeight / contentHeight);
>>
>> _contentHolder.setActualSize(unscaledWidth, unscaledHeight);
>>
>> _contentHolder.allowInvalidateSize = false;
>> if (xScale < 1 || yScale < 1) {
>> _contentHolder.scaleX = xScale
>> _contentHolder.scaleY = yScale
>> } else {
>> _contentHolder.scaleX = 1.0;
>> _contentHolder.scaleY = 1.0;
>> }
>> _contentHolder.allowInvalidateSize = true;
>>
>> }
>>
>> }
>>
>> public class ScaleToFitContentHolder extends UIComponent
>> {
>> public var allowInvalidateSize:Boolean = true;
>>
>> public function ScaleToFitContentHolder()
>> {
>> }
>>
>> override protected function measure():void
>> {
>> super.measure();
>> }
>>
>> override public function invalidateSize():void
>> {
>> if (allowInvalidateSize)
>> super.invalidateSize();
>> }
>>
>> }
>> On Mon, May 26, 2008 at 9:02 PM, Alex Harui <[EMAIL PROTECTED]> wrote:
>>> One way is to block invalidateSize when scaling the child. See
>>> ListBaseContentHolder
>>>
>>>
>>>
>>> ________________________________
>>>
>>
>
>