Page 1 of 1

Window sizes

Posted: Tue Dec 12, 2006 16:47
by BRAINLESS
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)

Posted: Tue Dec 12, 2006 16:50
by BRAINLESS
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 :)

Posted: Tue Dec 12, 2006 16:57
by BRAINLESS
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 ;)