ActionsDev
4 replies to this thread. Most Recent
waltd
24 Jun 2008, 3:27 am
How to get absolute X/Y coordinates of an item
It’s easy to parse the style tag of an item and read its top and left properties if it’s a layer. But this method falls down if the item in question is grouped or otherwise nested within another object, or if it is not a layer.
Is there any way to get the geometry of a fwItem with respect to the page itself, ignoring any parents?
Thanks,
Walter
Freeway user since 1997
waltd
24 Jun 2008, 5:13 pmAnswering my own question…
Here’s a partial solution. I haven’t tested to see what it does on a non-layer item, it might work.
This is a recursive function that creates a pair of dummy variables on the item, and then walks up the tree to find the cumulative offset from 0,0. The return value is an array of (top,left) as integers.
function getPosition(item){
if(!item['_top']) item['_top'] = item.fwTop;
if(!item['_left']) item['_left'] = item.fwLeft;
if(item.fwParent){
var p = item.fwParent;
if(p.toString().indexOf("PageDiv") < 0){
p['_top'] = item._top + p.fwTop;
p['_left'] = item._left + p.fwLeft;
return getPosition(p);
}
}
return [item._top,item._left];
}
This feels sort of hacky to me, it would be nice if Freeway would just tell us this directly without so much introspection. I stand ready to be told that there’s an undocumented property like fwItem.fwAbsTop hiding in there somewhere…
Walter
Freeway user since 1997
Joe Muscara
24 Jun 2008, 8:36 pmSince the inspector doesn’t even show you the absolute location of the item, I wonder if it’s even “recorded” anywhere in Freeway. To my mind, the absolute coordinates should be in the “Screen Measurements” area, and the relative positioning under “Dimensions” if it’s a child item.
Here’s something related that’s strange. I drew an HTML item on the page, then drew a child HTML item inside it. While I was drawing the child item, the X and Y coords were the absolute value on the page. As soon as I was finished drawing, both sets of X/Y coords popped to show the relative location.
Joe Muscara
Freeway Actions and more t2studios.com/freeway
alan
30 Jun 2008, 2:37 pmHi,
The top/left was introduced in Freeway 3 (as I remember) and when we moved to nested items it returns the relative co-ordinates.
Alan
waltd
30 Jun 2008, 2:47 pmSo could the “real” top/left please stand up in Freeway 5? As Joe pointed out, it is known to Freeway up until the moment the mouse cursor is released on a draw. Does anyone else need this, or am I alone in wanting to “absolutize” elements at whim inside an Action?
Walter
On Jun 30, 2008, at 10:37 AM, alan wrote:
Hi,
The top/left was introduced in Freeway 3 (as I remember) and when we moved to nested items it returns the relative co-ordinates.
Alan
Freeway user since 1997