Is is possible to set the text style in a Label ?

Started by starkhorn, 25 January 2015, 01:02:52

starkhorn

I've set the text to a label, but I'd like to say add an underline or make it bold, i.e. the stuff can be set with sf::Text test.setStyle();
I've tried the below but obviously it says that m_text isn't accessible.

Code (cpp) Select

LabelList->m_Text.setStyle(sf::Text::Underlined);


So I tried the below, where i define the sf::Text string and style. However I get a cannot convert parameter error.

Code (cpp) Select

tgui::Label::Ptr LabelList;
sf::Text str;

str.setString("Global Nation Treasury");
str.setStyle(sf::Text::Underlined);
LabelList->setText(str);

Error 17 error C2664: 'tgui::Label::setText' : cannot convert parameter 1 from 'sf::Text' to 'const sf::String &'


PS. Sorry for all of the posts recently - I really hope that I'm not asking obvious things here. I did try to search the forums beforehand.

texus

#1
It is not possible. You should draw an sf::Text yourself to have more advanced features like bold and underline.

Or you can cheat, put the following before including tgui and use m_Text anyway :). But that's probably not what you want.
Code (cpp) Select
#define private public
#define protected public


Edit: I'll think about adding a setStyle function in the future. But I would have to test what the effect would be (since it might break stuff like word-wrap).

texus

I just realized that word-wrap was only added in v0.7-dev, so there is actually nothing that stops me from adding such style in v0.6 right away.

The latest version on the master branch now has setTextStyle and getTextStyle functions.