Page 1 of 1

Formatting Static Text

Posted: Mon Jul 25, 2005 07:18
by kungfoomasta
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.

Re: Formatting Static Text

Posted: Mon Jul 25, 2005 18:47
by CrazyEddie
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.

Re: Formatting Static Text

Posted: Thu Jul 28, 2005 15:09
by EJohnson
...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:

Code: Select all

myStaticText->setText("this is how I \n use a newline");

Re: Formatting Static Text

Posted: Thu Jul 28, 2005 16:16
by EJohnson
...erg, okay that was easy.

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" />

Any way I can use '\n' from the .xml file?


Re: Formatting Static Text

Posted: Thu Jul 28, 2005 18:44
by CrazyEddie
I assume you have the Value attribute in you XML and that the copy&paste is just a minor mishap ;)

Maybe this works?

Code: Select all

    <Property Name="Text" Value="this is how I
use a newline" />

Re: Formatting Static Text

Posted: Thu Jul 28, 2005 23:30
by EJohnson
Err, yeah. Cut & Paste error. :)

..and no, breaking the xml line in two doesn't seem to do much.

Any other ideas?

Re: Formatting Static Text

Posted: Sat Jul 30, 2005 12:17
by CrazyEddie
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).

Posted: Thu Jun 01, 2006 16:40
by Gf11speed
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?

Posted: Fri Jun 02, 2006 21:21
by Gf11speed
Is there no way to do this?

Posted: Fri Jun 02, 2006 22:02
by lindquist
not without modifying the source code
The easiest way to do is probably to add a Font::setLineSpacing member, but this would affect alot of code. I'm not going to try it right now, but feel free to let us know what it does if you try it :)

Posted: Sat Jun 03, 2006 14:04
by Gf11speed
Ok, I probably won't mess with the internal system... at least for now. I think I might just use a transparent background for the text so that I can make text closer without the boarder frame and background overlapping.

Posted: Tue Jun 13, 2006 16:03
by Van
We are being bit by this problem too. Any plans to correct the static text with newline characters in xml files?

Posted: Tue Jun 13, 2006 16:26
by Gf11speed
We ended up creating seperate vertical text fields with transparent backgrounds. If you do that then you can set the text as close as you want to each other without the text backgrounds overlapping. It works well, but the disadvantage is that you have to have a text field for every line.

Re: Formatting Static Text

Posted: Tue Dec 13, 2011 13:51
by pav
I realize this topic is ancient but for anyone looking how to do this, you can use "&#0010;" in the XML property (tested on 0.7.5).