1
1
package processing.app.ui
2
2
3
+ import androidx.compose.animation.animateColorAsState
4
+ import androidx.compose.animation.core.animateFloatAsState
3
5
import androidx.compose.foundation.Image
4
6
import androidx.compose.foundation.background
5
7
import androidx.compose.foundation.layout.*
6
8
import androidx.compose.material.Surface
7
9
import androidx.compose.material.Text
8
- import androidx.compose.runtime.Composable
10
+ import androidx.compose.runtime.*
9
11
import androidx.compose.ui.Alignment
12
+ import androidx.compose.ui.ExperimentalComposeUiApi
10
13
import androidx.compose.ui.Modifier
11
14
import androidx.compose.ui.awt.ComposePanel
12
15
import androidx.compose.ui.graphics.Color
16
+ import androidx.compose.ui.input.pointer.PointerEventType
17
+ import androidx.compose.ui.input.pointer.PointerIcon
18
+ import androidx.compose.ui.input.pointer.onPointerEvent
19
+ import androidx.compose.ui.input.pointer.pointerHoverIcon
13
20
import androidx.compose.ui.res.painterResource
14
21
import androidx.compose.ui.text.font.FontWeight
15
22
import androidx.compose.ui.unit.DpSize
@@ -19,8 +26,11 @@ import androidx.compose.ui.window.Window
19
26
import androidx.compose.ui.window.WindowPosition
20
27
import androidx.compose.ui.window.application
21
28
import androidx.compose.ui.window.rememberWindowState
29
+ import com.formdev.flatlaf.util.SystemInfo
30
+ import java.awt.Cursor
22
31
import java.awt.Dimension
23
-
32
+ import java.awt.event.KeyAdapter
33
+ import java.awt.event.KeyEvent
24
34
import javax.swing.JFrame
25
35
import javax.swing.SwingUtilities
26
36
@@ -35,32 +45,47 @@ class WelcomeToBeta {
35
45
Please report any bugs on the forums."""
36
46
val buttonText = " Thank you"
37
47
38
-
39
48
@JvmStatic
40
49
fun showWelcomeToBeta () {
50
+ val mac = SystemInfo .isMacFullWindowContentSupported
41
51
SwingUtilities .invokeLater {
42
52
JFrame (windowTitle).apply {
53
+ val close = { dispose() }
54
+ rootPane.putClientProperty(" apple.awt.transparentTitleBar" , mac)
55
+ rootPane.putClientProperty(" apple.awt.fullWindowContent" , mac)
43
56
defaultCloseOperation = JFrame .DISPOSE_ON_CLOSE
44
57
contentPane.add(ComposePanel ().apply {
58
+ size = windowSize
45
59
setContent {
46
- welcomeToBeta()
60
+ Box (modifier = Modifier .padding(top = if (mac) 22 .dp else 0 .dp)) {
61
+ welcomeToBeta(close)
62
+ }
47
63
}
48
- size = windowSize
49
64
})
65
+ pack()
66
+ background = java.awt.Color .white
50
67
setLocationRelativeTo(null )
68
+ addKeyListener(object : KeyAdapter () {
69
+ override fun keyPressed (e : KeyEvent ) {
70
+ if (e.keyCode == KeyEvent .VK_ESCAPE ) close()
71
+ }
72
+ })
73
+ isResizable = false
51
74
isVisible = true
75
+ requestFocus()
52
76
}
53
77
}
54
78
}
55
79
56
80
@Composable
57
- fun welcomeToBeta () {
81
+ fun welcomeToBeta (close : () -> Unit = {} ) {
58
82
// TODO: Add fonts and colors
59
83
60
84
Row (
61
85
modifier = Modifier
62
86
.padding(20 .dp, 10 .dp)
63
- .size(windowSize.width.dp, windowSize.height.dp),
87
+ .size(windowSize.width.dp, windowSize.height.dp)
88
+ ,
64
89
horizontalArrangement = Arrangement .spacedBy(20 .dp)
65
90
){
66
91
Image (
@@ -86,20 +111,55 @@ Please report any bugs on the forums."""
86
111
)
87
112
Row {
88
113
Spacer (modifier = Modifier .weight(1f ))
89
- // TODO Add button shadow and make interactive
90
- Box (
91
- modifier = Modifier
92
- .background(Color .Blue )
93
- .padding(10 .dp)
94
- .sizeIn(minWidth = 100 .dp),
95
- contentAlignment = Alignment .Center
96
- ) {
114
+ PDEButton (onClick = {
115
+ close()
116
+ }) {
97
117
Text (buttonText, color = Color .White )
98
118
}
99
119
}
100
120
}
101
121
}
102
122
}
123
+ @OptIn(ExperimentalComposeUiApi ::class )
124
+ @Composable
125
+ fun PDEButton (onClick : () -> Unit , content : @Composable BoxScope .() -> Unit ) {
126
+ var hover by remember { mutableStateOf(false ) }
127
+ var clicked by remember { mutableStateOf(false ) }
128
+ val offset by animateFloatAsState(if (hover) - 5f else 5f )
129
+ val color by animateColorAsState(if (clicked) Color .Black else Color .Blue )
130
+
131
+ Box (modifier = Modifier .padding(end = 5 .dp, top = 5 .dp)) {
132
+ Box (
133
+ modifier = Modifier
134
+ .offset((- offset).dp, (offset).dp)
135
+ .background(Color .Gray )
136
+ .matchParentSize()
137
+ )
138
+ Box (
139
+ modifier = Modifier
140
+ .onPointerEvent(PointerEventType .Press ) {
141
+ clicked = true
142
+ }
143
+ .onPointerEvent(PointerEventType .Release ) {
144
+ clicked = false
145
+ onClick()
146
+ }
147
+ .onPointerEvent(PointerEventType .Enter ) {
148
+ hover = true
149
+ }
150
+ .onPointerEvent(PointerEventType .Exit ) {
151
+ hover = false
152
+ }
153
+ .pointerHoverIcon(PointerIcon (Cursor (Cursor .HAND_CURSOR )))
154
+ .background(color)
155
+ .padding(10 .dp)
156
+ .sizeIn(minWidth = 100 .dp),
157
+ contentAlignment = Alignment .Center ,
158
+ content = content
159
+ )
160
+ }
161
+ }
162
+
103
163
104
164
@JvmStatic
105
165
fun main (args : Array <String >) {
@@ -108,9 +168,12 @@ Please report any bugs on the forums."""
108
168
size = DpSize .Unspecified ,
109
169
position = WindowPosition (Alignment .Center )
110
170
)
171
+
111
172
Window (onCloseRequest = ::exitApplication, state = windowState, title = windowTitle) {
112
173
Surface (color = Color .White ) {
113
- welcomeToBeta()
174
+ welcomeToBeta{
175
+ exitApplication()
176
+ }
114
177
}
115
178
116
179
}
0 commit comments