WindowSizeClass



WindowSizeClass represents breakpoints for a viewport. 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 WindowSizeClass.WIDTH_DP_EXPANDED_LOWER_BOUND width it might be more reasonable to have a side navigation.

An application use-case can be applied for apps that use a list-detail pattern. The app can use the WindowSizeClass.WIDTH_DP_MEDIUM_LOWER_BOUND 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.

To process a WindowSizeClass use the methods containsWindowSizeDp, containsWidthDp, containsHeightDp methods. Note these methods are order dependent as the smaller minWidthDp and minHeightDp would match all the breakpoints that are larger. Therefore when processing the selection should normally be ordered from larger to smaller breakpoints.

Summary

Constants

const Int

A lower bound for a size class with Expanded height in dp.

Cmn
const Int

A lower bound for a size class with Medium height in dp.

Cmn
const Int

A lower bound for a size class with Expanded width in dp.

Cmn
const Int

A lower bound for a size class with Medium width in dp.

Cmn

Public companion functions

WindowSizeClass
compute(dpWidth: Float, dpHeight: Float)

This function is deprecated. Use computeWindowSizeClass instead.

Cmn

Public companion properties

Set<WindowSizeClass>
Cmn

Public constructors

WindowSizeClass(minWidthDp: Int, minHeightDp: Int)
Cmn
WindowSizeClass(widthDp: Float, heightDp: Float)

A convenience constructor that will truncate to ints.

Cmn

Public functions

Boolean
containsHeightDp(heightDp: Int)

Returns true when minHeightDp is greater than or equal to heightDp, false otherwise.

Cmn
Boolean
containsWidthDp(widthDp: Int)

Returns true when minWidthDp is greater than or equal to widthDp, false otherwise.

Cmn
Boolean
containsWindowSizeDp(widthDp: Int, heightDp: Int)

Returns true when widthDp is greater than or equal to minWidthDp and heightDp is greater than or equal to minHeightDp, false otherwise.

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

Public properties

Int

Returns the lower bound for the height of the size class in dp.

Cmn
Int

Returns the lower bound for the width of the size class in dp.

Cmn
WindowHeightSizeClass

This property is deprecated. Use either isHeightAtLeast or isAtLeast to check matching bounds.

Cmn
WindowWidthSizeClass

This property is deprecated. Use either isWidthAtLeast or isAtLeast to check matching bounds.

Cmn

Constants

HEIGHT_DP_EXPANDED_LOWER_BOUND

const val HEIGHT_DP_EXPANDED_LOWER_BOUND = 900: Int

A lower bound for a size class with Expanded height in dp.

HEIGHT_DP_MEDIUM_LOWER_BOUND

const val HEIGHT_DP_MEDIUM_LOWER_BOUND = 480: Int

A lower bound for a size class with Medium height in dp.

WIDTH_DP_EXPANDED_LOWER_BOUND

const val WIDTH_DP_EXPANDED_LOWER_BOUND = 840: Int

A lower bound for a size class with Expanded width in dp.

WIDTH_DP_MEDIUM_LOWER_BOUND

const val WIDTH_DP_MEDIUM_LOWER_BOUND = 600: Int

A lower bound for a size class with Medium width in dp.

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.

Public companion properties

BREAKPOINTS_V1

val BREAKPOINTS_V1Set<WindowSizeClass>

Public constructors

WindowSizeClass

WindowSizeClass(minWidthDp: Int, minHeightDp: Int)

WindowSizeClass

WindowSizeClass(widthDp: Float, heightDp: Float)

A convenience constructor that will truncate to ints.

Public functions

containsHeightDp

fun containsHeightDp(heightDp: Int): Boolean

Returns true when minHeightDp is greater than or equal to heightDp, false otherwise. When processing a WindowSizeClass note that this method is order dependent. A WindowSizeClass with minWidthDp = 0 and minHeightDp = 0 will match any breakpoint, so the selection should normally go from largest to smallest breakpoints.

containsWidthDp

fun containsWidthDp(widthDp: Int): Boolean

Returns true when minWidthDp is greater than or equal to widthDp, false otherwise. When processing a WindowSizeClass note that this method is order dependent. A WindowSizeClass with minWidthDp = 0 and minHeightDp = 0 will match any breakpoint, so the selection should normally go from largest to smallest breakpoints.

containsWindowSizeDp

fun containsWindowSizeDp(widthDp: Int, heightDp: Int): Boolean

Returns true when widthDp is greater than or equal to minWidthDp and heightDp is greater than or equal to minHeightDp, false otherwise. When processing a WindowSizeClass note that this method is order dependent. A WindowSizeClass with minWidthDp = 0 and minHeightDp = 0 will match any breakpoint, so * the selection should normally go from largest to smallest breakpoints.

equals

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

hashCode

open fun hashCode(): Int

toString

open fun toString(): String

Public properties

minHeightDp

val minHeightDpInt

Returns the lower bound for the height of the size class in dp.

minWidthDp

val minWidthDpInt

Returns the lower bound for the width of the size class in dp.

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.