Class ScyllaUISafeArea
Turns an operating-system safe area and a designer margin into the four rectangle values a stretched layout needs: anchor minimum, anchor maximum, offset minimum and offset maximum.
Inherited Members
Namespace: Scylla.Core.Util.UI
Assembly: ScyllaCore.dll
Syntax
public static class ScyllaUISafeArea
Remarks
The calculation is pure. It reads nothing from the scene and touches no
Unity object, which is what makes it testable without a canvas and
reusable by any presentation layer. ScyllaUIScreenMargin
applies the result to a RectTransform; a UI Toolkit panel root can
apply the same numbers as padding.
The safe area is expressed in pixels and converted to normalized anchors per edge, so an edge whose toggle is off reaches the physical screen boundary regardless of any notch or home indicator. The designer margin is then applied on top as offsets, with percent values resolving against the parent dimensions rather than the screen.
Methods
Compute(Rect?, float, float, Rect, bool, bool, bool, bool, ScyllaUIEdgeInsets, float, float, out Vector2, out Vector2, out Vector2, out Vector2)
Resolves the safe area and designer margin into anchor and offset values.
Declaration
public static void Compute(Rect? overrideSafeArea, float screenWidth, float screenHeight, Rect osSafeArea, bool applyTop, bool applyRight, bool applyBottom, bool applyLeft, ScyllaUIEdgeInsets designerMargin, float parentWidth, float parentHeight, out Vector2 anchorMin, out Vector2 anchorMax, out Vector2 offsetMin, out Vector2 offsetMax)
Parameters
| Type | Name | Description |
|---|---|---|
| Rect? | overrideSafeArea | A substitute safe area, or |
| float | screenWidth | Screen width in pixels. Values below 1 are raised to 1. |
| float | screenHeight | Screen height in pixels. Values below 1 are raised to 1. |
| Rect | osSafeArea | The operating-system safe area in pixels. |
| bool | applyTop | Whether the top edge honors the safe area. |
| bool | applyRight | Whether the right edge honors the safe area. |
| bool | applyBottom | Whether the bottom edge honors the safe area. |
| bool | applyLeft | Whether the left edge honors the safe area. |
| ScyllaUIEdgeInsets | designerMargin | Additional per-edge inset applied after the safe area. |
| float | parentWidth | Parent width that percent margins resolve against. |
| float | parentHeight | Parent height that percent margins resolve against. |
| Vector2 | anchorMin | Receives the normalized lower-left anchor. |
| Vector2 | anchorMax | Receives the normalized upper-right anchor. |
| Vector2 | offsetMin | Receives the left and bottom offsets in pixels. |
| Vector2 | offsetMax | Receives the negated right and top offsets in pixels. |
Remarks
Pass overrideSafeArea to simulate a device cutout
deterministically in a demo or a test. When it is null the
operating-system rectangle in osSafeArea is used,
except when the screen reports no dimensions at all, which happens in
batch mode before the graphics device exists. In that case the whole
screen is treated as safe so a caller can still run.
The returned offsetMax follows the Unity
convention of negative right and top insets, so it can be assigned to
a RectTransform unchanged.