|
|
@ -19,7 +19,7 @@ import androidx.compose.ui.window.application |
|
|
|
|
|
|
|
|
|
|
|
@OptIn(ExperimentalComposeUiApi::class) |
|
|
|
@OptIn(ExperimentalComposeUiApi::class) |
|
|
|
fun main() = application { |
|
|
|
fun main() = application { |
|
|
|
Window { |
|
|
|
Window(onCloseRequest = ::exitApplication) { |
|
|
|
// Content |
|
|
|
// Content |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -41,7 +41,7 @@ import androidx.compose.ui.window.application |
|
|
|
fun main() = application { |
|
|
|
fun main() = application { |
|
|
|
var fileName by remember { mutableStateOf("Untitled") } |
|
|
|
var fileName by remember { mutableStateOf("Untitled") } |
|
|
|
|
|
|
|
|
|
|
|
Window(title = "$fileName - Editor") { |
|
|
|
Window(onCloseRequest = ::exitApplication, title = "$fileName - Editor") { |
|
|
|
Button(onClick = { fileName = "note.txt" }) { |
|
|
|
Button(onClick = { fileName = "note.txt" }) { |
|
|
|
Text("Save") |
|
|
|
Text("Save") |
|
|
|
} |
|
|
|
} |
|
|
@ -74,11 +74,11 @@ fun main() = application { |
|
|
|
isPerformingTask = false |
|
|
|
isPerformingTask = false |
|
|
|
} |
|
|
|
} |
|
|
|
if (isPerformingTask) { |
|
|
|
if (isPerformingTask) { |
|
|
|
Window { |
|
|
|
Window(onCloseRequest = ::exitApplication) { |
|
|
|
Text("Performing some tasks. Please wait!") |
|
|
|
Text("Performing some tasks. Please wait!") |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
Window { |
|
|
|
Window(onCloseRequest = ::exitApplication) { |
|
|
|
Text("Hello, World!") |
|
|
|
Text("Hello, World!") |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -112,8 +112,8 @@ fun main() = application { |
|
|
|
) { |
|
|
|
) { |
|
|
|
if (isAskingToClose) { |
|
|
|
if (isAskingToClose) { |
|
|
|
Dialog( |
|
|
|
Dialog( |
|
|
|
|
|
|
|
onCloseRequest = { isAskingToClose = false }, |
|
|
|
title = "Close the document without saving?", |
|
|
|
title = "Close the document without saving?", |
|
|
|
onCloseRequest = { isAskingToClose = false } |
|
|
|
|
|
|
|
) { |
|
|
|
) { |
|
|
|
Button( |
|
|
|
Button( |
|
|
|
onClick = { isOpen = false } |
|
|
|
onClick = { isOpen = false } |
|
|
@ -150,9 +150,9 @@ fun main() = application { |
|
|
|
val state = rememberWindowState() |
|
|
|
val state = rememberWindowState() |
|
|
|
|
|
|
|
|
|
|
|
Window( |
|
|
|
Window( |
|
|
|
|
|
|
|
onCloseRequest = { state.isVisible = false }, |
|
|
|
state, |
|
|
|
state, |
|
|
|
title = "Counter", |
|
|
|
title = "Counter", |
|
|
|
onCloseRequest = { state.isVisible = false } |
|
|
|
|
|
|
|
) { |
|
|
|
) { |
|
|
|
var counter by remember { mutableStateOf(0) } |
|
|
|
var counter by remember { mutableStateOf(0) } |
|
|
|
LaunchedEffect(Unit) { |
|
|
|
LaunchedEffect(Unit) { |
|
|
@ -211,7 +211,7 @@ fun main() = application { |
|
|
|
@Composable |
|
|
|
@Composable |
|
|
|
private fun MyWindow( |
|
|
|
private fun MyWindow( |
|
|
|
state: MyWindowState |
|
|
|
state: MyWindowState |
|
|
|
) = Window(title = state.title, onCloseRequest = state::close) { |
|
|
|
) = Window(onCloseRequest = state::close, title = state.title) { |
|
|
|
MenuBar { |
|
|
|
MenuBar { |
|
|
|
Menu("File") { |
|
|
|
Menu("File") { |
|
|
|
Item("New window", onClick = state.openNewWindow) |
|
|
|
Item("New window", onClick = state.openNewWindow) |
|
|
@ -272,22 +272,41 @@ import androidx.compose.ui.ExperimentalComposeUiApi |
|
|
|
import androidx.compose.ui.Modifier |
|
|
|
import androidx.compose.ui.Modifier |
|
|
|
import androidx.compose.ui.unit.dp |
|
|
|
import androidx.compose.ui.unit.dp |
|
|
|
import androidx.compose.ui.window.Window |
|
|
|
import androidx.compose.ui.window.Window |
|
|
|
|
|
|
|
import androidx.compose.ui.window.WindowPlacement |
|
|
|
import androidx.compose.ui.window.application |
|
|
|
import androidx.compose.ui.window.application |
|
|
|
import androidx.compose.ui.window.rememberWindowState |
|
|
|
import androidx.compose.ui.window.rememberWindowState |
|
|
|
|
|
|
|
|
|
|
|
@OptIn(ExperimentalComposeUiApi::class) |
|
|
|
@OptIn(ExperimentalComposeUiApi::class) |
|
|
|
fun main() = application { |
|
|
|
fun main() = application { |
|
|
|
val state = rememberWindowState(isMaximized = true) |
|
|
|
val state = rememberWindowState(placement = WindowPlacement.Maximized) |
|
|
|
|
|
|
|
|
|
|
|
Window(state) { |
|
|
|
Window(onCloseRequest = ::exitApplication, state) { |
|
|
|
Column { |
|
|
|
Column { |
|
|
|
Row(verticalAlignment = Alignment.CenterVertically) { |
|
|
|
Row(verticalAlignment = Alignment.CenterVertically) { |
|
|
|
Checkbox(state.isFullscreen, { state.isFullscreen = !state.isFullscreen }) |
|
|
|
Checkbox( |
|
|
|
|
|
|
|
state.placement == WindowPlacement.Fullscreen, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
state.placement = if (it) { |
|
|
|
|
|
|
|
WindowPlacement.Fullscreen |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
WindowPlacement.Floating |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
) |
|
|
|
Text("isFullscreen") |
|
|
|
Text("isFullscreen") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Row(verticalAlignment = Alignment.CenterVertically) { |
|
|
|
Row(verticalAlignment = Alignment.CenterVertically) { |
|
|
|
Checkbox(state.isMaximized, { state.isMaximized = !state.isMaximized }) |
|
|
|
Checkbox( |
|
|
|
|
|
|
|
state.placement == WindowPlacement.Fullscreen, |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
state.placement = if (it) { |
|
|
|
|
|
|
|
WindowPlacement.Maximized |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
WindowPlacement.Floating |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
) |
|
|
|
Text("isMaximized") |
|
|
|
Text("isMaximized") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -299,7 +318,10 @@ fun main() = application { |
|
|
|
Text( |
|
|
|
Text( |
|
|
|
"Position ${state.position}", |
|
|
|
"Position ${state.position}", |
|
|
|
Modifier.clickable { |
|
|
|
Modifier.clickable { |
|
|
|
state.position = state.position.copy(x = state.position.x + 10.dp) |
|
|
|
val position = state.position |
|
|
|
|
|
|
|
if (position is WindowPosition.Absolute) { |
|
|
|
|
|
|
|
state.position = position.copy(x = state.position.x + 10.dp) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
@ -362,43 +384,21 @@ private fun onWindowRelocate(position: WindowPosition) { |
|
|
|
|
|
|
|
|
|
|
|
## Handle window-level shortcuts |
|
|
|
## Handle window-level shortcuts |
|
|
|
```kotlin |
|
|
|
```kotlin |
|
|
|
import androidx.compose.foundation.layout.Box |
|
|
|
|
|
|
|
import androidx.compose.material.TextField |
|
|
|
import androidx.compose.material.TextField |
|
|
|
import androidx.compose.runtime.LaunchedEffect |
|
|
|
|
|
|
|
import androidx.compose.runtime.getValue |
|
|
|
|
|
|
|
import androidx.compose.runtime.mutableStateOf |
|
|
|
|
|
|
|
import androidx.compose.runtime.remember |
|
|
|
|
|
|
|
import androidx.compose.runtime.setValue |
|
|
|
|
|
|
|
import androidx.compose.ui.ExperimentalComposeUiApi |
|
|
|
import androidx.compose.ui.ExperimentalComposeUiApi |
|
|
|
import androidx.compose.ui.Modifier |
|
|
|
|
|
|
|
import androidx.compose.ui.focus.FocusRequester |
|
|
|
|
|
|
|
import androidx.compose.ui.focus.focusRequester |
|
|
|
|
|
|
|
import androidx.compose.ui.focus.focusTarget |
|
|
|
|
|
|
|
import androidx.compose.ui.input.key.Key |
|
|
|
import androidx.compose.ui.input.key.Key |
|
|
|
import androidx.compose.ui.input.key.key |
|
|
|
import androidx.compose.ui.input.key.key |
|
|
|
import androidx.compose.ui.input.key.onPreviewKeyEvent |
|
|
|
|
|
|
|
import androidx.compose.ui.window.Window |
|
|
|
import androidx.compose.ui.window.Window |
|
|
|
import androidx.compose.ui.window.application |
|
|
|
import androidx.compose.ui.window.application |
|
|
|
|
|
|
|
|
|
|
|
@OptIn(ExperimentalComposeUiApi::class) |
|
|
|
@OptIn(ExperimentalComposeUiApi::class) |
|
|
|
fun main() = application { |
|
|
|
fun main() = application { |
|
|
|
var isOpen by remember { mutableStateOf(true) } |
|
|
|
Window( |
|
|
|
|
|
|
|
onCloseRequest = ::exitApplication, |
|
|
|
if (isOpen) { |
|
|
|
onPreviewKeyEvent = { |
|
|
|
Window { |
|
|
|
|
|
|
|
val focusRequester = remember(::FocusRequester) |
|
|
|
|
|
|
|
LaunchedEffect(Unit) { |
|
|
|
|
|
|
|
focusRequester.requestFocus() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Box( |
|
|
|
|
|
|
|
Modifier |
|
|
|
|
|
|
|
.focusRequester(focusRequester) |
|
|
|
|
|
|
|
.focusTarget() |
|
|
|
|
|
|
|
.onPreviewKeyEvent { |
|
|
|
|
|
|
|
when (it.key) { |
|
|
|
when (it.key) { |
|
|
|
Key.Escape -> { |
|
|
|
Key.Escape -> { |
|
|
|
isOpen = false |
|
|
|
exitApplication() |
|
|
|
true |
|
|
|
true |
|
|
|
} |
|
|
|
} |
|
|
|
else -> false |
|
|
|
else -> false |
|
|
@ -407,8 +407,6 @@ fun main() = application { |
|
|
|
) { |
|
|
|
) { |
|
|
|
TextField("Text", {}) |
|
|
|
TextField("Text", {}) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
``` |
|
|
|
``` |
|
|
|
(Currently it is a bit verbose, but in the future we will investigate how we can provide a simple API for handling window key events). |
|
|
|
(Currently it is a bit verbose, but in the future we will investigate how we can provide a simple API for handling window key events). |
|
|
@ -445,8 +443,8 @@ fun main() = application { |
|
|
|
|
|
|
|
|
|
|
|
if (isDialogOpen) { |
|
|
|
if (isDialogOpen) { |
|
|
|
Dialog( |
|
|
|
Dialog( |
|
|
|
initialAlignment = Alignment.Center, |
|
|
|
onCloseRequest = { isDialogOpen = false }, |
|
|
|
onCloseRequest = { isDialogOpen = false } |
|
|
|
initialAlignment = Alignment.Center |
|
|
|
) { |
|
|
|
) { |
|
|
|
// Dialog's content |
|
|
|
// Dialog's content |
|
|
|
} |
|
|
|
} |
|
|
@ -487,7 +485,7 @@ import java.awt.Cursor |
|
|
|
|
|
|
|
|
|
|
|
@OptIn(ExperimentalComposeUiApi::class) |
|
|
|
@OptIn(ExperimentalComposeUiApi::class) |
|
|
|
fun main() = application { |
|
|
|
fun main() = application { |
|
|
|
Window { |
|
|
|
Window(onCloseRequest = ::exitApplication) { |
|
|
|
LaunchedEffect(Unit) { |
|
|
|
LaunchedEffect(Unit) { |
|
|
|
window.cursor = Cursor(Cursor.CROSSHAIR_CURSOR) |
|
|
|
window.cursor = Cursor(Cursor.CROSSHAIR_CURSOR) |
|
|
|
} |
|
|
|
} |
|
|
|