Skip to content

Commit 00ab8c2

Browse files
committed
Add p5.js example download and update dependencies
Introduces a Gradle task to download and extract p5.js examples for use in the project. Updates dependencies to use material3 components and changes theme usage in p5jsEditor.kt. Also sets Electron window 'alwaysOnTop' to false and fixes a reference to SketchException.
1 parent 201e197 commit 00ab8c2

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed

p5js/build.gradle.kts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import org.jetbrains.compose.internal.de.undercouch.gradle.tasks.download.Download
2+
13
plugins {
24
kotlin("jvm") version libs.versions.kotlin
35
kotlin("plugin.serialization") version "1.9.0"
@@ -15,6 +17,7 @@ repositories {
1517

1618
dependencies {
1719
compileOnly(project(":app"))
20+
compileOnly(project(":app:utils"))
1821
implementation(project(":core"))
1922

2023
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")
@@ -27,10 +30,33 @@ dependencies {
2730
implementation(compose.ui)
2831
implementation(compose.components.resources)
2932
implementation(compose.components.uiToolingPreview)
33+
implementation(libs.material3)
34+
}
35+
36+
tasks.register<Download>("includeP5jsExamples"){
37+
val examples = layout.buildDirectory.file("tmp/p5-examples.zip")
38+
src("https://github.com/processing/p5.js-website/archive/refs/heads/2.0.zip")
39+
dest(examples)
40+
overwrite(false)
41+
doLast{
42+
copy{
43+
from(zipTree(examples)){ // remove top level directory
44+
include("*/src/content/examples/en/**/*")
45+
eachFile { relativePath = RelativePath(true, *relativePath.segments.drop(5).toTypedArray()) }
46+
eachFile{
47+
if(name != "code.js"){ return@eachFile }
48+
49+
val parentName = this.file.parentFile.name
50+
name = "$parentName.js"
51+
}
52+
}
53+
into(layout.buildDirectory.dir("mode/examples/Basics"))
54+
}
55+
}
3056
}
3157

3258
tasks.register<Copy>("createMode") {
33-
dependsOn("jar")
59+
dependsOn("jar", "includeP5jsExamples")
3460
into(layout.buildDirectory.dir("mode"))
3561
// TODO Why is there a duplicate in the first place?
3662
duplicatesStrategy = DuplicatesStrategy.WARN

p5js/js/electron/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const createWindow = () => {
77
height: 400,
88
show: false,
99
autoHideMenuBar: true,
10-
alwaysOnTop: true,
10+
alwaysOnTop: false,
1111
webPreferences: {
1212
contextIsolation: false,
1313
nodeIntegration: true,

p5js/src/main/kotlin/p5jsEditor.kt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ package processing.p5js
33
import androidx.compose.foundation.layout.*
44
import androidx.compose.foundation.lazy.LazyColumn
55
import androidx.compose.foundation.lazy.itemsIndexed
6-
import androidx.compose.material.Button
7-
import androidx.compose.material.Divider
8-
import androidx.compose.material.OutlinedTextField
9-
import androidx.compose.material.Text
6+
import androidx.compose.material3.Button
7+
import androidx.compose.material3.Divider
8+
import androidx.compose.material3.OutlinedTextField
9+
import androidx.compose.material3.Text
1010
import androidx.compose.runtime.getValue
1111
import androidx.compose.runtime.mutableStateOf
1212
import androidx.compose.runtime.remember
@@ -27,7 +27,7 @@ import processing.app.syntax.JEditTextArea
2727
import processing.app.syntax.PdeTextArea
2828
import processing.app.syntax.PdeTextAreaDefaults
2929
import processing.app.ui.*
30-
import processing.app.ui.theme.ProcessingTheme
30+
import processing.app.ui.theme.PDETheme
3131
import java.awt.event.ActionEvent
3232
import java.awt.event.ActionListener
3333
import java.io.BufferedReader
@@ -188,9 +188,11 @@ class p5jsEditor(base: Base, path: String?, state: EditorState?, mode: Mode?): E
188188

189189
override fun createFooter(): EditorFooter {
190190
val footer = super.createFooter()
191+
return footer;
192+
191193
val composePanel = ComposePanel()
192194
composePanel.setContent {
193-
ProcessingTheme {
195+
PDETheme(darkTheme = false) {
194196
var packageToInstall by remember { mutableStateOf("") }
195197
var packagesSearched by remember { mutableStateOf(listOf<String>()) }
196198
Row(
@@ -310,7 +312,7 @@ class p5jsEditor(base: Base, path: String?, state: EditorState?, mode: Mode?): E
310312
// TODO: more robust data exchange, double-check with @Stef
311313
// TODO: `statusError` does not do anything with column of a SketchException
312314
val ( msgType, msgText, msgFile, msgLine, msgCol ) = line.split("|")
313-
statusError(SketchException(msgText, 0, msgLine.toInt()-1, msgCol.toInt()))
315+
statusError(processing.utils.SketchException(msgText, 0, msgLine.toInt()-1, msgCol.toInt()))
314316
continue
315317
}
316318

0 commit comments

Comments
 (0)