Formatting Static Text
Moderators: CEGUI MVP, CEGUI Team
- kungfoomasta
- Not too shy to talk
- Posts: 34
- Joined: Wed Apr 06, 2005 08:25
Formatting Static Text
I have a scenario where I want to talk to an entity. I want the entity to pop up a window with a static text box, and display as much of his text as possible. My question is, how do I know how much of the text can be shown in one window? If the entity has a lot to say, I want to view the text one window at a time. I was looking at the Ogre GUI demo, and I saw that the text can be formatted within the text region. I want to use this formatting, along with some way to know how much text can fit in a particular window to be able to talk to entities. Any ideas would be helpful.
- CrazyEddie
- CEGUI Project Lead
- Posts: 6760
- Joined: Wed Jan 12, 2005 12:06
- Location: England
- Contact:
Re: Formatting Static Text
How much text will fit within a given area depends upon what the text is.
You can calculate the number of lines that will fit in the StaticText widget by taking its height, subtracting the heights of the top and bottom frame images and dividing by the font line spacing.
The font has a getFormattedLineCount member which will return the number of lines required when formatting into a Rect of a given width - you could feed this the width of the StaticText widget (minus the width of the frame sides) and find out how many lines are required for some text.
You may want to consider "pre-formatting" the text in a similar way that MultiLineEditbox does; basically storing information about the character index of the start of each line - this will enable you to more easily manage 'pages' of text.
Really, all of the widgets' formatting is internal, so there is no easy way to obtain details about where a widget will split lines of text; you may end up needing to write your own formatting (word-wrap) code so you know for sure where to split the lines - which you need to know in order to properly manage paging of text like what you're aiming for.
If all of the above is not desirable, my only other suggestion would be to determine ahead of time the 'page breaks' required for your longer texts and deal with things that way - though this is defiately a most inelegant solution, especially since you'd need to faff about every time you made a minor change to the texts.
You can calculate the number of lines that will fit in the StaticText widget by taking its height, subtracting the heights of the top and bottom frame images and dividing by the font line spacing.
The font has a getFormattedLineCount member which will return the number of lines required when formatting into a Rect of a given width - you could feed this the width of the StaticText widget (minus the width of the frame sides) and find out how many lines are required for some text.
You may want to consider "pre-formatting" the text in a similar way that MultiLineEditbox does; basically storing information about the character index of the start of each line - this will enable you to more easily manage 'pages' of text.
Really, all of the widgets' formatting is internal, so there is no easy way to obtain details about where a widget will split lines of text; you may end up needing to write your own formatting (word-wrap) code so you know for sure where to split the lines - which you need to know in order to properly manage paging of text like what you're aiming for.
If all of the above is not desirable, my only other suggestion would be to determine ahead of time the 'page breaks' required for your longer texts and deal with things that way - though this is defiately a most inelegant solution, especially since you'd need to faff about every time you made a minor change to the texts.
Useful Links: Forum Guidelines | Documentation | Tutorials | HOWTO | Videos | Donate to CEGUI | CEGUI Twitter
Re: Formatting Static Text
...on a slightly similiar note, is there a way to embed newlines in the text for a StaticText Window?
I am hoping for something like:
I am hoping for something like:
Code: Select all
myStaticText->setText("this is how I \n use a newline");
Re: Formatting Static Text
...erg, okay that was easy.
This works:
but this doesn't:
Any way I can use '\n' from the .xml file?
thanks!
This works:
Code: Select all
myStaticText->setText("this is how I \n use a newline");
but this doesn't:
Code: Select all
<Window Type="WindowsLook/StaticText" Name="RadioDialogText">
<Property Name="RelativeRect" Value="l:0.05 t:0.250000 r:0.95 b:0.900000" />
<Property Name="HorzFormatting" Value="LeftAligned" />
<Property Name="VertFormatting" Value="TopAligned" />
<Property Name="Text"this is how I \n use a newline" />
</Window>
Any way I can use '\n' from the .xml file?
thanks!
- CrazyEddie
- CEGUI Project Lead
- Posts: 6760
- Joined: Wed Jan 12, 2005 12:06
- Location: England
- Contact:
Re: Formatting Static Text
I assume you have the Value attribute in you XML and that the copy&paste is just a minor mishap
Maybe this works?
Maybe this works?
Code: Select all
...
<Property Name="Text" Value="this is how I
use a newline" />
...
Useful Links: Forum Guidelines | Documentation | Tutorials | HOWTO | Videos | Donate to CEGUI | CEGUI Twitter
Re: Formatting Static Text
Err, yeah. Cut & Paste error.
..and no, breaking the xml line in two doesn't seem to do much.
Any other ideas?
..and no, breaking the xml line in two doesn't seem to do much.
Any other ideas?
- CrazyEddie
- CEGUI Project Lead
- Posts: 6760
- Joined: Wed Jan 12, 2005 12:06
- Location: England
- Contact:
Re: Formatting Static Text
No other ideas really, I'm afraid - seems like you've highlighted a 'missing' feature
I guess we should add some simple parsing to the Property for window text so that it's possible to specify newlines via properties (and therefore, via XML).
I guess we should add some simple parsing to the Property for window text so that it's possible to specify newlines via properties (and therefore, via XML).
Useful Links: Forum Guidelines | Documentation | Tutorials | HOWTO | Videos | Donate to CEGUI | CEGUI Twitter
As far as text formatting, is there any way that I can make the vertical spacing between lines closer together?
Say I have some static text and I set the text:
text->setText("This is the first line\nThis is the second line");
I'd like to be able to have less space between the two lines. Is this possible?
Say I have some static text and I set the text:
text->setText("This is the first line\nThis is the second line");
I'd like to be able to have less space between the two lines. Is this possible?
Syntasoft Games
www.syntasoft.com
www.syntasoft.com
Re: Formatting Static Text
I realize this topic is ancient but for anyone looking how to do this, you can use "
" in the XML property (tested on 0.7.5).
Return to “Modifications / Integrations / Customisations”
Who is online
Users browsing this forum: No registered users and 4 guests