Hi,
I need to get one of the following for a wrapped text component after calling setText(str);
- window height
- number of lines
- the text after it has been wrapped (visual)
using windowslook - the type of window is "WindowsLook/StaticText"
I have tried calling win->getTextVisual() but returns the unformatted (non-wrapped) text.
It seems like the formatting is only done at the render stage - is this true ? if so, can I force rendering ?
Thanks.
get window height for wrapped text component
Moderators: CEGUI MVP, CEGUI Team
- CrazyEddie
- CEGUI Project Lead
- Posts: 6760
- Joined: Wed Jan 12, 2005 12:06
- Location: England
- Contact:
Re: get window height for wrapped text component
Hi,
getTextVisual is not related to formatting - it's related to bidirectional text support, so is somewhat unlikely to be what you wanted anyway
The window height will always be whatever you set it to; the window height does not change due to formatting, so probably no point in getting that. If you're actually after getting the dimensions of the formatted output, you can use the "HorzExtent" and "VertExtent" properties.
However, you are correct that formatting is only done as-needed when the widget is rendered (this is an optimisation, formatting each and every time the text changes would be unacceptably slow for some scenarios). To force the rendering / formatting to occur, you can call the Window::render function for the StaticText.
HTH
CE.
getTextVisual is not related to formatting - it's related to bidirectional text support, so is somewhat unlikely to be what you wanted anyway
The window height will always be whatever you set it to; the window height does not change due to formatting, so probably no point in getting that. If you're actually after getting the dimensions of the formatted output, you can use the "HorzExtent" and "VertExtent" properties.
However, you are correct that formatting is only done as-needed when the widget is rendered (this is an optimisation, formatting each and every time the text changes would be unacceptably slow for some scenarios). To force the rendering / formatting to occur, you can call the Window::render function for the StaticText.
HTH
CE.
Useful Links: Forum Guidelines | Documentation | Tutorials | HOWTO | Videos | Donate to CEGUI | CEGUI Twitter
Re: get window height for wrapped text component
Hey CE,
Thanks for the great response to this query - a straight-forward solution along with some worth while justification and background info; what more could the community ask for
I'm still having problems with this however - possibly because I'm still using 0.6.2?
I'm wanting to display a form in a window: basically just headings with a paragraph of text below each. My problem is that I only know what the text is at run-time, so I'm guessing I have to figure out how high each "paragraph" window is at run-time and move all the headings/paragraphs below it down to a suitable Y position, (please let me know if there's some much simpler way to achieve this).
I've made a function:
...which I assume is on the right track?
I'm passing in StaticText windows with Horz/Vert Formatting set to Top/Left. I set the text on this window and than pass it into this function to see how high to make it. The problem is that my window doesn't appear to have any "VertExtent" property (or similar).
Thoughts?
Thanks for the great response to this query - a straight-forward solution along with some worth while justification and background info; what more could the community ask for
I'm still having problems with this however - possibly because I'm still using 0.6.2?
I'm wanting to display a form in a window: basically just headings with a paragraph of text below each. My problem is that I only know what the text is at run-time, so I'm guessing I have to figure out how high each "paragraph" window is at run-time and move all the headings/paragraphs below it down to a suitable Y position, (please let me know if there's some much simpler way to achieve this).
I've made a function:
Code: Select all
int getRequiredHeightForText(CEGUI::Window* win)
{
win->render();
const CEGUI::String str = win->getProperty("VertExtent");
int requiredHeight = CEGUI::PropertyHelper::stringToInt(str);
return requiredHeight;
}
...which I assume is on the right track?
I'm passing in StaticText windows with Horz/Vert Formatting set to Top/Left. I set the text on this window and than pass it into this function to see how high to make it. The problem is that my window doesn't appear to have any "VertExtent" property (or similar).
Thoughts?
- CrazyEddie
- CEGUI Project Lead
- Posts: 6760
- Joined: Wed Jan 12, 2005 12:06
- Location: England
- Contact:
Re: get window height for wrapped text component
DO NOT BUMP THREADS THAT ARE STILL ON THE FIRST PAGE
Because you have done this, my reply will not contain the solution.
CE.
Because you have done this, my reply will not contain the solution.
CE.
Useful Links: Forum Guidelines | Documentation | Tutorials | HOWTO | Videos | Donate to CEGUI | CEGUI Twitter
Re: get window height for wrapped text component
Oh no!
Sorry CE; and I mean that in the sincerest way possible.
I didn't realize this post was still on the first page - I've just been logging into the forum and clicking the "View your posts" link every day to see if there had been a response. I know you're really good at answering and thought that because I had appended my post to the end of someone else's already-solved post, and it had been five days that it had been overlooked
I can quite understand your frustration and I'll make sure this doesn't ever happen in future.
Please do come back to this post when you're ready, as I've been completely unable to figure this one out myself and can't find any other information (apart from this thread) pertaining to the same problem.
Sincerely,
-Aaron.
Sorry CE; and I mean that in the sincerest way possible.
I didn't realize this post was still on the first page - I've just been logging into the forum and clicking the "View your posts" link every day to see if there had been a response. I know you're really good at answering and thought that because I had appended my post to the end of someone else's already-solved post, and it had been five days that it had been overlooked
I can quite understand your frustration and I'll make sure this doesn't ever happen in future.
Please do come back to this post when you're ready, as I've been completely unable to figure this one out myself and can't find any other information (apart from this thread) pertaining to the same problem.
Sincerely,
-Aaron.
Re: get window height for wrapped text component
I think this is possible with the RenderedString classes in 0.7 and (I am not sure) the Font class in 0.6.
Also, please consider helping others as well and not just leeching the forum. Thanks
Also, please consider helping others as well and not just leeching the forum. Thanks
Re: get window height for wrapped text component
Thanks Kulik,
I'm just getting back to this now - we have a big deadline we've been working towards on Friday and I was going to take the "put a sticking plaster over it and pretend the functionality doesn't exist" approach.. I'd love to get it working and am just having a look into your suggestion now.
I'm assuming the steps would be something like:
First problem I've run into is that I'm running 0.6 and in my documentation directory I have a text file telling me the documentation can be found on http://www.cegui.org.uk/... but I can't see any way to get old documentation from the web site... any ideas?
I understand where you're coming from - we've all been flat-out with getting this release together for the last month and I really just needed some help with this one desperately (haven't been finding time for sleeping let alone anything else) - I'll be sure to check my posts (and others) via the regular interface in future.
I'm just getting back to this now - we have a big deadline we've been working towards on Friday and I was going to take the "put a sticking plaster over it and pretend the functionality doesn't exist" approach.. I'd love to get it working and am just having a look into your suggestion now.
Kulik wrote:I think this is possible with the RenderedString classes in 0.7 and (I am not sure) the Font class in 0.6.
I'm assuming the steps would be something like:
- * get font from font manager
* send font appropriate text and max width
* ask what min height required is
First problem I've run into is that I'm running 0.6 and in my documentation directory I have a text file telling me the documentation can be found on http://www.cegui.org.uk/... but I can't see any way to get old documentation from the web site... any ideas?
Kulik wrote:Also, please consider helping others as well and not just leeching the forum. Thanks
I understand where you're coming from - we've all been flat-out with getting this release together for the last month and I really just needed some help with this one desperately (haven't been finding time for sleeping let alone anything else) - I'll be sure to check my posts (and others) via the regular interface in future.
Re: get window height for wrapped text component
Ok, I think I have an answer (for anyone else looking to do the same thing) - please comment on any obvious pitfalls...
NB: This is for v0.6.2!
EDIT: Don't use this code - use the code in CE's link below...
NB: This is for v0.6.2!
EDIT: Don't use this code - use the code in CE's link below...
Code: Select all
int getRequiredHeightForWrappedText(CEGUI::Window* win)
{
//Returns the height (in pixels) required for the text in this window given the window's
// current width, current font, and current text, and given the assumption it's
// supposed to wrap.
CEGUI::Font* fontInUse = win->getFont();
CEGUI::Rect rect = win->getInnerRect();
CEGUI::String text = win->getText();
//std::string textICanReadInMyDebugger = text.c_str();
CEGUI::TextFormatting formatting = CEGUI::WordWrapLeftAligned; //not sure how to read this out of win?
int lineCount = fontInUse->getFormattedLineCount(text, rect, formatting);
int lineHeight = fontInUse->getLineSpacing();
return lineCount * lineHeight;
}
Last edited by zuur on Mon May 16, 2011 21:34, edited 1 time in total.
- CrazyEddie
- CEGUI Project Lead
- Posts: 6760
- Joined: Wed Jan 12, 2005 12:06
- Location: England
- Contact:
Re: get window height for wrapped text component
Because the inner rects are mostly broken in 0.6.x, your code may not always behave correctly. The following post gives the correct code for this, and the thread it contains is an otherwise interesting discussion regarding performing this calculation: viewtopic.php?p=19987#p19987
Btw, the HorzExtent and VertExtent properties were added to StaticText for one of the 0.7.x releases.
CE
Btw, the HorzExtent and VertExtent properties were added to StaticText for one of the 0.7.x releases.
CE
Useful Links: Forum Guidelines | Documentation | Tutorials | HOWTO | Videos | Donate to CEGUI | CEGUI Twitter
Re: get window height for wrapped text component
Thanks CE,
...and to think it was there on the forum the whole time
Just out of curiosity, is the 0.6 documentation still available somewhere?
...and to think it was there on the forum the whole time
Just out of curiosity, is the 0.6 documentation still available somewhere?
- CrazyEddie
- CEGUI Project Lead
- Posts: 6760
- Joined: Wed Jan 12, 2005 12:06
- Location: England
- Contact:
Re: get window height for wrapped text component
zuur wrote:Just out of curiosity, is the 0.6 documentation still available somewhere?
You can download docs for the previous versions from sourceforge.net: https://sourceforge.net/projects/crayze ... k-2/0.6.2/
HTH
CE
Useful Links: Forum Guidelines | Documentation | Tutorials | HOWTO | Videos | Donate to CEGUI | CEGUI Twitter
Return to “Modifications / Integrations / Customisations”
Who is online
Users browsing this forum: No registered users and 3 guests