You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@flex.apache.org by kamcknig <ka...@gmail.com> on 2016/10/18 19:14:44 UTC

Can't get custom component to size down properly

Hey everyone,

I'm porting a project over to RobotLegs and I had a huge issue of the
components not properly resizing. It has taken me almost two weeks but I've
finally narrowed it down to one (hopefully) component causing all of the
issues.

I have boiled it down to a simple test project.

In my test I have an App class and a MainView class. MainView is a child of
App. I have ResizeEvent.RESIZE listeners on both App and MainView. With just
this, I get trace statements from the resize handlers BOTH when sizing up
and when sizing down.  This is expected. If I add my custom component as a
child of MainView, then I will get the resize handlers traced out when
sizing UP but not when sizing DOWN. So the custom component will grow but
will never shrink. I'm not great when it comes to custom components as I was
a pure AS3 person. 

I have attached the project as a zip file. The problem component is called
BackgroundFill. It's a Group that contains a Rect that gets created and
resized. I noticed that when sizing up both updateDisplayList() and
measure() get called, but when sizing down, neither of them do.

test.zip
<http://apache-flex-users.2333346.n4.nabble.com/file/n13841/test.zip>  

Thanks for any help!



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Can-t-get-custom-component-to-size-down-properly-tp13841.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: Can't get custom component to size down properly

Posted by kamcknig <ka...@gmail.com>.
Never mind, I was able to figure it out by doing this:





--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Can-t-get-custom-component-to-size-down-properly-tp13841p13858.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: Can't get custom component to size down properly

Posted by kamcknig <ka...@gmail.com>.
Oh my! You did it! Thanks so much!

Sorry though, how would I set the width and height of the Rect to the width
and height a user might set on the component? I tried setting
_fillRect.width/height within the updateDisplayList() override method
instead of setting the top/right/bottom/left in the createChildren() method
but that breaks it.



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Can-t-get-custom-component-to-size-down-properly-tp13841p13857.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: Can't get custom component to size down properly

Posted by Clint M <cm...@gmail.com>.
Does this work for you?

<?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
width="100%"
height="100%">
<fx:Script>
<![CDATA[
import mx.graphics.GradientEntry;
import mx.graphics.LinearGradient;
import mx.graphics.SolidColor;
import mx.graphics.SolidColorStroke;
import spark.primitives.Rect;
public var traceWidth:Boolean = false;
private var needsUpdate:Boolean;

public var _fillRect:Rect;
private var _solidStrokeColor:SolidColorStroke;
private var _linearGradient:LinearGradient;
private var _gradientEntry1:GradientEntry;
private var _gradientEntry2:GradientEntry;

private var _radiusX:int = 0;
public function set radiusX(value:int):void
{
_radiusX = value;
needsUpdate = true;
invalidateProperties();
}

private var _radiusY:int = 0;
public function set radiusY(value:int):void
{
_radiusY = value;
needsUpdate = true;
invalidateProperties();
}

private var _gradientRotation:int = 90;
public function set gradientRotation(value:int):void
{
_gradientRotation = value;
needsUpdate = true;
invalidateProperties();
}

private var _gradientFill01:uint = 0xEFEFEF;
public function get gradientFill01():uint
{
return _gradientFill01;
}
public function set gradientFill01(value:uint):void
{
_gradientFill01 = value;
needsUpdate = true;
invalidateProperties();
}

private var _gradientFill02:uint = 0xEFEFEF;
public function get gradientFill02():uint
{
return _gradientFill02;
}
public function set gradientFill02(value:uint):void
{
_gradientFill02 = value;
needsUpdate = true;
invalidateProperties();
}

private var _gradientFill01Alpha:Number = 1;
public function get gradientFill01Alpha():Number
{
return _gradientFill01Alpha;
}
public function set gradientFill01Alpha(value:Number):void
{
_gradientFill01Alpha = value;
needsUpdate = true;
invalidateProperties();
}

private var _gradientFill02Alpha:Number = 1;
public function get gradientFill02Alpha():Number
{
return _gradientFill02Alpha;
}
public function set gradientFill02Alpha(value:Number):void
{
_gradientFill02Alpha = value;
needsUpdate = true;
invalidateProperties();
}

private var _strokeColor:uint = 0xEEEEEE;
public function get strokeColor():uint
{
return _strokeColor;
}
public function set strokeColor(value:uint):void
{
_strokeColor = value;
needsUpdate = true;
invalidateProperties();
}

private var _strokeAlpha:Number = 1;
public function get strokeAlpha():Number
{
return _strokeAlpha;
}
public function set strokeAlpha(value:Number):void
{
_strokeAlpha = value;
needsUpdate = true;
invalidateProperties();
}

private var _strokeWeight:Number = 1;
public function get strokeWeight():Number
{
return _strokeWeight;
}
public function set strokeWeight(value:Number):void
{
_strokeWeight = value;
needsUpdate = true;
invalidateProperties();
}

private var _trbl:Object = { t:0, r:0, b:0, l:0 };
public function set trbl(value:Array):void
{
if(!isNaN(value[0]))
{
_trbl.t = value[0];
}

if(!isNaN(value[1]))
{
_trbl.r = value[1];
}

if(!isNaN(value[2]))
{
_trbl.b = value[2];
}

if(!isNaN(value[3]))
{
_trbl.l = value[3];
}
needsUpdate = true;
invalidateProperties();
}

override protected function createChildren():void
{
super.createChildren();
_fillRect = new Rect();
_fillRect.left = _fillRect.right = _fillRect.top = _fillRect.bottom = 0;
_fillRect.fill = new SolidColor(0xFF0000);
_fillRect.stroke = new SolidColorStroke(0x00FF00,2);
addElement(_fillRect);
}
override protected function commitProperties():void {
super.commitProperties();
if(needsUpdate) {
needsUpdate = false;
try {
_linearGradient = new LinearGradient();
_gradientEntry1 = new GradientEntry(_gradientFill01, 0,
_gradientFill01Alpha);
_gradientEntry2 = new GradientEntry(_gradientFill02, .5,
_gradientFill02Alpha);
_linearGradient.entries = [_gradientEntry1, _gradientEntry2];
_linearGradient.rotation = _gradientRotation;
_fillRect.fill = _linearGradient;
_fillRect.radiusX = _radiusX;
_fillRect.radiusY = _radiusY;
_solidStrokeColor = new SolidColorStroke(_strokeColor, _strokeWeight,
_strokeAlpha);
_fillRect.stroke = _solidStrokeColor;
invalidateDisplayList();
} catch (e:Error) {
trace(e.message);
}
}
}
override protected function updateDisplayList(unscaledWidth:Number,
unscaledHeight:Number):void {
super.updateDisplayList(unscaledWidth, unscaledHeight);
}
]]>
</fx:Script>
</s:Group>


On Tue, Oct 18, 2016 at 12:31 PM, kamcknig <ka...@gmail.com> wrote:

> I think it has something to do with the fact that I'm setting the
> measuredMinWidth in the measure() method. So when sizing down, it's looking
> at the measuredMinWidth and it can't size it down below that. But if I take
> that out then my app runs forever. And continues to grow in width/height
> non-stop and i have to end the process to get it to stop updating
>
>
>
> --
> View this message in context: http://apache-flex-users.
> 2333346.n4.nabble.com/Can-t-get-custom-component-to-size-
> down-properly-tp13841p13842.html
> Sent from the Apache Flex Users mailing list archive at Nabble.com.
>

Re: Can't get custom component to size down properly

Posted by kamcknig <ka...@gmail.com>.
I think it has something to do with the fact that I'm setting the
measuredMinWidth in the measure() method. So when sizing down, it's looking
at the measuredMinWidth and it can't size it down below that. But if I take
that out then my app runs forever. And continues to grow in width/height
non-stop and i have to end the process to get it to stop updating



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Can-t-get-custom-component-to-size-down-properly-tp13841p13842.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.