|Getting width of text [message #1066432]
||Tue, 02 July 2013 11:56
| Albert Hofkamp
Registered: August 2009
First of all, I really like your tutorial, the pattern to build features becomes very clear with it.|
The main things still causing a lot of confusion for me are the "PictogramElement", "ContainerShape", "Shape", and in particular the "GraphicsAlgorithm" concepts and how they relate.
To me, an algorithm is a function to calculate something (ie the usual computer science notion), while "Text" or "Rectangle" feels like an object rather than a function to compute something.
On to my question.
In the tutorial, the add feature does
to set the width of the displayed text. For longer text however, a fixed length is not working, I want the graphical elements to adjust to the width needed by the text to get it fully displayed instead.
int width = 100;
Text text = gaService.createText(shape, addedClass.getName());
gaService.setLocationAndSize(text, 0, 0, width, 20);
I have been trying to get the width of the text from the system.
would seem the obvious solution, but I either get (0,0) (before setting width/height) or my previously set width/height, instead the minimally required width of the text to get it fully displayed.
IDimension dim = gls.calculateSize(text);
Querying before or after first rendering does not seem to make any difference, so I have run out of ideas how to do this.
In other words, how do I retrieve the natural width of a text so I can use that to decide the size of my graphical elements?
Powered by FUDForum
. Page generated in 0.01990 seconds