Formatting Static Text

For help with anything that CEGUI doesn't offer straight out-of-the-box, e.g.:
- Implementation of new features, such as new Core classes, widgets, WindowRenderers, etc. ...
- Modification of any existing features for specific purposes
- Integration of CEGUI in new engines or frameworks and writing of new plugins (Renderer, Parser, ...) or modules

Moderators: CEGUI MVP, CEGUI Team

User avatar
kungfoomasta
Not too shy to talk
Not too shy to talk
Posts: 34
Joined: Wed Apr 06, 2005 08:25

Formatting Static Text

Postby kungfoomasta » Mon Jul 25, 2005 07:18

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.

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

Re: Formatting Static Text

Postby CrazyEddie » Mon Jul 25, 2005 18:47

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.

User avatar
EJohnson
Just popping in
Just popping in
Posts: 11
Joined: Fri Jul 01, 2005 03:45
Location: California
Contact:

Re: Formatting Static Text

Postby EJohnson » Thu Jul 28, 2005 15:09

...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");

User avatar
EJohnson
Just popping in
Just popping in
Posts: 11
Joined: Fri Jul 01, 2005 03:45
Location: California
Contact:

Re: Formatting Static Text

Postby EJohnson » Thu Jul 28, 2005 16:16

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



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

thanks!

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

Re: Formatting Static Text

Postby CrazyEddie » Thu Jul 28, 2005 18:44

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

User avatar
EJohnson
Just popping in
Just popping in
Posts: 11
Joined: Fri Jul 01, 2005 03:45
Location: California
Contact:

Re: Formatting Static Text

Postby EJohnson » Thu Jul 28, 2005 23:30

Err, yeah. Cut & Paste error. :)

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

Any other ideas?

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

Re: Formatting Static Text

Postby CrazyEddie » Sat Jul 30, 2005 12:17

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).

User avatar
Gf11speed
Not too shy to talk
Not too shy to talk
Posts: 22
Joined: Mon Jun 13, 2005 17:51
Contact:

Postby Gf11speed » Thu Jun 01, 2006 16:40

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?
Syntasoft Games
www.syntasoft.com

User avatar
Gf11speed
Not too shy to talk
Not too shy to talk
Posts: 22
Joined: Mon Jun 13, 2005 17:51
Contact:

Postby Gf11speed » Fri Jun 02, 2006 21:21

Is there no way to do this?
Syntasoft Games

www.syntasoft.com

User avatar
lindquist
CEGUI Team (Retired)
Posts: 770
Joined: Mon Jan 24, 2005 21:20
Location: Copenhagen, Denmark

Postby lindquist » Fri Jun 02, 2006 22:02

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 :)

User avatar
Gf11speed
Not too shy to talk
Not too shy to talk
Posts: 22
Joined: Mon Jun 13, 2005 17:51
Contact:

Postby Gf11speed » Sat Jun 03, 2006 14:04

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.
Syntasoft Games

www.syntasoft.com

User avatar
Van
Just can't stay away
Just can't stay away
Posts: 225
Joined: Fri Jan 21, 2005 20:29
Contact:

Postby Van » Tue Jun 13, 2006 16:03

We are being bit by this problem too. Any plans to correct the static text with newline characters in xml files?

User avatar
Gf11speed
Not too shy to talk
Not too shy to talk
Posts: 22
Joined: Mon Jun 13, 2005 17:51
Contact:

Postby Gf11speed » Tue Jun 13, 2006 16:26

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.
Syntasoft Games

www.syntasoft.com

pav
Not too shy to talk
Not too shy to talk
Posts: 37
Joined: Thu Dec 01, 2011 14:17

Re: Formatting Static Text

Postby pav » Tue Dec 13, 2011 13:51

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).


Return to “Modifications / Integrations / Customisations”

Who is online

Users browsing this forum: No registered users and 18 guests