Provides a Safe Area Container for Unity's UI Toolkit.
The goal of the safe area container is to provide a custom control to simplify handling safe areas with UI Toolkit on relevant devices.
- Option to collapse margins with the safe area.
- Option to exclude specific safe area edges.
- Option to exclude safe area on tvOS.
The SafeArea container is available in the Library in UI Builder and can be found under Project → Custom Controls and can be dragged into the UI hierarchy.
The SafeArea container should be added as the top element in the hierarchy to ensure that it can fill up the entire screen. All child elements dropped into the SafeArea container will live inside safe-area-content-container
and be adjusted accordingly depending on the current device SafeArea.
Margins can be set on the SafeArea container, which can be useful when running on devices that does not utilize a safe area.
The SafeArea container has a selection of custom attributes that can be set in the UI Builder inspector.
The container margins and the safe area is collapsed by default. That can be disabled in the inspector.
Take a look at these screenshots which helps illustrate the differences how margin, safe area and collapse comes together. In each example the margin is set to 10px 10px 0px 10px
.
- For a device without a safe area, the margin values are used as-is and collapse margins doesn't play a part as there is no safe area to collapse with.
- For a device with a safe area the margins are collapsed with the safe area. The margin value is used if it would be larger than the safe area.
- If
Collapse Margins
is disabled, the margin is added to the safe area.
With exclude edges, the safe area value of left
, right
, top
and bottom
edges can optionally be excluded from the calculations. If an edge is excluded, only the margin value for that edge will be used.
This option excludes the safe area values for all edges on tvOS. If selected, tvOS builds will not use safe area but only the margin values.
Requires Unity 2021.3 LTS or higher.
The package is available on the OpenUPM registry. It's recommended to install it via openupm-cli.
openupm add com.bitbebop.ui-toolkit-safe-area
Install the package directly in Unity Package Manger using this URL:
https://github.com/artstorm/ui-toolkit-safe-area.git?path=/Packages/com.bitbebop.ui-toolkit-safe-area
Open Unity Package Manager → + → Add package from git URL:
Paste URL: