-
Notifications
You must be signed in to change notification settings - Fork 909
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
Add safe area and document coordinate systems #3890
base: master
Are you sure you want to change the base?
Conversation
7899334
to
67113a7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can macOS backend provide safe area when the transparent decorations are used? The ones where the buttons are over the main surface.
Didn't even know we had I was kinda hoping I could define |
You just need to |
Added `Window::safe_area`, which describes the area of the surface that is unobstructed by notches, bezels etc. The drawing code in the examples have been updated to draw a star inside the safe area, and the plain background outside of it. Also renamed `Window::inner_position` to `Window::surface_position`, and changed it to from screen coordinates to window coordinates, to better align how these coordinate systems work together. Finally, added some SVG images and documentation to describe how all of this works.
67113a7
to
98a9914
Compare
Dunno, I can imagine that it will happen on some platforms
I have ensured that |
ed83b5f
to
bc12e13
Compare
Very bare-bones, probably not correct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great!
I will work on the Web implementation soon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the safe area account for the virtual keyboard as well on iOS?
I found this: https://developer.apple.com/design/human-interface-guidelines/layout#iOS-keyboard-layout-guide |
I implemented Web as well now. However there is a bug when not used with This could also be happening on Android, unfortunately I can't test it because I don't have an Android device with a notch. |
So I spent some more time thinking about the Web implementation. AFAIK on iOS you can't move the window partly off-screen, but on Web it is possible to do so. A practical example: It seems to me that the safe area is only useful if the I'm unsure how to implement this on Web. Probably if the canvas is not as big as the viewport or the We might want to define a new concept like "visible surface area", which exposes the truly visible area to the user, which would account for everything: safe area, occlusion, virtual keyboard and so on. |
Safe area matters for fullscreen window to not draw behind the notch, for the rest it's not used. It's also static to display coordinates (most of the time). Like the whole purpose here is for e.g. alacritty offset it viewport to not put anything behind notch on macOS during fullscreen, nothing more, and yes, it's called safe area. |
@daxpedda and I talked about this today, and a rough conclusion was to calculate the safe area independently of the scroll position of the page, i.e. in a sort of "absolute" position of the entire document. |
I haven't exactly followed this PR, but how is this "surface inside window" representation going to come together with #3942 and all future "subsurface" changes that we're going to make? Every individual surface having its position relative to the parent surface and eventually relative to the window "area" that we define here? |
Not sure yet, but I think it makes sense to allow querying the safe area relative to each surface. In any case, I'll leave it to that PR (since I hope this one is going to merge first). |
8133eb7
to
12f3666
Compare
I have changed I believe the only remaining thing is for @daxpedda to fix the web wrt. scrolling, as I wrote shortly about in #3890 (comment) (if you don't have the time rn, I'm inclined to merge this fairly soon anyhow, and then track the completion of that in #3910). |
Resolves #2308, by adding
Window::safe_area
, which describes the area of the surface that is unobstructed by notches, bezels etc. The drawing code in the examples have been updated to draw a star inside the safe area, and the plain background outside of it.Also renamed
Window::inner_position
(introduced in #430) toWindow::surface_position
, and changed it to from screen coordinates to window coordinates, to better align how these coordinate systems work together.Finally, I've added some SVG images and documentation to describe how these coordinate systems work together. The images should be auto-adjusting to the page theme when viewed on docs.rs. See also #3891, whether we use window coordinates or surface coordinates is currently a bit confusing.
Completing implementation on all platforms is tracked in #3910
Fixes #1122
Fixes #2308
Fixes #3742
Fixes #2066
Fixes #2347
Fixes #2235