Difference between revisions of "love.window.getSafeArea"

m (Example: Minor improvements)
Line 19: Line 19:
  
 
=== Example ===
 
=== Example ===
[[File:safe-area-07.png|200px|thumb|left|alt text]]
+
[[File:safe-area-07.png|150px|thumb|right|Show safe area]]
 
<source lang="lua">
 
<source lang="lua">
 
-- outside of love.load
 
-- outside of love.load
love.window.setMode(240, 320) -- QVGA, but vertical
+
love.window.setMode(240, 320) -- QVGA, but vertical (this sets viewport to portrait)
 
love.window.setMode(240, 320) -- double it!
 
love.window.setMode(240, 320) -- double it!
 
safeX, safeY, safeW, safeH = love.window.getSafeArea( )
 
safeX, safeY, safeW, safeH = love.window.getSafeArea( )
Line 31: Line 31:
 
love.graphics.line(0, 0, safeW, safeH)
 
love.graphics.line(0, 0, safeW, safeH)
 
love.graphics.line(0, safeH, safeW, 0)
 
love.graphics.line(0, safeH, safeW, 0)
love.graphics.circle ('line', safeW/2, safeH/2, safeW/2)
+
love.graphics.circle('line', safeW/2, safeH/2, safeW/2)
love.graphics.circle ('line', safeW/2, safeH/2, safeH/2)
+
love.graphics.circle('line', safeW/2, safeH/2, safeH/2)
 
end
 
end
 
</source>
 
</source>
 
  
 
== See Also ==
 
== See Also ==

Revision as of 07:09, 30 January 2023

Available since LÖVE 11.3
This function is not supported in earlier versions.

Gets area inside the window which is known to be unobstructed by a system title bar, the iPhone X notch, etc. Useful for making sure UI elements can be seen by the user.

Function

Synopsis

x, y, w, h = love.window.getSafeArea( )

Arguments

None.

Returns

number x
Starting position of safe area (x-axis).
number y
Starting position of safe area (y-axis).
number w
Width of safe area.
number h
Height of safe area.

Notes

Values returned are in DPI-scaled units (the same coordinate system as most other window-related APIs), not in pixels.

Example

Show safe area
-- outside of love.load
love.window.setMode(240, 320) -- QVGA, but vertical (this sets viewport to portrait)
love.window.setMode(240, 320) -- double it!
safeX, safeY, safeW, safeH = love.window.getSafeArea( )

function love.draw()
	love.graphics.translate(safeX, safeY)
	love.graphics.rectangle("line", 0, 0, safeW, safeH)
	love.graphics.line(0, 0, safeW, safeH)
	love.graphics.line(0, safeH, safeW, 0)
	love.graphics.circle('line', safeW/2, safeH/2, safeW/2)
	love.graphics.circle('line', safeW/2, safeH/2, safeH/2)
end

See Also


Other Languages