Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] Safe area reimplementation #40761

Merged
merged 1 commit into from
Jul 29, 2020

Conversation

naithar
Copy link
Contributor

@naithar naithar commented Jul 27, 2020

Reimplements usage of safeAreaInsets for master branch and Vulkan support.
Tested with this GDScript on Panel with Panel child:

func _ready():
	var rect = DisplayServer.screen_get_usable_rect()
	var screen_size = DisplayServer.screen_get_size()
	var view_size = get_size()
	
	var aspect_y = view_size.y / screen_size.y
	var aspect_x = view_size.x / screen_size.x
	
	$Panel.set_position(Vector2(rect.position.x * aspect_x, rect.position.y * aspect_y))
	$Panel.set_size(Vector2(rect.size.x * aspect_x, rect.size.y * aspect_y))
Result

Storyboard

Project

@Calinou Calinou added this to the 4.0 milestone Jul 27, 2020
@akien-mga akien-mga requested a review from a team July 27, 2020 22:30
@akien-mga akien-mga merged commit 35ff38b into godotengine:master Jul 29, 2020
@akien-mga
Copy link
Member

Thanks!

@naithar naithar deleted the feature/ios-safe_area branch July 29, 2020 23:06
@marius-se
Copy link
Contributor

Hey @naithar I'm trying to get this working on 3.x - what's the var view_size = get_size() about? Can't find it on 3.x.

Oh and just to make clear: self is of type Panel in your example, correct? Many thanks in advance!

@naithar
Copy link
Contributor Author

naithar commented Mar 18, 2022

Hey @naithar I'm trying to get this working on 3.x - what's the var view_size = get_size() about? Can't find it on 3.x.

Oh and just to make clear: self is of type Panel in your example, correct? Many thanks in advance!

This PR and example is for 4.0 only. You can try using this code for 3.x: https://gist.github.com/naithar/01fa04248956c39a06b7b061b19be83f

get_size() is ui control method: https://docs.godotengine.org/en/stable/classes/class_control.html?highlight=get_size()#class-control-property-rect-size

@marius-se
Copy link
Contributor

Ah thanks! Works like a charm <3 Now I even understand Viewports, screen resolutions, scaling, etc. ... a little bit more!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants