Ok.. I programmed a bit. It was about ~500 lines of code to implement basic TextArea class.
What i have done:
Added tags: <b></b>
<u></u>
<i></i>
<size=xx></size>,
where xx is number: 09, 12, 89<color=xxx.xxx.xxx></color>,
where xxx is number: 001, 034, 234<align=x></align>,
where x is: c-center, l-left, r-right, j-justifyProblems:- if tags are inside word, word can split up.
- if word width is higher then rectangle width there is undefined behavior.
- space between lines.
- you need add enter before </align> tab otherwise last line will be aligned improperly.
To Laurent:- What about a sf::Text feature which will easily give you metrics for special characters like: space, tab, new line.
- I miss std::string functions in sf::String, such as substr().
- Do you control bold effect in fonts? As you can see in the picture, small font with bold style are too fat.
What I want to do:- Add link tag <l> which will will don't split up two linked words
- Rewrite some parts of code to be more clearly and have better performance.
- Render to texture.
- If implementation will be stable I'll rewrite comments in source code (now they are unfortunately in polish).
- Fixed tab size?
Demo render:Parse time: ~0.15 s.
Render time: ~0.02 s.
How to use:Create object TextArea and set string, rect and font. After that, before rendering parse the text. In main application loop render it.
//This code before rendering:
TextArea ta;
TextArea ta;
ta.SetRectArea( sf::FloatRect(20,20,780,580) );
ta.SetFont( font );
ta.SetString( myString );
ta.Parse();
//This code between app.Clear() and app.Display():
ta.Render(app);
Put this files in your project:-
http://paste-it.net/public/q98ffc4/-
http://paste-it.net/public/jc6dcfd/I'm waiting for your opinions and propositions.