Window sizes

For help with anything that CEGUI doesn't offer straight out-of-the-box, e.g.:
- Implementation of new features, such as new Core classes, widgets, WindowRenderers, etc. ...
- Modification of any existing features for specific purposes
- Integration of CEGUI in new engines or frameworks and writing of new plugins (Renderer, Parser, ...) or modules

Moderators: CEGUI MVP, CEGUI Team

User avatar
BRAINLESS
Just popping in
Just popping in
Posts: 7
Joined: Wed Mar 30, 2005 19:18
Contact:

Window sizes

Postby BRAINLESS » Tue Dec 12, 2006 16:47

I want to allow adding GUI widgets to a window by code, and I don't want it to take a lot of effort. So, I've written a simple wrapper called class: Label. It does exactly what you would expect, display a label :)

The problem is, I can't figure out how wide the label has to be. I don't want it to be 1.0f in width, as then even the height may not be enough. Is there an auto-resize function that I've missed? I've been looking around but the API docs are incredibly slow and flying blind didn't help either.

(for the record, I'm still using CEGUI 0.4.1)

User avatar
BRAINLESS
Just popping in
Just popping in
Posts: 7
Joined: Wed Mar 30, 2005 19:18
Contact:

Postby BRAINLESS » Tue Dec 12, 2006 16:50

Don't you just love it that 10 seconds after you post a question, you come across something that could possibly answer it...

Code: Select all

float getTextExtent (const String &text, float x_scale=1.0f)
  Return the pixel width of the specified text if rendered with this Font.

float getFormattedTextExtent (const String &text, const Rect &format_area, TextFormatting fmt, float x_scale=1.0f)
  Return the horizontal pixel extent given text would be formatted to.


Assuming that's the best there is, I'll see if this works :)

User avatar
BRAINLESS
Just popping in
Just popping in
Posts: 7
Joined: Wed Mar 30, 2005 19:18
Contact:

Postby BRAINLESS » Tue Dec 12, 2006 16:57

Alright, here we go:

Code: Select all

std::string label = "test";
m_Window->setSize(CEGUI::Absolute, CEGUI::Size(m_Window->getFont()->getTextExtent(label), m_Window->getFont()->getFontHeight()));


getTextExtend returns 17, getFontHeight returns 13, so you've got to use CEGUI::Absolute with it.

Sorry for all the spam ;)


Return to “Modifications / Integrations / Customisations”

Who is online

Users browsing this forum: No registered users and 7 guests