Value within progress bar
« on: 06 April 2016, 02:50:18 »
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

  • *****
  • 1163
    • View Profile
    • Texus's Blog
Re: Value within progress bar
« Reply #1 on: 06 April 2016, 10:54:28 »
Whatever you pass tp setText will be displayed inside the bar, so everytime you change the value you can do something like this:
hp->setText(std::to_string(hp->getValue()));

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

Re: Value within progress bar
« Reply #2 on: 06 April 2016, 22:58:24 »
Thank you very much, worked perfectly!