Value within progress bar

Started by Bryan9311, 06 April 2016, 02:50:18

Bryan9311

I'm trying to set up a progress bar to act as a health bar and I was wondering if it's possible to display the current value inside the par as text. I've messed around with casting as a string but I've had no luck so far. Here's my base code:

//Health Bar
    tgui::ProgressBar::Ptr hp = std::make_shared<tgui::ProgressBar>();
    hp->setText("Health");
    hp->getRenderer()->setBackgroundColor(sf::Color::White);
    hp->getRenderer()->setForegroundColor(sf::Color::Red);
    hp->setMaximum(10);
    hp->setMinimum(0);
    hp->setPosition(0,0);
    hp->setValue(5);
    gui.add(hp);

texus

Whatever you pass tp setText will be displayed inside the bar, so everytime you change the value you can do something like this:
Code (cpp) Select
hp->setText(std::to_string(hp->getValue()));

Or if you want the total to be visible as well:
Code (cpp) Select
hp->setText(std::to_string(hp->getValue()) + " / " + std::to_string(hp->getMaximum()));

Bryan9311

Thank you very much, worked perfectly!