In draw2d, how do you align text about a point? [message #241166] |
Thu, 31 January 2008 22:09 |
Eclipse User |
|
|
|
Originally posted by: aebeytin.yahoo.com
Hi all,
How do you add text to a figure that is aligned around a point? More specifically: I have text and I have an x,y point, but I want the text to have its horizontal (and possibly vertical) center (or possibly right edge) at that point.
My only successful attempt at this so far used an org.eclipse.draw2d.Label, initially positioned at 1,1 inside its containing Figure. Then, a thread was set up to watch it and calculate its correct upper-left-hand corner once it had a known size so that it would be centered around the intended point. This approach caused the text to originally appear in the corner on the creation and each resize of the window, not to mention the overhead of running an extra thread to watch it and all other similar Labels in the Figure. I can't calculate the point earlier because the Label's getSize() method returns an object with zero width and height unless the Figure has already been rendered.
There must be a better solution. Thanks for your help!
Adam
|
|
|
|
Re: In draw2d, how do you align text about a point? [message #241188 is a reply to message #241178] |
Fri, 01 February 2008 21:17 |
Eclipse User |
|
|
|
Originally posted by: aebeytin.yahoo.com
Thanks for the help!
I have extended org.eclipse.draw2d.RectangleFigure with a "TextRectangle" that takes a String, an xy point, and a horizontal/vertical alignment. I replaced outlineShape() with an empty function, and I replaced fillShape() with a function that creates a TextLayout and uses its getBounds() function to calculate the correct offsets horizontally and vertically before calling graphics.drawTextLayout(). It works perfectly!
Thanks again,
Adam
|
|
|
Powered by
FUDForum. Page generated in 0.02939 seconds