From 3df4da94618ed66d9a2b48a601b0ce7bac9a2d4e Mon Sep 17 00:00:00 2001 From: Stef Tervelde Date: Sun, 9 Feb 2025 12:57:55 +0100 Subject: [PATCH] Welcome Screen: Bugfixes --- app/src/processing/app/Language.java | 1 + app/src/processing/app/ui/Welcome.kt | 22 ++++++++++- .../app/ui/components/LanuageSelector.kt | 11 +++--- .../app/ui/components/examples/Examples.kt | 4 +- app/src/processing/app/ui/theme/Window.kt | 38 +++++-------------- 5 files changed, 39 insertions(+), 37 deletions(-) diff --git a/app/src/processing/app/Language.java b/app/src/processing/app/Language.java index f0fdab875..bcc4385a5 100644 --- a/app/src/processing/app/Language.java +++ b/app/src/processing/app/Language.java @@ -184,6 +184,7 @@ public class Language { } static public void reload(){ + if(instance == null) return; synchronized (Language.class) { instance = new Language(); } diff --git a/app/src/processing/app/ui/Welcome.kt b/app/src/processing/app/ui/Welcome.kt index 754c9e4fc..98c8c2ed4 100644 --- a/app/src/processing/app/ui/Welcome.kt +++ b/app/src/processing/app/ui/Welcome.kt @@ -14,11 +14,14 @@ import androidx.compose.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip +import androidx.compose.ui.draw.scale import androidx.compose.ui.geometry.Offset import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.ColorFilter +import androidx.compose.ui.platform.LocalLayoutDirection import androidx.compose.ui.res.painterResource +import androidx.compose.ui.unit.LayoutDirection import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.min import com.formdev.flatlaf.util.SystemInfo @@ -90,6 +93,10 @@ class Welcome @Throws(IOException::class) constructor(base: Base) { .height(200.dp) .offset (32.dp) .align(Alignment.BottomEnd) + .scale(when(LocalLayoutDirection.current) { + LayoutDirection.Rtl -> -1f + else -> 1f + }, 1f) ) } } @@ -139,7 +146,12 @@ class Welcome @Throws(IOException::class) constructor(base: Base) { painter = painterResource("welcome/intro/bubble.svg"), contentDescription = locale["welcome.intro.long"], modifier = Modifier - .align{ _, space, _ -> space / 4 } + .align(Alignment.Start) + .scale(when(LocalLayoutDirection.current) { + LayoutDirection.Rtl -> -1f + else -> 1f + }, 1f) + .padding(start = 64.dp) ) Row( horizontalArrangement = Arrangement.SpaceBetween, @@ -151,6 +163,10 @@ class Welcome @Throws(IOException::class) constructor(base: Base) { contentDescription = locale["welcome.intro.long"], modifier = Modifier .offset(x = -32.dp) + .scale(when(LocalLayoutDirection.current) { + LayoutDirection.Rtl -> -1f + else -> 1f + }, 1f) ) Image( painter = painterResource("welcome/intro/short.svg"), @@ -158,6 +174,10 @@ class Welcome @Throws(IOException::class) constructor(base: Base) { modifier = Modifier .align(Alignment.Bottom) .offset(x = 16.dp, y = -16.dp) + .scale(when(LocalLayoutDirection.current) { + LayoutDirection.Rtl -> -1f + else -> 1f + }, 1f) ) } } diff --git a/app/src/processing/app/ui/components/LanuageSelector.kt b/app/src/processing/app/ui/components/LanuageSelector.kt index 801f0f008..5c42443fe 100644 --- a/app/src/processing/app/ui/components/LanuageSelector.kt +++ b/app/src/processing/app/ui/components/LanuageSelector.kt @@ -21,6 +21,7 @@ import processing.app.ui.theme.LocalLocale import processing.app.ui.theme.PDEChip import processing.app.watchFile import java.io.File +import java.nio.file.FileSystem import java.nio.file.FileSystems import java.nio.file.Files import java.nio.file.Paths @@ -34,6 +35,8 @@ data class Language( val properties: Properties ) +var jarFs: FileSystem? = null + @Composable fun LanguageChip(){ var expanded by remember { mutableStateOf(false) } @@ -44,9 +47,6 @@ fun LanguageChip(){ val main = ClassLoader.getSystemResource("PDE.properties")?: return - - - val languages = remember { val list = when(main.protocol){ "file" -> { @@ -55,8 +55,8 @@ fun LanguageChip(){ } "jar" -> { val uri = main.toURI() - val fs = FileSystems.newFileSystem(uri, emptyMap()) - Files.list(fs.getPath("/")) + jarFs = jarFs ?: FileSystems.newFileSystem(uri, emptyMap()) ?: return@remember null + Files.list(jarFs!!.getPath("/")) } else -> null } ?: return@remember null @@ -81,6 +81,7 @@ fun LanguageChip(){ ) } } + .sortedBy { it.name.lowercase() } } ?: return val current = languageFile.readText(Charsets.UTF_8).substring(0, 2) diff --git a/app/src/processing/app/ui/components/examples/Examples.kt b/app/src/processing/app/ui/components/examples/Examples.kt index 45455a2ca..4c0a9045c 100644 --- a/app/src/processing/app/ui/components/examples/Examples.kt +++ b/app/src/processing/app/ui/components/examples/Examples.kt @@ -135,7 +135,7 @@ fun examples(){ randoms = randoms + List(4 - randoms.size) { Example( folder = Paths.get(""), library = Paths.get(""), - title = "Test", + title = "Example", image = ClassLoader.getSystemResource("default.png")?.toURI()?.let { Paths.get(it) } ?: Paths.get(""), ) } } @@ -154,7 +154,7 @@ fun examples(){ } } } -@OptIn(ExperimentalComposeUiApi::class, ExperimentalResourceApi::class) +@OptIn(ExperimentalResourceApi::class) @Composable fun Example(example: Example){ val base = LocalBase.current diff --git a/app/src/processing/app/ui/theme/Window.kt b/app/src/processing/app/ui/theme/Window.kt index 8ad5532d1..23b71ebad 100644 --- a/app/src/processing/app/ui/theme/Window.kt +++ b/app/src/processing/app/ui/theme/Window.kt @@ -6,6 +6,7 @@ import androidx.compose.material.MaterialTheme.colors import androidx.compose.material.Surface import androidx.compose.material.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.awt.ComposePanel @@ -41,6 +42,10 @@ class PDEWindow(titleKey: String = "", fullWindowContent: Boolean = false, conte ProcessingTheme { val locale = LocalLocale.current this@PDEWindow.title = locale[titleKey] + LaunchedEffect(locale){ + this@PDEWindow.pack() + this@PDEWindow.setLocationRelativeTo(null) + } Box(modifier = Modifier .padding(top = if (mac && !fullWindowContent) 22.dp else 0.dp) @@ -81,6 +86,10 @@ fun pdeapplication(titleKey: String = "", fullWindowContent: Boolean = false,con putClientProperty("apple.awt.fullWindowContent", mac) putClientProperty("apple.awt.transparentTitleBar", mac) } + LaunchedEffect(locale){ + window.pack() + window.setLocationRelativeTo(null) + } Surface(color = colors.background) { Box(modifier = Modifier .padding(top = if (mac && !fullWindowContent) 22.dp else 0.dp) @@ -92,32 +101,3 @@ fun pdeapplication(titleKey: String = "", fullWindowContent: Boolean = false,con } } } - - -fun main(){ - application { - val windowState = rememberWindowState( - size = DpSize.Unspecified, - position = WindowPosition(Alignment.Center) - ) - Window(onCloseRequest = ::exitApplication, title = "Welcome to Processing", state = windowState) { - Row{ - Text("Hello, Processing!") - Column( - modifier = Modifier -// .wrapContentSize() - ) { - Box( - modifier = Modifier - .background(Color.Red) - .sizeIn(minHeight = 100.dp) - ) { - - } - Text("Hello, Processing!") - } - } - - } - } -}