11package processing.app.ui.theme
22
3- import androidx.compose.foundation.background
43import androidx.compose.foundation.layout.*
54import androidx.compose.material.MaterialTheme.colors
65import androidx.compose.material.Surface
7- import androidx.compose.material.Text
86import androidx.compose.runtime.Composable
7+ import androidx.compose.runtime.CompositionLocalProvider
98import androidx.compose.runtime.LaunchedEffect
9+ import androidx.compose.runtime.compositionLocalOf
1010import androidx.compose.ui.Alignment
1111import androidx.compose.ui.Modifier
1212import 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
1613import androidx.compose.ui.unit.DpSize
1714import androidx.compose.ui.unit.dp
1815import androidx.compose.ui.window.Window
1916import androidx.compose.ui.window.WindowPosition
2017import androidx.compose.ui.window.application
2118import androidx.compose.ui.window.rememberWindowState
2219import com.formdev.flatlaf.util.SystemInfo
23- import processing.app.ui.WelcomeToBeta.Companion.welcomeToBeta
2420
2521import java.awt.event.KeyAdapter
2622import java.awt.event.KeyEvent
2723import javax.swing.JFrame
2824
25+ val LocalWindow = compositionLocalOf<JFrame > { error(" No Window Set" ) }
2926
3027class 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