Is there a way to program constraints for resizable windows?

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
SugarRayLua
Citizen
Posts: 55
Joined: Sat Dec 03, 2022 7:52 pm

Is there a way to program constraints for resizable windows?

Post 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 😊
User avatar
darkfrei
Party member
Posts: 1197
Joined: Sat Feb 08, 2020 11:09 pm

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

Post 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
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
dusoft
Party member
Posts: 635
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

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

Post 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.
User avatar
slime
Solid Snayke
Posts: 3162
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

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

Post by slime »

love.conf and love.window.updateMode have minimum window size parameters you can set.
SugarRayLua
Citizen
Posts: 55
Joined: Sat Dec 03, 2022 7:52 pm

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

Post by SugarRayLua »

Thanks, Everyone-- I'll try those suggestion!
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 2 guests