Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: "setSize()" does not work  (Read 1331 times)

0 Members and 1 Guest are viewing this topic.

Gabriel_

  • Newbie
  • *
  • Posts: 4
    • View Profile
"setSize()" does not work
« on: March 03, 2022, 06:59:18 pm »
Hello,

I use the function "setSize" to resize a window when the user makes it too small.
This same exact code worked fine on Windows 10 but on Linux Mint - Cinnamon it's giving me problems.

The code resizes the window only once in a while instead of constantly resizing.

This is my code:

void Game::proportionateWin()
{
        printf("Winsize : %4d %4d \n",w->getSize().x,w->getSize().y);

        //changes window size to the minimum size (WIN_MIN) (it's 600)
        if (w->getSize().x < WIN_MIN){
                w->setSize(sf::Vector2u(WIN_MIN, w->getSize().y));
                printf("resizing!");
        }
        ....
 
 

I call this function when the window gets resized here:

                if (event.type == sf::Event::Resized) {

                        //printf("resized\n");
                        proportionateWin();
                }

When I run my application every printf is triggered when making the window too small.
And yet the window does not resize.

Edit: Ok so I realized what makes the window resize: when I change the window size by dragging it fast it resizes immediatly but if I slowly drag the window the resizing doesn't take place.

« Last Edit: March 03, 2022, 09:07:39 pm by Gabriel_ »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10394
    • View Profile
    • development blog
    • Email
Re: "setSize()" does not work
« Reply #1 on: March 04, 2022, 08:33:29 am »
I have a feeling that there's some "race condition" with X11's client-server architecture causing this.
What if you use the size provided by the Resize event, instead of calling getSize(): https://www.sfml-dev.org/tutorials/2.5/window-events.php#the-resized-event
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://dev.my-gate.net/

Gabriel_

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: "setSize()" does not work
« Reply #2 on: March 04, 2022, 12:38:05 pm »
I replaced the "getSize()" with the size of the event by passing the event to the function but I still get the same result.

Gabriel_

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: "setSize()" does not work
« Reply #3 on: March 04, 2022, 01:32:58 pm »
Ok I managed to find a way to fix this by saving the value returned by the event and then checking in my main loop if the size ever becomes smaller than 600 and if it does I resize the window.

 

anything