love.window.setMode with resizable flag lacks minimum size constraints
0 reputation · 04 Aug 2021, 09:20 UTC
0 reputation · 04 Aug 2021, 09:20 UTC
The goal is to allow users to resize a LÖVE window while keeping the rendering surface usable across all possible dimensions.
Currently love.window.setMode(width, height, {resizable=true}) places no lower bound on the reported width and height; the window can be shrunk to 1×1 pixels, which can break drawing and input handling. Developers must manually clamp love.graphics.getWidth() and love.graphics.getHeight() inside love.resize or repeatedly call love.window.setMode to enforce a size policy, but there is no consensus on whether the engine should provide an optional minSize argument or enforce a default minimum.
Should love.window.setMode accept optional minWidth/minHeight parameters? Should the engine automatically clamp dimensions to a developer‑defined minimum? Would adding such constraints affect existing projects that rely on unrestricted resizing?
35275 reputation · 04 Aug 2021, 19:20 UTC
love.window.setMode does not enforce a minimum size when the resizable flag is true; the underlying SDL2 layer allows the window to be shrunk to 1×1 pixels.
love.resize(w, h) callback receives the new size after the user drags the window border.The function forwards the request to SDL2, which honors the resizable flag but offers no way to attach size constraints; consequently Love2D cannot automatically clamp the dimensions.
love.load set the initial window with the desired resizable flag:function love.load()
love.window.setMode(800, 600, {resizable=true, vsync=true})
end
love.resize to clamp the width and height to your minima and, only if the clamped values differ from the received ones, call love.window.setMode again:local MIN_W, MIN_H = 400, 300
function love.resize(w, h)
local changed = false
if w < MIN_W then w = MIN_W; changed = true end
if h < MIN_H then h = MIN_H; changed = true end
if changed then
love.window.setMode(w, h, {resizable=true})
end
-- use w and h for rendering or store them
end
love.window.getWidth() and love.window.getHeight() after the potential second setMode call.MIN_W or MIN_H; the window should snap back to the clamped size.love.window.getWidth() and love.window.getHeight() inside love.resize before and after the conditional setMode to confirm the values.Adding optional minWidth and minHeight parameters to love.window.setMode would be backward‑compatible; projects that do not supply them would retain the current unrestricted resizing behavior. Only projects that rely on the ability to shrink the window to arbitrary sizes would need to adjust their expectations or explicitly disable the new limits.
Use comments to ask for clarification. Post a solution as an answer.
35,275 reputation · 04 Aug 2021, 16:03 UTC
Starting with LÖVE 11.5 the setMode options table may include minWidth and minHeight. When set, the engine clamps every resize event so the window never shrinks below the specified values.
Example:
love.window.setMode(800, 600, {
resizable = true,
minWidth = 200,
minHeight = 150
})
Older releases ignore these keys and keep the pre‑11.5 behaviour. Thus projects that never used the fields remain unaffected, while new code can enforce safe minimums without extra callbacks.