Sunday, March 28, 2010

Tracking positions of...

Is there anyway to find out the x,y coordinates of a SpanElement, ParagraphElement or LinkElement as it scrolls in a scrollable TextArea?

Tracking positions of...

Probably although the question is a bit problematic.?Any element can cross column and container boundaries so its hard to say what is meant by x,y position.?Elements that are scrolled out of view may not even be composed.?

Let's assume you mean the x,y position of the first atom in the element.?Start with the following formula - this is psuedo code and there may be other errors so you'll have to some research:

0. force the entire textFlow to compose textFlow.flowComposer.composeToPosition() followed by textFlow.flowComposer.updateAllContainers()

1. find the elements absoluteStart.?elem.getAbsoluteStart()

2. find the TextFlowLine containing the position.?textFlow.flowComposer.findLineAtPosition()

3. get the actual TextLine. textFlowLine.getTextLine(true)

4. You'll need the charIndex which is relative to the owning paragraph elem.getAbsoluteStart()-elem.findParagraph().getAbsoluteStart()

5. Using that find the atom that maps to the atome textLine.getAtomIndexAtCharIndex()

6. get the atom bounds textLine.getAtomBounds

7. The bounds are relative to the TextLine.?Convert them to the container coordinate system (or whatever coordinate system you want).?For x and y you may want to use textFlowLine.x and textFlowLine.y instead of TextLine.?The TextLine returned may not actually be the one that's on the display list.

8. Note that the container may be scrolled.?Use the verticalScrollPosition, horizontalScrollPosition to adjust

Hope that helps,

Richard

No comments:

Post a Comment