Nothing is drawn

  • 2 Replies
  • 1221 Views
Nothing is drawn
« on: 30 July 2017, 21:20:59 »
No widgets are drawn when call gui.draw(), but usual SFML stuff draws correctly. Debug tells nothing. Im trying to draw button and a sfml circle, and get only circle.
Code: (cpp) [Select]
#include<TGUI/TGUI.hpp>

int main() {
sf::RenderWindow window(sf::VideoMode(800, 600), "TGUI");
sf::CircleShape shape(100);
tgui::Gui gui{window};

auto theme = tgui::Theme::create("TGUI/widgets/Black.txt");

//tgui::Button::Ptr bClickMe = tgui::Button::create("Click me!");
tgui::Button::Ptr bClickMe = theme->load("Button");
bClickMe->setText("lol");
bClickMe->setPosition("50%", 100);
gui.add(bClickMe);

while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed || event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) {
window.close();
}
gui.handleEvent(event);
}

window.clear(sf::Color(128, 128, 128));
window.draw(shape);
gui.draw();
window.display();
}
}
« Last Edit: 30 July 2017, 21:29:24 by Yuri12358 »

*

texus

  • *****
  • 1621
    • View Profile
    • Texus's Blog
Re: Nothing is drawn
« Reply #1 on: 30 July 2017, 22:07:11 »
Quote
Code: (cpp) [Select]
bClickMe->setPosition("50%", 100);
This code only works in tgui 0.8-dev. In tgui 0.7 the "50%" gets evaluated as "50 mod 0", which is NaN.

The equivalent line for tgui 0.7 is:
Code: (cpp) [Select]
bClickMe->setPosition("parent.width/2", 100);
or shorter:
Code: (cpp) [Select]
bClickMe->setPosition("&.w/2", 100);

Re: Nothing is drawn
« Reply #2 on: 30 July 2017, 22:18:37 »
Thanks very much.
Btw, your library is awesome