CEGUI::TextItem problems

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

User avatar
davesh
Not too shy to talk
Not too shy to talk
Posts: 36
Joined: Fri Feb 03, 2006 22:59

CEGUI::TextItem problems

Postby davesh » Fri Feb 23, 2007 18:38

I'm creating a GUI programatically. In general I'm able to create and place widgets where I want them. I am having difficulties placing CEGUI::TextItems.

Assuming that I have just created the TextItem and have a pointer to it textItem, then I immediately set its text using setText:

Code: Select all

textItem->setText("Hi");

I subsequently try to get the size (in pixels) of this text using

Code: Select all

int width = textItem->getWidth();

The width shows up as 0, in spite of the fact that the text is not zero length. I have tried various things to force the textItem to compute its width, but this does not seem to work. What is the proper way to initialize the text item (so that it has the appropriate width/height? Do I have to call textItem->setWidth(), if so what mechanism is in place for me to compute the width given the text string "Hi"?

I'm using CEGUI with Ogre. I believe it is version 0.4.1 of CEGUI.

User avatar
scriptkid
Home away from home
Home away from home
Posts: 1178
Joined: Wed Jan 12, 2005 12:06
Location: The Hague, The Netherlands
Contact:

Postby scriptkid » Sat Feb 24, 2007 19:47

Hi,

TextItems are not meant to be placed directly; they should be passed to lists (combobox, listbox and multicolumnlist). The reason they don't return a correct value is probably because their parents (the aformentioned lists) calculate & mange their sizes.

If you want a bit of static text, use the StaticText widget; if you want an editable text, use the Editbox.

To check which CEGUI comes with your Ogre version, have a look at the CEGUI.log file, and see below this line: "CEGUI::System singleton created".

If it reads 0.5, there is not StaticText, but rather a DefaultWindow to use. After that everything works as you were used to.

[EDIT] Yes their should be a way to ask for the width of a string, but i forgot the method's name. But maybe my post is already useful.[/EDIT]

Good luck! :-)

User avatar
davesh
Not too shy to talk
Not too shy to talk
Posts: 36
Joined: Fri Feb 03, 2006 22:59

Postby davesh » Mon Feb 26, 2007 15:10

Thanks for the response. Yup your response was indeed useful. Its good to know that TextItems are not typically created programmatically.

I do still need to know, however, how to get the width of the string. We need to be able to get width and height in order to manage the placement of the string within our control panel.

User avatar
scriptkid
Home away from home
Home away from home
Posts: 1178
Joined: Wed Jan 12, 2005 12:06
Location: The Hague, The Netherlands
Contact:

Postby scriptkid » Tue Feb 27, 2007 08:20

davesh wrote:I do still need to know, however, how to get the width of the string. We need to be able to get width and height in order to manage the placement of the string within our control panel.


Hi, i found it. Have a look at the Font::getFontHeight and Font::getTextExtent methods. Using values returned from those methods allows you to set a widget size using UDim values. Because both methods return an absolute (pixels) value, you should use 0 for the scale and the returned values for the offset. For example:

Code: Select all

button->setWidth(UVector2(0, textWidth));
button->setHeight(UVector2(0, fontHeight));


(not tested though, but should work)

HTH :-)


Return to “Help”

Who is online

Users browsing this forum: No registered users and 17 guests