desktopMain.io.github.lyxnx.compose.screenables.ScreenDefinition.jvm.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of screenables-desktop Show documentation
Show all versions of screenables-desktop Show documentation
Jetpack Compose screen definition utility
package io.github.lyxnx.compose.screenables
import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
import androidx.compose.runtime.Composable
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalWindowInfo
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.toSize
/**
* Creates a screen definition
*/
@OptIn(ExperimentalMaterial3WindowSizeClassApi::class)
@Composable
public actual fun calculateScreenDefinition(): ScreenDefinition {
return ScreenDefinition(
foldOrientation = null,
foldWidth = 0.dp,
foldHeight = 0.dp,
leftContentSize = DpSize.Zero,
rightContentSize = DpSize.Zero,
topContentSize = DpSize.Zero,
bottomContentSize = DpSize.Zero,
isPortrait = false, // desktop doesn't have a concept of portrait or landscape and only has different sized windows
windowSizeClass = calculateWindowSizeClass(),
windowSize = windowSize()
)
}
@OptIn(ExperimentalComposeUiApi::class)
@Composable
private fun windowSize(): DpSize = with(LocalDensity.current) {
LocalWindowInfo.current.containerSize.toSize().toDpSize()
}