@ -8,7 +8,7 @@ In this tutorial we will show you how to work with images using Compose for Desk
Using images from application resources is very simple. Suppose we have a PNG image that is placed in the `resources` directory in our project. For this tutorial we will use the image sample:
Using images from application resources is very simple. Suppose we have a PNG image that is placed in the `resources` directory in our project. For this tutorial we will use the image sample:
![Sample](sample.png)
<imgalt="Sample"src="sample.png"height="500"/>
```kotlin
```kotlin
import androidx.compose.foundation.Image
import androidx.compose.foundation.Image
@ -28,7 +28,7 @@ fun main() = singleWindowApplication {
@ -74,7 +74,7 @@ fun main() = singleWindowApplication {
Note the annotation `@OptIn(ExperimentalComposeUiApi::class)`. Some keys related APIs are still an experimental feature of Compose, and later API changes are possible. So it requires the use of a special annotation to emphasize the experimental nature of the code.
Note the annotation `@OptIn(ExperimentalComposeUiApi::class)`. Some keys related APIs are still an experimental feature of Compose, and later API changes are possible. So it requires the use of a special annotation to emphasize the experimental nature of the code.
To move focus in custom order we need to create a `FocusRequester` and apply the `Modifier.focusOrder` modifier to each component you want to navigate.
To move focus in custom order we need to create a `FocusRequester` and apply the `Modifier.focusOrder` modifier to each component you want to navigate.
If the window requires some custom logic on close (for example, to show a dialog), you can override the close action using `onCloseRequest`.
If the window requires some custom logic on close (for example, to show a dialog), you can override the close action using `onCloseRequest`.
@ -120,7 +120,7 @@ fun main() = application {
}
}
}
}
```
```
<imgsrc="ask_to_close.gif"height="309"/>
<imgalt="Ask to close"src="ask_to_close.gif"height="309"/>
If you don't need to close the window and just need to hide it (for example to the tray), you can change the `windowState.isVisible` state:
If you don't need to close the window and just need to hide it (for example to the tray), you can change the `windowState.isVisible` state:
```kotlin
```kotlin
@ -177,7 +177,7 @@ object TrayIcon : Painter() {
}
}
}
}
```
```
<imgsrc="hide_instead_of_close.gif"height="308"/>
<imgalt="Hide instead of closing"src="hide_instead_of_close.gif"height="308"/>
If an application has multiple windows, then it is better to put its state into a separate class and open/close window in response to `mutableStateListOf` changes (see [notepad example](https://github.com/JetBrains/compose-jb/tree/master/examples/notepad) for more complex use cases):
If an application has multiple windows, then it is better to put its state into a separate class and open/close window in response to `mutableStateListOf` changes (see [notepad example](https://github.com/JetBrains/compose-jb/tree/master/examples/notepad) for more complex use cases):
## Changing the state (maximized, minimized, fullscreen, size, position) of the window.
## Changing the state (maximized, minimized, fullscreen, size, position) of the window.
@ -378,7 +378,7 @@ fun main() = application {
}
}
}
}
```
```
<imgsrc="state.gif"height="231"/>
<imgalt="Changing the state"src="state.gif"height="231"/>
## Listening the state of the window
## Listening the state of the window
Reading the state in composition is useful when you need to update UI, but there are cases when you need to react to the state changes and send a value to another non-composable level of your application (write it to the database, for example):
Reading the state in composition is useful when you need to update UI, but there are cases when you need to react to the state changes and send a value to another non-composable level of your application (write it to the database, for example):
@ -579,7 +579,7 @@ fun main() = application {
}
}
}
}
```
```
Note that `WindowDraggableArea` can be used only inside `singleWindowApplication`, `Window` and `Dialog`. If you need to use it in another Composable function, pass `WindowScope` as a reciever there:
Note that `WindowDraggableArea` can be used only inside `singleWindowApplication`, `Window` and `Dialog`. If you need to use it in another Composable function, pass `WindowScope` as a receiver there:
```kotlin
```kotlin
import androidx.compose.foundation.background
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Box
@ -605,5 +605,4 @@ private fun WindowScope.AppWindowTitleBar() = WindowDraggableArea {