-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMain.kt
81 lines (72 loc) · 2.24 KB
/
Main.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Button
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.*
import kotlinx.coroutines.delay
import java.awt.Shape
@Composable
fun App() {
var text by remember { mutableStateOf("Hello, World!") }
var showNotification by remember { mutableStateOf(false) }
MaterialTheme {
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Button(onClick = {
text = "Hello, Desktop!"
showNotification = true
}) {
Text(text)
}
}
}
if (showNotification) {
Notification(text = text) {
showNotification = false
}
}
}
@Composable
fun Notification(text: String, onClose: () -> Unit) {
LaunchedEffect(Unit) {
delay(2000)
onClose()
}
Window(
onCloseRequest = onClose,
title = "Notification",
resizable = false,
undecorated = true,
transparent = true,
state = WindowState(width = 400.dp, height = 100.dp, placement = WindowPlacement.Floating, position = WindowPosition(Alignment.TopEnd))
) {
MaterialTheme {
Box(
modifier = Modifier.fillMaxSize().padding(8.dp).clip(shape = RoundedCornerShape(10.dp)).background(MaterialTheme.colors.background),
){
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally,
) {
Text(text = text)
}
}
}
}
}
fun main() = application {
Window(onCloseRequest = ::exitApplication) {
App()
}
}