From 870730903b315c824fb13a7ec19f3dee06c8b021 Mon Sep 17 00:00:00 2001 From: Igor Demin Date: Wed, 4 Aug 2021 13:36:19 +0300 Subject: [PATCH] Update README.md --- tutorials/Window_API_new/README.md | 35 ++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tutorials/Window_API_new/README.md b/tutorials/Window_API_new/README.md index 232344e1bb..f6e31327ec 100644 --- a/tutorials/Window_API_new/README.md +++ b/tutorials/Window_API_new/README.md @@ -262,6 +262,41 @@ Use it if: - you don't need custom closing logic - you don't need to change the window parameters after it is already created +## Adaptive window size +Sometimes we want to show some content as a whole without knowing in advance what exactly will be shown, meaning that we don’t know the optimal window dimensions for it. By setting one or both dimensions of your window’s WindowSize to Dp.Unspecified, Compose for Desktop will automatically adjust the initial size of your window in that dimension to accommodate its content: +``` +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.material.Text +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.unit.Dp +import androidx.compose.ui.unit.dp +import androidx.compose.ui.window.Window +import androidx.compose.ui.window.application +import androidx.compose.ui.window.rememberWindowState + +fun main() = application { + Window( + onCloseRequest = ::exitApplication, + state = rememberWindowState(width = Dp.Unspecified, height = Dp.Unspecified), + title = "Adaptive", + resizable = false + ) { + Column(Modifier.background(Color(0xFFEEEEEE))) { + Row { + Text("label 1", Modifier.size(100.dp, 100.dp).padding(10.dp).background(Color.White)) + Text("label 2", Modifier.size(150.dp, 200.dp).padding(5.dp).background(Color.White)) + Text("label 3", Modifier.size(200.dp, 300.dp).padding(25.dp).background(Color.White)) + } + } + } +} +``` + ## Changing the state (maximized, minimized, fullscreen, size, position) of the window. Some states of the native window are moved into a separate API class, `WindowState`. You can change its properties in callbacks or observe it in Composable's.