GetFormattedLineCount in 0.7.0?

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

Kentaree
Just popping in
Just popping in
Posts: 4
Joined: Fri Sep 25, 2009 08:51

GetFormattedLineCount in 0.7.0?

Postby Kentaree » Fri Sep 25, 2009 11:22

Is there an equivalent to GetFormattedLineCount in 0.7.0? I'm porting from 0.6 and missing the functionality to determine what size to resize a window too. I can see in the changelog it's been taken out, but is there an alternative, or a better way of doing it?

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: GetFormattedLineCount in 0.7.0?

Postby CrazyEddie » Fri Sep 25, 2009 12:22

Hi,

It depends really on how you have your string. Formatting is now handled by wrapping a RenderedString in a FormattedRenderedString - this object has functions for accessing the horizontal and vertical extent of the formatted string. Now, whether this is of any immediate use to yourself is dependant upon whether you're rendering the string yourself, or whether this is - for example - a StaticText. If it is a StaticText, we're currently missing the functionality to expose these values - if you like I can add some read-only properties to expose them :)

Thanks for raising this, btw, as it's something I'd (obviously) overlooked.

CE.

Kentaree
Just popping in
Just popping in
Posts: 4
Joined: Fri Sep 25, 2009 08:51

Re: GetFormattedLineCount in 0.7.0?

Postby Kentaree » Fri Sep 25, 2009 13:38

It's a StaticText that's rendering the string, so those properties would be handy :) Does the extent of the formatted string take clipping area into account for vertical size? At the moment I'm working off a small StaticText and use the GetFormattedLineCount to decide how large to scale it to, will I have to switch it around, and make sure the StaticText is always large enough and just scale it down?

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: GetFormattedLineCount in 0.7.0?

Postby CrazyEddie » Fri Sep 25, 2009 13:50

Ok, I'll add the properties to StaticText :)

The extents returned here are unclipped; for word-wrapping purposes we obviously have to use the current window width (actually the width of the text render area), so ideally that width should remain the same when you set the size back according to the text extents (otherwise it will trigger another reformat, possibly changing the extents!).

The basic approach is similar to now where you basically calculate (or in this case, fetch) the text extents, add the size of any frame imagery, and set this back to the widget as a pixel size.

CE.

Kentaree
Just popping in
Just popping in
Posts: 4
Joined: Fri Sep 25, 2009 08:51

Re: GetFormattedLineCount in 0.7.0?

Postby Kentaree » Fri Sep 25, 2009 14:33

Cool, to get access to the change I'll need to pull it from subversion I take it?

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: GetFormattedLineCount in 0.7.0?

Postby CrazyEddie » Fri Sep 25, 2009 19:09

I'll get this added tomorrow morning, and yes, in order to get it straight away you'll need to get the v0-7 branch from svn - though do note that we intend a pretty quick turn around for the 0.7.1 version in order to address all the issues that came up over the past week (currently the 0.7.1 release is planned for early in October).

I'll let you know here once I've added the new properties, and tested them a bit :)

CE.

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: GetFormattedLineCount in 0.7.0?

Postby CrazyEddie » Sat Sep 26, 2009 11:22

I have added "VertExtent" and "HorzExtent" properties to the falagard renderer for StaticText, these are accessed via the Window and the usual getProperty function - obviously the strings returned need to be converted back from text to floats, so you may use the CEGUI::PropertyHelper for that in the usual way. I've tested it out for the intended purpose, and it seems to function fine.

As a point of interest as to the reasons for the somewhat convoluted implementation of this, we can't add functions to the "StaticText" Window class - since there is no such thing. While there are now getVerticalTextExtent and getHorizontalTextExtent functions on the FalagardStaticText window renderer class, to access those you would need to link directly to the CEGUIFalagardWRBase module - which is not the intended usage for that, so this leaves us with the property based implementation ;)

CE.

kili
Not too shy to talk
Not too shy to talk
Posts: 45
Joined: Fri Apr 27, 2007 06:17

Re: GetFormattedLineCount in 0.7.0?

Postby kili » Wed Nov 04, 2009 08:35

Hi,
I'm using DefaultWindow with TextComponent. Is there any way to get VertExtent such as StaticText?If not, could I get it using TextComponet?

kili
Not too shy to talk
Not too shy to talk
Posts: 45
Joined: Fri Apr 27, 2007 06:17

Re: GetFormattedLineCount in 0.7.0?

Postby kili » Thu Nov 05, 2009 11:22

Hi,

Image
There are two images at the same place(the purple stone), both back and front image would change color, so it's hard to combine them.

The old method I use is something like this:

Code: Select all

Font.getFormattedLineCount(Text, Tooltip_Rect, Font::WordWrapLeftAligned, 1.0);


I use the hight to put the 2 created images to the right position.
Is there any method to accomplish this?

zuur
Not too shy to talk
Not too shy to talk
Posts: 31
Joined: Tue Apr 01, 2008 21:17

Re: GetFormattedLineCount in 0.7.0?

Postby zuur » Thu Sep 17, 2020 00:07

For those still trying to figure this out 11 years later!

This function returns the line count for a piece of word-wrapped text being placed in a space with a constrained width, similar to GetFormattedLineCount() from 0.7

Code: Select all

int getWrappedTextLineCount(const CEGUI::String &text, const CEGUI::Font *font, const float width, const CEGUI::Window *ref_wnd)
{
   //I don't know what ref_wind is - the parent window you're going to put the string in maybe?? Passing in something relevant seems to work fine.
   CEGUI::RenderedStringTextComponent rstc(text);
   rstc.setFont(font);
   CEGUI::RenderedString rs;
   rs.appendComponent(rstc);
   CEGUI::RenderedStringWordWrapper<CEGUI::LeftAlignedRenderedString> rsww(rs);
   rsww.format(ref_wnd, CEGUI::Sizef(width, 999999));
   return rsww.getFormattedLineCount();
}


Return to “Help”

Who is online

Users browsing this forum: No registered users and 4 guests