Skip to content

Commit 8d8bd01

Browse files
committed
Welcome Screen: Close Functionality
1 parent 3df4da9 commit 8d8bd01

File tree

3 files changed

+32
-25
lines changed

3 files changed

+32
-25
lines changed

app/src/processing/app/ui/Welcome.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,10 @@ class Welcome @Throws(IOException::class) constructor(base: Base) {
250250
text = locale["welcome.action.startup"],
251251
)
252252
}
253-
PDEButton(onClick = { println("Open") }) {
253+
val window = LocalWindow.current
254+
PDEButton(onClick = {
255+
window.dispose()
256+
}) {
254257
Text(
255258
text = locale["welcome.action.go"],
256259
modifier = Modifier

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class WelcomeToBeta {
5454
}
5555

5656
@Composable
57-
fun welcomeToBeta(close: () -> Unit = {}) {
57+
fun welcomeToBeta() {
5858
Row(
5959
modifier = Modifier
6060
.padding(20.dp, 10.dp)
@@ -87,9 +87,10 @@ class WelcomeToBeta {
8787
text = locale["beta.message"]
8888
)
8989
Row {
90+
val window = LocalWindow.current
9091
Spacer(modifier = Modifier.weight(1f))
9192
PDEButton(onClick = {
92-
close()
93+
window.dispose()
9394
}) {
9495
Text(
9596
text = locale["beta.button"],

app/src/processing/app/ui/theme/Window.kt

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,28 @@
11
package processing.app.ui.theme
22

3-
import androidx.compose.foundation.background
43
import androidx.compose.foundation.layout.*
54
import androidx.compose.material.MaterialTheme.colors
65
import androidx.compose.material.Surface
7-
import androidx.compose.material.Text
86
import androidx.compose.runtime.Composable
7+
import androidx.compose.runtime.CompositionLocalProvider
98
import androidx.compose.runtime.LaunchedEffect
9+
import androidx.compose.runtime.compositionLocalOf
1010
import androidx.compose.ui.Alignment
1111
import androidx.compose.ui.Modifier
1212
import androidx.compose.ui.awt.ComposePanel
13-
import androidx.compose.ui.geometry.Offset
14-
import androidx.compose.ui.graphics.Brush
15-
import androidx.compose.ui.graphics.Color
1613
import androidx.compose.ui.unit.DpSize
1714
import androidx.compose.ui.unit.dp
1815
import androidx.compose.ui.window.Window
1916
import androidx.compose.ui.window.WindowPosition
2017
import androidx.compose.ui.window.application
2118
import androidx.compose.ui.window.rememberWindowState
2219
import com.formdev.flatlaf.util.SystemInfo
23-
import processing.app.ui.WelcomeToBeta.Companion.welcomeToBeta
2420

2521
import java.awt.event.KeyAdapter
2622
import java.awt.event.KeyEvent
2723
import javax.swing.JFrame
2824

25+
val LocalWindow = compositionLocalOf<JFrame> { error("No Window Set") }
2926

3027
class PDEWindow(titleKey: String = "", fullWindowContent: Boolean = false, content: @Composable () -> Unit): JFrame(){
3128
init{
@@ -39,19 +36,22 @@ class PDEWindow(titleKey: String = "", fullWindowContent: Boolean = false, conte
3936
defaultCloseOperation = DISPOSE_ON_CLOSE
4037
ComposePanel().apply {
4138
setContent {
42-
ProcessingTheme {
43-
val locale = LocalLocale.current
44-
this@PDEWindow.title = locale[titleKey]
45-
LaunchedEffect(locale){
46-
this@PDEWindow.pack()
47-
this@PDEWindow.setLocationRelativeTo(null)
48-
}
39+
CompositionLocalProvider(LocalWindow provides this@PDEWindow) {
40+
ProcessingTheme {
41+
val locale = LocalLocale.current
42+
this@PDEWindow.title = locale[titleKey]
43+
LaunchedEffect(locale) {
44+
this@PDEWindow.pack()
45+
this@PDEWindow.setLocationRelativeTo(null)
46+
}
4947

50-
Box(modifier = Modifier
51-
.padding(top = if (mac && !fullWindowContent) 22.dp else 0.dp)
52-
) {
53-
content()
48+
Box(
49+
modifier = Modifier
50+
.padding(top = if (mac && !fullWindowContent) 22.dp else 0.dp)
51+
) {
52+
content()
5453

54+
}
5555
}
5656
}
5757
}
@@ -90,11 +90,14 @@ fun pdeapplication(titleKey: String = "", fullWindowContent: Boolean = false,con
9090
window.pack()
9191
window.setLocationRelativeTo(null)
9292
}
93-
Surface(color = colors.background) {
94-
Box(modifier = Modifier
95-
.padding(top = if (mac && !fullWindowContent) 22.dp else 0.dp)
96-
) {
97-
content()
93+
CompositionLocalProvider(LocalWindow provides window) {
94+
Surface(color = colors.background) {
95+
Box(
96+
modifier = Modifier
97+
.padding(top = if (mac && !fullWindowContent) 22.dp else 0.dp)
98+
) {
99+
content()
100+
}
98101
}
99102
}
100103
}

0 commit comments

Comments
 (0)