Skip to content

Commit ed49b65

Browse files
committed
Welcome to Beta screen: Colors, Typhography, Locale
1 parent a3635bc commit ed49b65

File tree

7 files changed

+196
-27
lines changed

7 files changed

+196
-27
lines changed

app/build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ sourceSets{
3838
kotlin{
3939
srcDirs("src")
4040
}
41+
resources{
42+
srcDirs("resources", listOf("languages", "fonts", "theme").map { "../build/shared/lib/$it" })
43+
}
4144
}
4245
}
4346

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

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import androidx.compose.animation.core.animateFloatAsState
55
import androidx.compose.foundation.Image
66
import androidx.compose.foundation.background
77
import androidx.compose.foundation.layout.*
8+
import androidx.compose.material.MaterialTheme
9+
import androidx.compose.material.MaterialTheme.colors
810
import androidx.compose.material.Surface
911
import androidx.compose.material.Text
1012
import androidx.compose.runtime.*
@@ -27,23 +29,24 @@ import androidx.compose.ui.window.WindowPosition
2729
import androidx.compose.ui.window.application
2830
import androidx.compose.ui.window.rememberWindowState
2931
import com.formdev.flatlaf.util.SystemInfo
32+
import processing.app.ui.theme.LocalLocale
33+
import processing.app.ui.theme.LocalTheme
34+
import processing.app.ui.theme.Locale
35+
import processing.app.ui.theme.ProcessingTheme
3036
import java.awt.Cursor
3137
import java.awt.Dimension
3238
import java.awt.event.KeyAdapter
3339
import java.awt.event.KeyEvent
40+
import java.io.InputStream
41+
import java.util.Properties
3442
import javax.swing.JFrame
3543
import javax.swing.SwingUtilities
3644

3745

3846
class WelcomeToBeta {
3947
companion object{
4048
val windowSize = Dimension(400, 200)
41-
val windowTitle = "Welcome to Beta"
42-
val title = "Welcome to the Processing Beta"
43-
val message = """Thank you for trying out the new version of Processing. We’re very grateful!
44-
45-
Please report any bugs on the forums."""
46-
val buttonText = "Thank you"
49+
val windowTitle = Locale()["beta.window.title"]
4750

4851
@JvmStatic
4952
fun showWelcomeToBeta() {
@@ -57,8 +60,10 @@ Please report any bugs on the forums."""
5760
contentPane.add(ComposePanel().apply {
5861
size = windowSize
5962
setContent {
60-
Box(modifier = Modifier.padding(top = if(mac) 22.dp else 0.dp)) {
61-
welcomeToBeta(close)
63+
ProcessingTheme {
64+
Box(modifier = Modifier.padding(top = if (mac) 22.dp else 0.dp)) {
65+
welcomeToBeta(close)
66+
}
6267
}
6368
}
6469
})
@@ -79,14 +84,12 @@ Please report any bugs on the forums."""
7984

8085
@Composable
8186
fun welcomeToBeta(close: () -> Unit = {}) {
82-
// TODO: Add fonts and colors
83-
8487
Row(
8588
modifier = Modifier
8689
.padding(20.dp, 10.dp)
87-
.size(windowSize.width.dp, windowSize.height.dp)
88-
,
89-
horizontalArrangement = Arrangement.spacedBy(20.dp)
90+
.size(windowSize.width.dp, windowSize.height.dp),
91+
horizontalArrangement = Arrangement
92+
.spacedBy(20.dp)
9093
){
9194
Image(
9295
painter = painterResource("logo.svg"),
@@ -97,24 +100,30 @@ Please report any bugs on the forums."""
97100
)
98101
Column(
99102
modifier = Modifier
100-
.fillMaxHeight(),
101-
verticalArrangement = Arrangement.spacedBy(20.dp, alignment = Alignment.CenterVertically)
103+
.fillMaxHeight(),
104+
verticalArrangement = Arrangement
105+
.spacedBy(
106+
MaterialTheme.typography.subtitle1.lineHeight.value.dp,
107+
alignment = Alignment.CenterVertically
108+
)
102109
) {
110+
val locale = LocalLocale.current
103111
Text(
104-
title,
105-
fontSize = 17.sp,
106-
fontWeight = FontWeight.SemiBold
112+
text = locale["beta.title"],
113+
style = MaterialTheme.typography.subtitle1,
107114
)
108115
Text(
109-
message,
110-
fontSize = 13.sp
116+
text = locale["beta.message"]
111117
)
112118
Row {
113119
Spacer(modifier = Modifier.weight(1f))
114120
PDEButton(onClick = {
115121
close()
116122
}) {
117-
Text(buttonText, color = Color.White)
123+
Text(
124+
text = locale["beta.button"],
125+
color = Color.White
126+
)
118127
}
119128
}
120129
}
@@ -123,16 +132,18 @@ Please report any bugs on the forums."""
123132
@OptIn(ExperimentalComposeUiApi::class)
124133
@Composable
125134
fun PDEButton(onClick: () -> Unit, content: @Composable BoxScope.() -> Unit) {
135+
val theme = LocalTheme.current
136+
126137
var hover by remember { mutableStateOf(false) }
127138
var clicked by remember { mutableStateOf(false) }
128139
val offset by animateFloatAsState(if (hover) -5f else 5f)
129-
val color by animateColorAsState(if(clicked) Color.Black else Color.Blue)
140+
val color by animateColorAsState(if(clicked) colors.primaryVariant else colors.primary)
130141

131142
Box(modifier = Modifier.padding(end = 5.dp, top = 5.dp)) {
132143
Box(
133144
modifier = Modifier
134145
.offset((-offset).dp, (offset).dp)
135-
.background(Color.Gray)
146+
.background(theme.getColor("toolbar.button.pressed.field"))
136147
.matchParentSize()
137148
)
138149
Box(
@@ -170,12 +181,13 @@ Please report any bugs on the forums."""
170181
)
171182

172183
Window(onCloseRequest = ::exitApplication, state = windowState, title = windowTitle) {
173-
Surface(color = Color.White) {
174-
welcomeToBeta{
175-
exitApplication()
184+
ProcessingTheme {
185+
Surface(color = colors.background) {
186+
welcomeToBeta {
187+
exitApplication()
188+
}
176189
}
177190
}
178-
179191
}
180192
}
181193
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package processing.app.ui.theme
2+
3+
import androidx.compose.runtime.Composable
4+
import androidx.compose.runtime.CompositionLocalProvider
5+
import androidx.compose.runtime.compositionLocalOf
6+
import java.io.InputStream
7+
import java.util.*
8+
9+
class Locale : Properties() {
10+
init {
11+
val locale = java.util.Locale.getDefault()
12+
load(ClassLoader.getSystemResourceAsStream("PDE.properties"))
13+
load(ClassLoader.getSystemResourceAsStream("PDE_${locale.language}.properties") ?: InputStream.nullInputStream())
14+
load(ClassLoader.getSystemResourceAsStream("PDE_${locale.toLanguageTag()}.properties") ?: InputStream.nullInputStream())
15+
}
16+
17+
@Deprecated("Use get instead", ReplaceWith("get(key)"))
18+
override fun getProperty(key: String?): String {
19+
return super.getProperty(key)
20+
}
21+
operator fun get(key: String): String = getProperty(key)
22+
}
23+
val LocalLocale = compositionLocalOf { Locale() }
24+
@Composable
25+
fun LocaleProvider(content: @Composable () -> Unit) {
26+
val locale = Locale()
27+
// TODO: Listen for languages changes
28+
CompositionLocalProvider(LocalLocale provides locale) {
29+
content()
30+
}
31+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package processing.app.ui.theme
2+
3+
import androidx.compose.foundation.isSystemInDarkTheme
4+
import androidx.compose.material.Colors
5+
import androidx.compose.material.MaterialTheme
6+
import androidx.compose.runtime.Composable
7+
import androidx.compose.runtime.CompositionLocalProvider
8+
import androidx.compose.runtime.compositionLocalOf
9+
import androidx.compose.ui.graphics.Color
10+
import java.io.InputStream
11+
import java.util.Properties
12+
13+
14+
class Theme(themeFile: String? = "") : Properties() {
15+
init {
16+
load(ClassLoader.getSystemResourceAsStream("theme.txt"))
17+
load(ClassLoader.getSystemResourceAsStream(themeFile) ?: InputStream.nullInputStream())
18+
}
19+
fun getColor(key: String): Color {
20+
return Color(getProperty(key).toColorInt())
21+
}
22+
}
23+
24+
val LocalTheme = compositionLocalOf<Theme> { error("No theme provided") }
25+
26+
@Composable
27+
fun ProcessingTheme(
28+
darkTheme: Boolean = isSystemInDarkTheme(),
29+
content: @Composable() () -> Unit
30+
) {
31+
32+
val theme = Theme()
33+
val colors = Colors(
34+
primary = theme.getColor("editor.gradient.top"),
35+
primaryVariant = theme.getColor("toolbar.button.pressed.field"),
36+
secondary = theme.getColor("editor.gradient.bottom"),
37+
secondaryVariant = theme.getColor("editor.scrollbar.thumb.pressed.color"),
38+
background = theme.getColor("editor.bgcolor"),
39+
surface = theme.getColor("editor.bgcolor"),
40+
error = theme.getColor("status.error.bgcolor"),
41+
onPrimary = theme.getColor("toolbar.button.pressed.field"),
42+
onSecondary = theme.getColor("toolbar.button.pressed.field"),
43+
onBackground = theme.getColor("editor.fgcolor"),
44+
onSurface = theme.getColor("editor.fgcolor"),
45+
onError = theme.getColor("status.error.fgcolor"),
46+
isLight = theme.getProperty("laf.mode").equals("light")
47+
)
48+
49+
CompositionLocalProvider(LocalTheme provides theme) {
50+
LocaleProvider {
51+
MaterialTheme(
52+
colors = colors,
53+
typography = Typography,
54+
content = content
55+
)
56+
}
57+
}
58+
}
59+
60+
fun String.toColorInt(): Int {
61+
if (this[0] == '#') {
62+
var color = substring(1).toLong(16)
63+
if (length == 7) {
64+
color = color or 0x00000000ff000000L
65+
} else if (length != 9) {
66+
throw IllegalArgumentException("Unknown color")
67+
}
68+
return color.toInt()
69+
}
70+
throw IllegalArgumentException("Unknown color")
71+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package processing.app.ui.theme
2+
3+
import androidx.compose.material.MaterialTheme.typography
4+
import androidx.compose.material.Typography
5+
import androidx.compose.ui.text.TextStyle
6+
import androidx.compose.ui.text.font.FontFamily
7+
import androidx.compose.ui.text.font.FontStyle
8+
import androidx.compose.ui.text.font.FontWeight
9+
import androidx.compose.ui.text.platform.Font
10+
import androidx.compose.ui.unit.sp
11+
12+
val processingFont = FontFamily(
13+
Font(
14+
resource = "ProcessingSans-Regular.ttf",
15+
weight = FontWeight.Normal,
16+
style = FontStyle.Normal
17+
),
18+
Font(
19+
resource = "ProcessingSans-Bold.ttf",
20+
weight = FontWeight.Bold,
21+
style = FontStyle.Normal
22+
)
23+
)
24+
25+
val Typography = Typography(
26+
body1 = TextStyle(
27+
fontFamily = processingFont,
28+
fontWeight = FontWeight.Normal,
29+
fontSize = 13.sp,
30+
lineHeight = 16.sp
31+
),
32+
subtitle1 = TextStyle(
33+
fontFamily = processingFont,
34+
fontWeight = FontWeight.Bold,
35+
fontSize = 16.sp,
36+
lineHeight = 20.sp
37+
)
38+
)

build/shared/lib/languages/PDE.properties

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,13 @@ update_check.updates_available.core = A new version of Processing is available,\
614614
update_check.updates_available.contributions = There are updates available for some of the installed contributions,\nwould you like to open the the Contribution Manager now?
615615

616616

617+
# ---------------------------------------
618+
# Beta
619+
beta.window.title = Welcome to Beta
620+
beta.title = Welcome to the Processing Beta
621+
beta.message = Thank you for trying out the new version of Processing. We?re very grateful!\n\nPlease report any bugs on the forums.
622+
beta.button = Got it!
623+
617624
# ---------------------------------------
618625
# Color Chooser
619626

build/shared/lib/languages/PDE_nl.properties

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,13 @@ update_check = Update
315315
update_check.updates_available.core = Een nieuwe versie van Processing is beschikbaar,\nwilt u de Processing download pagina bezoeken?
316316
update_check.updates_available.contributions = Er zijn updates beschikbaar voor sommige van de door u geïnstalleerde bijdragen,\nwilt u nu de Bijdragen Manager openen?
317317

318+
# ---------------------------------------
319+
# Beta
320+
beta.window.title = Welkom bij Beta
321+
beta.title = Welkom bij de Processing Beta
322+
beta.message = Bedankt dat je de nieuwe versie van Processing uitprobeert. We zijn je zeer dankbaar!\n\nMeld eventuele bugs alsjeblieft op de forums.
323+
beta.button = Okee!
324+
318325

319326
# ---------------------------------------
320327
# Color Chooser

0 commit comments

Comments
 (0)