1
1
package processing.app.ui.theme
2
2
3
- import androidx.compose.foundation.background
4
3
import androidx.compose.foundation.layout.*
5
4
import androidx.compose.material.MaterialTheme.colors
6
5
import androidx.compose.material.Surface
7
- import androidx.compose.material.Text
8
6
import androidx.compose.runtime.Composable
7
+ import androidx.compose.runtime.CompositionLocalProvider
9
8
import androidx.compose.runtime.LaunchedEffect
9
+ import androidx.compose.runtime.compositionLocalOf
10
10
import androidx.compose.ui.Alignment
11
11
import androidx.compose.ui.Modifier
12
12
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
16
13
import androidx.compose.ui.unit.DpSize
17
14
import androidx.compose.ui.unit.dp
18
15
import androidx.compose.ui.window.Window
19
16
import androidx.compose.ui.window.WindowPosition
20
17
import androidx.compose.ui.window.application
21
18
import androidx.compose.ui.window.rememberWindowState
22
19
import com.formdev.flatlaf.util.SystemInfo
23
- import processing.app.ui.WelcomeToBeta.Companion.welcomeToBeta
24
20
25
21
import java.awt.event.KeyAdapter
26
22
import java.awt.event.KeyEvent
27
23
import javax.swing.JFrame
28
24
25
+ val LocalWindow = compositionLocalOf<JFrame > { error(" No Window Set" ) }
29
26
30
27
class PDEWindow (titleKey : String = " " , fullWindowContent : Boolean = false , content : @Composable () -> Unit ): JFrame(){
31
28
init {
@@ -39,19 +36,22 @@ class PDEWindow(titleKey: String = "", fullWindowContent: Boolean = false, conte
39
36
defaultCloseOperation = DISPOSE_ON_CLOSE
40
37
ComposePanel ().apply {
41
38
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
+ }
49
47
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()
54
53
54
+ }
55
55
}
56
56
}
57
57
}
@@ -90,11 +90,14 @@ fun pdeapplication(titleKey: String = "", fullWindowContent: Boolean = false,con
90
90
window.pack()
91
91
window.setLocationRelativeTo(null )
92
92
}
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
+ }
98
101
}
99
102
}
100
103
}
0 commit comments