Skip to content

Commit dbcdb6f

Browse files
madsmtmdaxpedda
andauthored
Add safe area and document coordinate systems (rust-windowing#3890)
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. This is fully implemented on macOS and iOS, and partially on the web. Co-authored-by: daxpedda <[email protected]>
1 parent d0c6c34 commit dbcdb6f

File tree

30 files changed

+796
-211
lines changed

30 files changed

+796
-211
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ objc2-foundation = { version = "0.2.2", features = [
149149
"NSDictionary",
150150
"NSDistributedNotificationCenter",
151151
"NSEnumerator",
152+
"NSGeometry",
152153
"NSKeyValueObserving",
153154
"NSNotification",
154155
"NSObjCRuntime",
@@ -296,6 +297,7 @@ web_sys = { package = "web-sys", version = "0.3.70", features = [
296297
"FocusEvent",
297298
"HtmlCanvasElement",
298299
"HtmlElement",
300+
"HtmlHtmlElement",
299301
"HtmlImageElement",
300302
"ImageBitmap",
301303
"ImageBitmapOptions",

docs/res/ATTRIBUTION.md renamed to docs/ATTRIBUTION.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,10 @@ by [Tomiĉo] (https://commons.wikimedia.org/wiki/User:Tomi%C4%89o). It was
99
originally released under the [CC-BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/deed.en)
1010
License. Minor modifications have been made by [John Nunley](https://github.com/notgull),
1111
which have been released under the same license as a derivative work.
12+
13+
## `coordinate-systems*`
14+
15+
These files are created by [Mads Marquart](https://github.com/madsmtm) using
16+
[draw.io](https://draw.io/), and compressed using [svgomg.net](https://svgomg.net/).
17+
18+
They are licensed under the [CC-BY 4.0](https://creativecommons.org/licenses/by/4.0/) license.

docs/coordinate-systems.drawio

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
<mxfile host="app.diagrams.net" agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:132.0) Gecko/20100101 Firefox/132.0" version="24.8.6" pages="2">
2+
<diagram name="desktop" id="3DDum1nDijUk3y7wIDRm">
3+
<mxGraphModel dx="1080" dy="707" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1000" pageHeight="500" math="0" shadow="0">
4+
<root>
5+
<mxCell id="0" />
6+
<mxCell id="1" parent="0" />
7+
<mxCell id="cRYnzpdCW-J0f_YpP3mc-1" value="" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#E8E8E8;fontColor=#333333;strokeColor=#666666;" parent="1" vertex="1">
8+
<mxGeometry x="200" y="80" width="480" height="360" as="geometry" />
9+
</mxCell>
10+
<mxCell id="cRYnzpdCW-J0f_YpP3mc-4" value="" style="rounded=1;whiteSpace=wrap;html=1;shadow=0;fillColor=#d5e8d4;strokeColor=#666666;" parent="1" vertex="1">
11+
<mxGeometry x="260" y="340" width="360" height="40" as="geometry" />
12+
</mxCell>
13+
<mxCell id="cRYnzpdCW-J0f_YpP3mc-2" value="" style="rounded=1;whiteSpace=wrap;html=1;shadow=0;fillColor=#dae8fc;strokeColor=#666666;" parent="1" vertex="1">
14+
<mxGeometry x="260" y="140" width="360" height="80" as="geometry" />
15+
</mxCell>
16+
<mxCell id="cRYnzpdCW-J0f_YpP3mc-3" value="" style="rounded=0;whiteSpace=wrap;html=1;fillColor=#DBDBDB;strokeColor=#666666;fontColor=#333333;" parent="1" vertex="1">
17+
<mxGeometry x="200" y="60" width="480" height="20" as="geometry" />
18+
</mxCell>
19+
<mxCell id="cRYnzpdCW-J0f_YpP3mc-5" value="" style="rounded=0;whiteSpace=wrap;html=1;strokeColor=none;fillColor=#d5e8d4;" parent="1" vertex="1">
20+
<mxGeometry x="260" y="180" width="360" height="180" as="geometry" />
21+
</mxCell>
22+
<mxCell id="cRYnzpdCW-J0f_YpP3mc-6" value="" style="endArrow=none;html=1;rounded=0;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;strokeColor=#666666;" parent="1" source="cRYnzpdCW-J0f_YpP3mc-4" target="cRYnzpdCW-J0f_YpP3mc-2" edge="1">
23+
<mxGeometry width="50" height="50" relative="1" as="geometry">
24+
<mxPoint x="10" y="310" as="sourcePoint" />
25+
<mxPoint x="60" y="260" as="targetPoint" />
26+
</mxGeometry>
27+
</mxCell>
28+
<mxCell id="cRYnzpdCW-J0f_YpP3mc-7" value="" style="endArrow=none;html=1;rounded=0;exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;strokeColor=#666666;" parent="1" source="cRYnzpdCW-J0f_YpP3mc-4" target="cRYnzpdCW-J0f_YpP3mc-2" edge="1">
29+
<mxGeometry width="50" height="50" relative="1" as="geometry">
30+
<mxPoint x="770" y="570" as="sourcePoint" />
31+
<mxPoint x="770" y="210" as="targetPoint" />
32+
</mxGeometry>
33+
</mxCell>
34+
<mxCell id="cRYnzpdCW-J0f_YpP3mc-8" value="" style="endArrow=none;html=1;rounded=0;exitX=0;exitY=0.5;exitDx=0;exitDy=0;entryX=1;entryY=0;entryDx=0;entryDy=0;strokeColor=#666666;" parent="1" source="cRYnzpdCW-J0f_YpP3mc-2" target="cRYnzpdCW-J0f_YpP3mc-5" edge="1">
35+
<mxGeometry width="50" height="50" relative="1" as="geometry">
36+
<mxPoint x="220.00000000000023" y="179.69" as="sourcePoint" />
37+
<mxPoint x="740.0000000000002" y="179.69" as="targetPoint" />
38+
</mxGeometry>
39+
</mxCell>
40+
<mxCell id="cRYnzpdCW-J0f_YpP3mc-9" value="&lt;font&gt;outer_position&lt;/font&gt;" style="endArrow=blockThin;html=1;strokeWidth=3;rounded=0;exitX=0;exitY=0;exitDx=0;exitDy=0;dashed=1;align=right;fontSize=20;fontFamily=monospace;fontColor=#6C8EBF;labelBackgroundColor=none;spacingLeft=0;spacingRight=15;spacing=0;fillColor=#dae8fc;strokeColor=#6C8EBF;endFill=1;startArrow=oval;startFill=1;endSize=6;targetPerimeterSpacing=0;entryX=0;entryY=0;entryDx=0;entryDy=0;" parent="1" source="cRYnzpdCW-J0f_YpP3mc-3" edge="1" target="cRYnzpdCW-J0f_YpP3mc-2">
41+
<mxGeometry x="-0.36" y="-24" width="50" height="50" relative="1" as="geometry">
42+
<mxPoint x="80" y="160" as="sourcePoint" />
43+
<mxPoint x="240" y="160" as="targetPoint" />
44+
<mxPoint as="offset" />
45+
</mxGeometry>
46+
</mxCell>
47+
<mxCell id="cRYnzpdCW-J0f_YpP3mc-10" value="&lt;font&gt;outer_size&lt;/font&gt;" style="endArrow=none;html=1;strokeWidth=3;rounded=0;dashed=1;align=left;fontSize=20;fontFamily=monospace;fontColor=#6C8EBF;labelBackgroundColor=none;spacingLeft=15;spacingRight=0;spacing=0;exitX=1;exitY=0;exitDx=0;exitDy=0;fillColor=#dae8fc;strokeColor=#6c8ebf;entryX=1;entryY=1;entryDx=0;entryDy=0;" parent="1" source="cRYnzpdCW-J0f_YpP3mc-2" edge="1" target="cRYnzpdCW-J0f_YpP3mc-4">
48+
<mxGeometry width="50" height="50" relative="1" as="geometry">
49+
<mxPoint x="850" y="170" as="sourcePoint" />
50+
<mxPoint x="760" y="420" as="targetPoint" />
51+
<Array as="points">
52+
<mxPoint x="860" y="140" />
53+
<mxPoint x="860" y="380" />
54+
</Array>
55+
<mxPoint as="offset" />
56+
</mxGeometry>
57+
</mxCell>
58+
<mxCell id="cRYnzpdCW-J0f_YpP3mc-11" value="&lt;font&gt;surface_size&lt;/font&gt;" style="endArrow=none;html=1;strokeWidth=3;rounded=0;dashed=1;align=left;fontSize=20;fontFamily=monospace;fontColor=#82B366;labelBackgroundColor=none;spacingLeft=15;spacingRight=0;spacing=0;entryX=1;entryY=1;entryDx=0;entryDy=0;fillColor=#d5e8d4;strokeColor=#82B366;" parent="1" target="cRYnzpdCW-J0f_YpP3mc-4" edge="1">
59+
<mxGeometry x="0.0526" width="50" height="50" relative="1" as="geometry">
60+
<mxPoint x="600" y="180" as="sourcePoint" />
61+
<mxPoint x="760" y="420" as="targetPoint" />
62+
<Array as="points">
63+
<mxPoint x="700" y="180" />
64+
<mxPoint x="700" y="380" />
65+
</Array>
66+
<mxPoint as="offset" />
67+
</mxGeometry>
68+
</mxCell>
69+
<mxCell id="cRYnzpdCW-J0f_YpP3mc-12" value="&lt;font&gt;surface_position&lt;/font&gt;" style="endArrow=blockThin;html=1;strokeWidth=3;rounded=0;dashed=1;align=right;fontSize=20;fontFamily=monospace;fontColor=#82B366;labelBackgroundColor=none;spacingLeft=0;spacingRight=15;spacing=0;fillColor=#d5e8d4;strokeColor=#82b366;exitX=0;exitY=0;exitDx=0;exitDy=0;entryX=0;entryY=0;entryDx=0;entryDy=0;curved=1;startArrow=oval;startFill=1;endFill=1;" parent="1" source="cRYnzpdCW-J0f_YpP3mc-2" target="cRYnzpdCW-J0f_YpP3mc-5" edge="1">
70+
<mxGeometry y="-50" width="50" height="50" relative="1" as="geometry">
71+
<mxPoint x="140" y="140" as="sourcePoint" />
72+
<mxPoint x="160" y="200" as="targetPoint" />
73+
<Array as="points">
74+
<mxPoint x="250" y="160" />
75+
</Array>
76+
<mxPoint x="-5" y="-22" as="offset" />
77+
</mxGeometry>
78+
</mxCell>
79+
</root>
80+
</mxGraphModel>
81+
</diagram>
82+
<diagram name="mobile" id="D5mAeJSS4Z33KEKjPCBt">
83+
<mxGraphModel dx="1710" dy="1120" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="720" pageHeight="720" math="0" shadow="0">
84+
<root>
85+
<mxCell id="0" />
86+
<mxCell id="1" parent="0" />
87+
<mxCell id="RxwCrVmIsQwV7z5iJ9nY-1" value="" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#E8E8E8;fontColor=#333333;strokeColor=#666666;" parent="1" vertex="1">
88+
<mxGeometry x="200" y="40" width="320" height="640" as="geometry" />
89+
</mxCell>
90+
<mxCell id="RxwCrVmIsQwV7z5iJ9nY-2" value="" style="rounded=1;whiteSpace=wrap;html=1;shadow=0;fillColor=#d5e8d4;strokeColor=#82b366;" parent="1" vertex="1">
91+
<mxGeometry x="210" y="50" width="300" height="620" as="geometry" />
92+
</mxCell>
93+
<mxCell id="RxwCrVmIsQwV7z5iJ9nY-4" value="" style="rounded=0;whiteSpace=wrap;html=1;shadow=0;fillColor=#ffe6cc;strokeColor=#d79b00;" parent="1" vertex="1">
94+
<mxGeometry x="210" y="90" width="300" height="540" as="geometry" />
95+
</mxCell>
96+
<mxCell id="RxwCrVmIsQwV7z5iJ9nY-20" value="" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#DBDBDB;strokeColor=#666666;fontColor=#333333;" parent="1" vertex="1">
97+
<mxGeometry x="290" y="640" width="140" height="10" as="geometry" />
98+
</mxCell>
99+
<mxCell id="RxwCrVmIsQwV7z5iJ9nY-3" value="" style="rounded=1;whiteSpace=wrap;html=1;fillColor=#DBDBDB;strokeColor=#666666;fontColor=#333333;" parent="1" vertex="1">
100+
<mxGeometry x="300" y="50" width="120" height="30" as="geometry" />
101+
</mxCell>
102+
<mxCell id="RxwCrVmIsQwV7z5iJ9nY-12" value="&lt;font&gt;surface_size&lt;/font&gt;" style="endArrow=none;html=1;strokeWidth=3;rounded=0;dashed=1;align=left;fontSize=20;fontFamily=monospace;fontColor=#82B366;labelBackgroundColor=none;spacingLeft=15;spacingRight=15;spacing=0;fillColor=#d5e8d4;strokeColor=#82b366;exitX=1;exitY=0;exitDx=0;exitDy=0;" parent="1" source="RxwCrVmIsQwV7z5iJ9nY-2" edge="1">
103+
<mxGeometry width="50" height="50" relative="1" as="geometry">
104+
<mxPoint x="210" y="50" as="sourcePoint" />
105+
<mxPoint x="510" y="670" as="targetPoint" />
106+
<Array as="points">
107+
<mxPoint x="560" y="50" />
108+
<mxPoint x="560" y="670" />
109+
</Array>
110+
<mxPoint as="offset" />
111+
</mxGeometry>
112+
</mxCell>
113+
<mxCell id="NrHAzeOh65jb3hkBOxW9-1" value="&lt;div&gt;safe_area.top&lt;/div&gt;" style="endArrow=blockThin;html=1;strokeWidth=3;rounded=0;align=right;fontSize=20;fontFamily=monospace;fontColor=#D79B00;labelBackgroundColor=none;spacingLeft=0;spacingRight=15;spacing=0;fillColor=#ffe6cc;strokeColor=#d79b00;startArrow=blockThin;startFill=1;endFill=1;" edge="1" parent="1">
114+
<mxGeometry width="50" height="50" relative="1" as="geometry">
115+
<mxPoint x="180" y="50" as="sourcePoint" />
116+
<mxPoint x="180" y="90" as="targetPoint" />
117+
<mxPoint as="offset" />
118+
</mxGeometry>
119+
</mxCell>
120+
<mxCell id="NrHAzeOh65jb3hkBOxW9-5" value="&lt;div&gt;safe_area.bottom&lt;/div&gt;" style="endArrow=blockThin;html=1;strokeWidth=3;rounded=0;align=right;fontSize=20;fontFamily=monospace;fontColor=#D79B00;labelBackgroundColor=none;spacingLeft=0;spacingRight=15;spacing=0;fillColor=#ffe6cc;strokeColor=#d79b00;startArrow=blockThin;startFill=1;endFill=1;" edge="1" parent="1">
121+
<mxGeometry width="50" height="50" relative="1" as="geometry">
122+
<mxPoint x="180" y="670" as="sourcePoint" />
123+
<mxPoint x="180" y="630" as="targetPoint" />
124+
<mxPoint as="offset" />
125+
</mxGeometry>
126+
</mxCell>
127+
</root>
128+
</mxGraphModel>
129+
</diagram>
130+
</mxfile>
Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)