Page 1 of 1

GetFormattedLineCount in 0.7.0?

Posted: Fri Sep 25, 2009 11:22
by Kentaree
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?

Re: GetFormattedLineCount in 0.7.0?

Posted: Fri Sep 25, 2009 12:22
by CrazyEddie
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.

Re: GetFormattedLineCount in 0.7.0?

Posted: Fri Sep 25, 2009 13:38
by Kentaree
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?

Re: GetFormattedLineCount in 0.7.0?

Posted: Fri Sep 25, 2009 13:50
by CrazyEddie
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.

Re: GetFormattedLineCount in 0.7.0?

Posted: Fri Sep 25, 2009 14:33
by Kentaree
Cool, to get access to the change I'll need to pull it from subversion I take it?

Re: GetFormattedLineCount in 0.7.0?

Posted: Fri Sep 25, 2009 19:09
by CrazyEddie
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.

Re: GetFormattedLineCount in 0.7.0?

Posted: Sat Sep 26, 2009 11:22
by CrazyEddie
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.

Re: GetFormattedLineCount in 0.7.0?

Posted: Wed Nov 04, 2009 08:35
by kili
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?

Re: GetFormattedLineCount in 0.7.0?

Posted: Thu Nov 05, 2009 11:22
by kili
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?

Re: GetFormattedLineCount in 0.7.0?

Posted: Thu Sep 17, 2020 00:07
by zuur
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();
}