Hi,
Using SFML 2.5.1 on Fedora 32 (GCC 10). I want to
restrict the size of the window so it doesn't shrink more than a certain size.
Using the following code, when I start to resize horizontally (mouse button pressed then mouse move) the window will grow in height until it reaches the top of the screen or until I release the resize handle (mouse button released).
#include <SFML/Window.hpp>
int main()
{
sf::Window window(sf::VideoMode(1280, 720, sf::VideoMode::getDesktopMode().bitsPerPixel), "W");
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
/**/ if (event.type == sf::Event::Closed)
window.close();
else if (event.type == sf::Event::Resized)
{
if (event.size.width < 1280 || event.size.height < 720)
window.setSize({ 1280, 720 });
}
}
}
}
The window end up not resizing to the values I want as a minimum. So I told myself "let's try to wait the release of the handle" but there is no such event. I tried this:
sf::Vector2u newSize;
while (window.isOpen())
{
bool resizing = false;
sf::Event event;
while (window.pollEvent(event))
{
/**/ if (event.type == sf::Event::Closed)
window.close();
else if (event.type == sf::Event::Resized)
{
newSize.x = event.size.width < 1280 ? 1280 : event.size.width;
newSize.y = event.size.height < 720 ? 720 : event.size.height;
resizing = true;
}
}
if (!resizing && newSize != sf::Vector2u())
{
window.setSize(newSize);
newSize = sf::Vector2u();
}
}
But it doesn't work either because the moment I stop moving but
still holding the resize handle the next frame will update the window size since no event is generated (Resized is only generated when there's actually a change in size).
I see 3 paths of resolution:
- Send new ResizeStart/ResizeStop events ;
- Send Resized event until the handle is released ;
- Find a way to actually specify a min/max width/height on the window so even if the user tries to, the window size doesn't go beyond what's been intended (sadly I supposed it is up to the Window Manager to decide about this).
PS: I can talk in French if that's easier to discuss.