How to center a SFGUI window (sfg::Window)

Simply get the SFGUI window size using GetAllocation, the sfml window size using getSize, then do this arithmetic:

auto window = sfg::Window::Create();
auto win_rect = window->GetAllocation();
sf::Vector2f size(win_rect.width, win_rect.height);
window->SetPosition(((sf::Vector2f)rwindow->getSize() - size) / 2.0f);
Comments

Comments are currently disabled whilst we remove the dependency on a third party service which was taken offline. In the meantime, feel free to send a message to me on Twitter.