texus / TGUI

Cross-platform modern c++ GUI

Home Page:https://tgui.eu

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Scalable widgets dont show up when window is 1000x1000

fwsmit opened this issue · comments

I found this very weird issue where when I make the window size 1000x1000 widgets don't up if their size or position scales with the window size. Here is an example:

#include <iostream>
#include <TGUI/TGUI.hpp>

int main(){
	sf::RenderWindow window(sf::VideoMode(1000, 1000), "TGUI scaling");
	tgui::Gui gui(window);
	
	auto button = tgui::Button::create("Only this text will show up, but not in the right place");
	button->setSize("10%", "23%");
	button->setPosition("40%", "60%");
	gui.add(button);

	while (window.isOpen())
	{
		sf::Event event;
		while (window.pollEvent(event))
		{
			switch (event.type){
				case sf::Event::Closed:
					window.close();
					break;
				case sf::Event::Resized:
					window.setView(sf::View(sf::FloatRect(0.f, 0.f, static_cast<float>(event.size.width), static_cast<float>(event.size.height))));
					gui.setView(window.getView());
				break;

				default:
					break;
			}
			gui.handleEvent(event);
		}
		window.clear();
		gui.draw();
		window.display();
	}
}

If you run this, you will get a black window without anything in it. If you make the window size anything but 1000x1000 everything will work fine.
I am using arch linux with i3-wm as window manager This issue may have something to do with i3. I have it set up so that every window from TGUI/SFML is set as floating. If I turn that off, i3 will resize the window so that it is not 1000x1000 and everything works fine.

I'm interested to know why this is happening.

This is a bug in TGUI and it isn't related to i3, as I could reproduce it here on cinnamon.
It took me a bit to find the issue too because it didn't make any sense that it worked for any value other than 1000x1000. It turns out that this size is the default size of sf::View (see sf::View constructor), so the m_view in the Gui object was being initialized with 1000x1000 while I assumed it would be 0x0. When the window size is 1000x1000 then the gui believed that the view hadn't changed and it didn't perform a necessary update for the widget size.
I'll apply a fix for this soon.