Skip to content

Commit a3635bc

Browse files
committed
Welcome to Beta screen: Animations, Interaction
1 parent 5ce873d commit a3635bc

File tree

1 file changed

+79
-16
lines changed

1 file changed

+79
-16
lines changed

app/src/processing/app/ui/WelcomeToBeta.kt

Lines changed: 79 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
package processing.app.ui
22

3+
import androidx.compose.animation.animateColorAsState
4+
import androidx.compose.animation.core.animateFloatAsState
35
import androidx.compose.foundation.Image
46
import androidx.compose.foundation.background
57
import androidx.compose.foundation.layout.*
68
import androidx.compose.material.Surface
79
import androidx.compose.material.Text
8-
import androidx.compose.runtime.Composable
10+
import androidx.compose.runtime.*
911
import androidx.compose.ui.Alignment
12+
import androidx.compose.ui.ExperimentalComposeUiApi
1013
import androidx.compose.ui.Modifier
1114
import androidx.compose.ui.awt.ComposePanel
1215
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
1320
import androidx.compose.ui.res.painterResource
1421
import androidx.compose.ui.text.font.FontWeight
1522
import androidx.compose.ui.unit.DpSize
@@ -19,8 +26,11 @@ import androidx.compose.ui.window.Window
1926
import androidx.compose.ui.window.WindowPosition
2027
import androidx.compose.ui.window.application
2128
import androidx.compose.ui.window.rememberWindowState
29+
import com.formdev.flatlaf.util.SystemInfo
30+
import java.awt.Cursor
2231
import java.awt.Dimension
23-
32+
import java.awt.event.KeyAdapter
33+
import java.awt.event.KeyEvent
2434
import javax.swing.JFrame
2535
import javax.swing.SwingUtilities
2636

@@ -35,32 +45,47 @@ class WelcomeToBeta {
3545
Please report any bugs on the forums."""
3646
val buttonText = "Thank you"
3747

38-
3948
@JvmStatic
4049
fun showWelcomeToBeta() {
50+
val mac = SystemInfo.isMacFullWindowContentSupported
4151
SwingUtilities.invokeLater {
4252
JFrame(windowTitle).apply {
53+
val close = { dispose() }
54+
rootPane.putClientProperty("apple.awt.transparentTitleBar", mac)
55+
rootPane.putClientProperty("apple.awt.fullWindowContent", mac)
4356
defaultCloseOperation = JFrame.DISPOSE_ON_CLOSE
4457
contentPane.add(ComposePanel().apply {
58+
size = windowSize
4559
setContent {
46-
welcomeToBeta()
60+
Box(modifier = Modifier.padding(top = if(mac) 22.dp else 0.dp)) {
61+
welcomeToBeta(close)
62+
}
4763
}
48-
size = windowSize
4964
})
65+
pack()
66+
background = java.awt.Color.white
5067
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
5174
isVisible = true
75+
requestFocus()
5276
}
5377
}
5478
}
5579

5680
@Composable
57-
fun welcomeToBeta() {
81+
fun welcomeToBeta(close: () -> Unit = {}) {
5882
// TODO: Add fonts and colors
5983

6084
Row(
6185
modifier = Modifier
6286
.padding(20.dp, 10.dp)
63-
.size(windowSize.width.dp, windowSize.height.dp),
87+
.size(windowSize.width.dp, windowSize.height.dp)
88+
,
6489
horizontalArrangement = Arrangement.spacedBy(20.dp)
6590
){
6691
Image(
@@ -86,20 +111,55 @@ Please report any bugs on the forums."""
86111
)
87112
Row {
88113
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+
}) {
97117
Text(buttonText, color = Color.White)
98118
}
99119
}
100120
}
101121
}
102122
}
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+
103163

104164
@JvmStatic
105165
fun main(args: Array<String>) {
@@ -108,9 +168,12 @@ Please report any bugs on the forums."""
108168
size = DpSize.Unspecified,
109169
position = WindowPosition(Alignment.Center)
110170
)
171+
111172
Window(onCloseRequest = ::exitApplication, state = windowState, title = windowTitle) {
112173
Surface(color = Color.White) {
113-
welcomeToBeta()
174+
welcomeToBeta{
175+
exitApplication()
176+
}
114177
}
115178

116179
}

0 commit comments

Comments
 (0)