I have a simple UIComponent that overrides measure and updateDisplayList to draw a vertical line. I've calculated the beginning and end of the line by taking into account the stroke width. The code is below. I am expecting the bounds to be printed as (x:0 y:0 w:1 h:300) but it prints (x:0 y:0 w:1 h:299) i.e. the height is 299 instead of 300. What am I missing?
override protected function measure():void
{
super.measure();
measuredWidth = measuredMinWidth = 300;
measuredHeight = measuredMinHeight = 300;
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
var stroke:SolidColorStroke = new SolidColorStroke(0xd8d8d8, 1, 1);
var g:Graphics = graphics;
g.clear();
var bX:Number;
var bY:Number;
var tX:Number;
var tY:Number;
var bW:Number;
var bH:Number;
bX = stroke.weight * 0.5;
bY = stroke.weight * 0.5;
tX = stroke.weight * 0.5;
tY = unscaledHeight - 1 - stroke.weight * 0.5;
bW = unscaledWidth - stroke.weight;
bH = unscaledHeight - stroke.weight;
trace ("From (", bX, ",", bY, ") To (", tX, ",", tY, ")");
stroke.apply(g, null, null);
g.moveTo(bX, bY);
g.lineTo(tX, tY);
trace ("Bounds:", getBounds(this));
}
Why do you use magical number → -1
? You have all as a parameters already. Change calculation for tY
:
tY = unscaledHeight - stroke.weight * 0.5;