WindowSizeClass



WindowSizeClass represents breakpoints for a viewport. The recommended width and height break points are presented through windowWidthSizeClass and windowHeightSizeClass. Designers should design around the different combinations of width and height buckets. Developers should use the different buckets to specify the layouts. Ideally apps will work well in each bucket and by extension work well across multiple devices. If two devices are in similar buckets they should behave similarly.

This class is meant to be a common definition that can be shared across different device types. Application developers can use WindowSizeClass to have standard window buckets and design the UI around those buckets. Library developers can use these buckets to create different UI with respect to each bucket. This will help with consistency across multiple device types.

A library developer use-case can be creating some navigation UI library. For a size class with the WindowWidthSizeClass.EXPANDED width it might be more reasonable to have a side navigation. For a WindowWidthSizeClass.COMPACT width, a bottom navigation might be a better fit.

An application use-case can be applied for apps that use a list-detail pattern. The app can use the WindowWidthSizeClass.MEDIUM to determine if there is enough space to show the list and the detail side by side. If all apps follow this guidance then it will present a very consistent user experience.

In some cases developers or UI systems may decide to create their own break points. A developer might optimize for a window that is smaller than the supported break points or larger. A UI system might find that some break points are better suited than the recommended break points. In these cases developers may wish to specify their own custom break points and match using a when statement.

Summary

Public companion functions

WindowSizeClass
compute(dpWidth: Float, dpHeight: Float)

Computes the recommended WindowSizeClass for the given width and height in DP.

Cmn
WindowSizeClass
@ExperimentalWindowCoreApi
compute(widthPx: Int, heightPx: Int, density: Float)

Computes the WindowSizeClass for the given width and height in pixels with density.

Cmn

Public functions

open operator Boolean
equals(other: Any?)
Cmn
open Int
Cmn
open String
Cmn

Public properties

WindowHeightSizeClass

Returns the WindowHeightSizeClass that corresponds to the heightDp of the window.

Cmn
WindowWidthSizeClass

Returns the WindowWidthSizeClass that corresponds to the widthDp of the window.

Cmn

Public companion functions

compute

fun compute(dpWidth: Float, dpHeight: Float): WindowSizeClass

Computes the recommended WindowSizeClass for the given width and height in DP.

Parameters
dpWidth: Float

width of a window in DP.

dpHeight: Float

height of a window in DP.

Returns
WindowSizeClass

WindowSizeClass that is recommended for the given dimensions.

compute

@ExperimentalWindowCoreApi
fun compute(widthPx: Int, heightPx: Int, density: Float): WindowSizeClass

Computes the WindowSizeClass for the given width and height in pixels with density.

Parameters
widthPx: Int

width of a window in PX.

heightPx: Int

height of a window in PX.

density: Float

density of the display where the window is shown.

Returns
WindowSizeClass

WindowSizeClass that is recommended for the given dimensions.

Public functions

equals

open operator fun equals(other: Any?): Boolean

hashCode

open fun hashCode(): Int

toString

open fun toString(): String

Public properties

windowHeightSizeClass

val windowHeightSizeClassWindowHeightSizeClass

Returns the WindowHeightSizeClass that corresponds to the heightDp of the window.

windowWidthSizeClass

val windowWidthSizeClassWindowWidthSizeClass

Returns the WindowWidthSizeClass that corresponds to the widthDp of the window.