love.window.setMode not triggering love.resize is bug or feature?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
GVovkiv
Party member
Posts: 688
Joined: Fri Jan 15, 2021 7:29 am

love.window.setMode not triggering love.resize is bug or feature?

Post by GVovkiv »

Wiki for love.resize() says:
Called when the window is resized, for example if the user resizes the window, or if love.window.setMode is called with an unsupported width or height in fullscreen and the window chooses the closest appropriate size.
But I found this weird because..:

Code: Select all

-- This won't trigger rs.resize because default window is 800x600
-- so this makes sense?
love.window.setMode(800, 600, {resizable = true})

-- Now let's change window to 1024x600.
-- And... love.resize still didn't triggered...
love.window.setMode(1024, 600, {resizable = true})


love.resize = function()
  print("Resized!")
end
I get 0 "Resized!" outputs, but I expected at least 1 after calling love.window.setMode(1024, 600) because, well, window size is changed!
Doing as wiki says, calling with "unsupported" arguments indeed triggers love.resize:

Code: Select all

love.window.setMode(0, 0, {resizable = true})
Did I miss something or everything works as intended(TM)?
User avatar
slime
Solid Snayke
Posts: 3172
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: love.window.setMode not triggering love.resize is bug or feature?

Post by slime »

As that wiki quote says, it's only called if the user resizes the window non-programmatically, or if setMode is called and the window had to be internally resized from the dimensions you gave to setMode because they weren't supported by the system.

It's not called if you give setMode a size and the window gets recreated in that exact size (i.e. it's working as intended in your example). However this might change in future love versions.
User avatar
GVovkiv
Party member
Posts: 688
Joined: Fri Jan 15, 2021 7:29 am

Re: love.window.setMode not triggering love.resize is bug or feature?

Post by GVovkiv »

slime wrote: Sat Aug 26, 2023 12:31 pm It's not called if you give setMode a size and the window gets recreated in that exact size (i.e. it's working as intended in your example). However this might change in future love versions.
I hope it will, because I found this to be weird behavior, because window size changed after all.

I working on library that relies on love.resize() to update itself if window was resized, but because setMode doesn't trigger love.resize, I need to wrap love.window.setMode in library and point users to use it instead, which is not ideal solution that I want.
User avatar
slime
Solid Snayke
Posts: 3172
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: love.window.setMode not triggering love.resize is bug or feature?

Post by slime »

You can just have a function that's meant to be called after a user calls setMode/updateMode, instead of wrapping setMode. Or if you already have a library function that's called in love.update or similar places, you can check the actual versus expected dimensions there and call your internal resize code when they don't match.
User avatar
GVovkiv
Party member
Posts: 688
Joined: Fri Jan 15, 2021 7:29 am

Re: love.window.setMode not triggering love.resize is bug or feature?

Post by GVovkiv »

slime wrote: Sat Aug 26, 2023 12:40 pm you can check the actual versus expected dimensions there and call your internal resize code when they don't match.
I was doing that in past, but now everything based around love.resize because it's easier to use and resulted in more clean codebase.
setMode/updateMode
I have this function, but my idea was specifically to avoid users doing so.
User avatar
slime
Solid Snayke
Posts: 3172
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: love.window.setMode not triggering love.resize is bug or feature?

Post by slime »

Alright, well those are some solutions, it's up to you to use them. :)
User avatar
GVovkiv
Party member
Posts: 688
Joined: Fri Jan 15, 2021 7:29 am

Re: love.window.setMode not triggering love.resize is bug or feature?

Post by GVovkiv »

slime wrote: Sat Aug 26, 2023 12:47 pm Alright, well those are some solutions, it's up to you to use them. :)
I mean, I can, but I found this behavior for setMode and love.resize to be weird.
Why it triggers when you allow this function to decide new size by itself (like passing 0, 0 to it) but doesn't when you pass something specifically? It doesn't make much sense (at least for me).
Does that means, that relying on love.resize is not 100% guaranty that it will be called if window was changed by any means?
User avatar
slime
Solid Snayke
Posts: 3172
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: love.window.setMode not triggering love.resize is bug or feature?

Post by slime »

love.resize is called when the size of the window changes to something you didn't specify. This can happen if the user resizes the window via desktop UI (or rotating a phone or whatever), or if you programmatically specified a size that's not supported so it has to pick something that is supported.

In situations where the window size does change to something you specify, you own the code to do it so it's also easy to have any other code that responds to that change in the same place.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 8 guests