Page 1 of 1

Is there a way to program constraints for resizable windows?

Posted: Mon Oct 23, 2023 6:39 am
by SugarRayLua
I'd like to add minimum limits on the amount a Love2D window can be resized (e.g. shrunken so as not to obscure objects displayed in the viewport).

Does anyone know if there is a way to set such constraints on a Love2D resizable window?

Thanks 😊

Re: Is there a way to program constraints for resizable windows?

Posted: Mon Oct 23, 2023 7:04 am
by darkfrei
SugarRayLua wrote: ↑Mon Oct 23, 2023 6:39 am I'd like to add minimum limits on the amount a Love2D window can be resized (e.g. shrunken so as not to obscure objects displayed in the viewport).

Does anyone know if there is a way to set such constraints on a Love2D resizable window?

Thanks 😊
Like this?
https://love2d.org/wiki/love.graphics.scale

Code: Select all

function love.load ()
	-- if your code was optimized for fullHD:
	window = {translateX = 40, translateY = 40, scale = 2, width = 1920, height = 1080}
	width, height = love.graphics.getDimensions ()
	love.window.setMode (width, height, {resizable=true, borderless=false})
	resize (width, height) -- update new translation and scale
end

function love.update (dt)
	-- mouse position with applied translate and scale:
	local mx = math.floor ((love.mouse.getX()-window.translateX)/window.scale+0.5)
	local my = math.floor ((love.mouse.getY()-window.translateY)/window.scale+0.5)
	-- your code here, use mx and my as mouse X and Y positions
end

function love.draw ()
	-- first translate, then scale
	love.graphics.translate (window.translateX, window.translateY)
	love.graphics.scale (window.scale)
	-- your graphics code here, optimized for fullHD
	love.graphics.rectangle('line', 0, 0, 1920, 1080)
end

function resize (w, h) -- update new translation and scale:
	local w1, h1 = window.width, window.height -- target rendering resolution
	local scale = math.min (w/w1, h/h1)
	window.translateX, window.translateY, window.scale = (w-w1*scale)/2, (h-h1*scale)/2, scale
end

function love.resize (w, h)
	resize (w, h) -- update new translation and scale
end

Re: Is there a way to program constraints for resizable windows?

Posted: Mon Oct 23, 2023 11:12 am
by dusoft
SugarRayLua wrote: ↑Mon Oct 23, 2023 6:39 am I'd like to add minimum limits on the amount a Love2D window can be resized (e.g. shrunken so as not to obscure objects displayed in the viewport).

Does anyone know if there is a way to set such constraints on a Love2D resizable window?

Thanks 😊
You can check the window dimensions in love.update and enforce minimum window size by resizing.

Re: Is there a way to program constraints for resizable windows?

Posted: Mon Oct 23, 2023 11:31 am
by slime
love.conf and love.window.updateMode have minimum window size parameters you can set.

Re: Is there a way to program constraints for resizable windows?

Posted: Wed Oct 25, 2023 5:14 am
by SugarRayLua
Thanks, Everyone-- I'll try those suggestion!