Difference between revisions of "love.window.getSafeArea"
(Created page with "{{newin|11.3|113|type=function}} 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 el...") |
m |
||
(7 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
{{newin|[[11.3]]|113|type=function}} | {{newin|[[11.3]]|113|type=function}} | ||
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. | 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 == | == Function == | ||
Line 14: | Line 13: | ||
{{param|number|y|Starting position of safe area (y-axis).}} | {{param|number|y|Starting position of safe area (y-axis).}} | ||
{{param|number|w|Width of safe area.}} | {{param|number|w|Width of safe area.}} | ||
− | {{param|number| | + | {{param|number|h|Height of safe area.}} |
== Notes == | == Notes == | ||
− | + | Values returned are in DPI-scaled units (the same coordinate system as most other window-related APIs), not in pixels. | |
+ | |||
+ | === Example === | ||
+ | [[File:safe-area-07.png|150px|thumb|right|Show safe area]] | ||
+ | <source lang="lua"> | ||
+ | function love.draw() | ||
+ | local safeX, safeY, safeW, safeH = love.window.getSafeArea() | ||
+ | |||
+ | 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 | ||
+ | </source> | ||
== See Also == | == See Also == | ||
* [[parent::love.window]] | * [[parent::love.window]] | ||
+ | * [[love.graphics.translate]] | ||
[[Category:Functions]] | [[Category:Functions]] | ||
{{#set:Description=Gets unobstructed area inside the window.}} | {{#set:Description=Gets unobstructed area inside the window.}} |
Latest revision as of 00:22, 4 February 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.
Contents
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
function love.draw()
local safeX, safeY, safeW, safeH = love.window.getSafeArea()
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
Dansk –
Deutsch –
English –
Español –
Français –
Indonesia –
Italiano –
Lietuviškai –
Magyar –
Nederlands –
Polski –
Português –
Română –
Slovenský –
Suomi –
Svenska –
Türkçe –
Česky –
Ελληνικά –
Български –
Русский –
Српски –
Українська –
עברית –
ไทย –
日本語 –
正體中文 –
简体中文 –
Tiếng Việt –
한국어
More info