Highlight background text
« on: 11 April 2015, 05:52:37 »
Is there a way for text that is set for radio or check buttons to be highlighted when the actual checkbox or radio button is selected?

Also, I have same question for labels as well. Basically I have a long list of checkbox but due to the fact I wanted to format the text in neat columns, I displayed them as labels.

I have had a look and I cannot seem to find any such method? Does one exist or are any in the works?

Re: Highlight background text
« Reply #1 on: 11 April 2015, 05:57:46 »
oh for labels, I just saw the background color method - I somehow missed seeing that one - sorry.

void tgui::Label::setBackgroundColor    (    const sf::Color &     backgroundColor   )

So my question then becomes, can i do something similiar for the radio and check button text?

Re: Highlight background text
« Reply #2 on: 11 April 2015, 07:04:36 »
sorry, another related question.......

So I've tried the setbackground colour of the labels but it actually only highlights the text. I have a row of seperate labels all on the ypos. I want to highlight the entire ypos row...including the gaps in between each label.

These labels are in a panel. So instead I was trying to create a sf::RectangleShape set to the row y size. I have the below which creates the rectange to the size and position within the panel.

My question is how can I add this rectangle shape so that it is displayed within the panel. I need to draw the rectangle shape before the labels as well. The below setPositions are valid within the panel only.


        for (int i = 0; i < LabelList.size(); i++)
        {
                if (LabelList[i]->getPosition().y  == passed_pos.getPosY() && LabelList[i]->getPosition().x < maxX)
                {
                        sf::RectangleShape labelBackground;
                        labelBackground.setSize(sf::Vector2f(maxX, getDataRowSize()));
                        labelBackground.setPosition(LabelList[i]->getPosition().x, LabelList[i]->getPosition().y);
                        labelBackground.setFillColor(sf::Color::Red);
                }
        }

 

*

texus

  • *****
  • 1161
    • View Profile
    • Texus's Blog
Re: Highlight background text
« Reply #3 on: 11 April 2015, 12:47:01 »
It is not possible for checkbox, you would have to use a checkbox without text and put a Label next to it.

There is a Canvas widget which lets you draw sfml stuff inbetween tgui widgets. It works like a sf::RenderTexture.

So you would get something like this (code was not tested).
Canvas::Ptr canvas(*panel); // Add canvas to the panel (before adding the labels, so that it is drawn behind the labels)

canvas->setSize(panel->getSize()); // Fill the entire panel so we can draw anywhere on it

// Before the gui.draw call you draw on the canvas
canvas->clear();
sf::RectangleShape labelBackground;
labelBackground.setSize(sf::Vector2f(maxX, getDataRowSize()));
labelBackground.setPosition(LabelList[i]->getPosition().x, LabelList[i]->getPosition().y);
labelBackground.setFillColor(sf::Color::Red);
canvas->draw(labelBackground);
canvas->display();
« Last Edit: 11 April 2015, 12:49:37 by texus »