SFML community forums

Help => Window => Topic started by: Chnossos on October 25, 2021, 01:46:32 pm

Title: [BUG] [Linux] Calling Window.setSize() while resizing makes the window grow
Post by: Chnossos on October 25, 2021, 01:46:32 pm
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:

PS: I can talk in French if that's easier to discuss.
Title: Re: [BUG] [Linux] Calling Window.setSize() while resizing makes the window grow
Post by: eXpl0it3r on April 13, 2022, 10:41:27 am
Not sure I fully understood the issue you're running into.

So with the given code, if you start changing the size, then the window starts "moving" around,  thus making your window resize "on its own" until it's reaches the full horizontal or vertical size?

Can you take a short video/gif of the issue, just so we properly understand it?
Also feel free to open an issue on GitHub about this.

On Windows the code looks like this:
(https://en.sfml-dev.org/forums/index.php?action=dlattach;topic=28276.0;attach=5525)