Skip to content

Commit e1fcdb1

Browse files
SteftervSableRaf
andauthored
Welcome screen implementation (#1307)
* Remove ContributionManager and ContributionPane UI files Deleted ContributionManager.kt and ContributionPane.kt from the contrib/ui directory. This removes the Compose-based contributions manager and its detail pane prototypes which got merged unnecessarily * Enhance Preferences reactivity and test coverage Refactored ReactiveProperties to use snapshotStateMap for Compose reactivity. Improved PreferencesProvider and watchFile composables with better file watching, override support via system properties, and added documentation. Updated PreferencesKtTest to use temporary files and verify file-to-UI reactivity. * Small bugfix for removed function * Add compose ui test to the deps * Refactor theme system to Material 3 color schemes Replaces legacy color definitions with Material 3 color schemes and introduces extended color support for warnings. Dialogs in Messages.kt are now implemented using Compose Material 3 components for a modern UI. Removes deprecated color sets and updates PDETheme to use new color schemes, improving consistency and maintainability. * Add PDEWelcome Composable UI screen Introduces a new PDEWelcome.kt file with a Composable UI for the Processing welcome screen. Includes layout with buttons for language selection, new sketch, examples, and sketchbook, as well as a placeholder for right-side content and a main entry point for launching the window. * Initial layout * Revamp welcome screen UI and add social icons Refactors the PDEWelcome screen to improve layout, update button icons, and add support for Discord, GitHub, and Instagram SVG icons. The welcome screen now receives a Base instance for proper action handling, and new methods replace deprecated ones in Base.java. Updates related menu actions to pass the Base instance as needed. * Add example previews to welcome screen Replaces placeholder text on the right side of the PDEWelcome screen with a LazyColumn displaying example sketches. Each example attempts to show a preview image if available, or a placeholder icon otherwise. Introduces an Example data class and related image loading logic. * Add hover-activated play button to example previews Introduced a hover effect on example preview images in the welcome screen, displaying a play button that opens the example when clicked. Refactored title key usage for consistency. * Localize welcome screen UI strings Replaced hardcoded strings in the PDEWelcome screen with localized values using the LocalLocale context. Added new keys for the welcome screen to the English and Dutch language property files to support internationalization. * Add language selector and UI improvements to welcome screen Introduces a language selection dropdown to the PDE welcome screen using a shared composable from preferences. Refactors the layout for better spacing, updates example cards with animated overlays, and replaces the show-on-startup button with a checkbox. Also adds a new translation key for the open example button. * Refactor example listing and randomize welcome sketches Moved example folder listing logic in Contributions.ExamplesList to a companion object function for reuse. Updated PDEWelcome to display a randomized selection of sketches from all available examples, replacing the previous static list. * Refactor example handling to use Sketch objects Replaces Example objects with Sketch objects for managing example sketches in the welcome screen. Updates all relevant usages to reference Sketch properties, simplifying the code and improving clarity. * Add vertical scrollbar to welcome screen examples Introduces a VerticalScrollbar to the examples list in the PDEWelcome screen for improved navigation. Also adjusts spacing and arrangement in several UI components for better layout consistency, and updates the welcome screen title in the language properties. * Add rounded corners to buttons in PDEWelcome Introduced a RoundedCornerShape with 12.dp radius and applied it to various buttons in the PDEWelcome screen for improved UI consistency and aesthetics. * Refactor PDEWelcome UI and add Sketch card composable Refactored the PDEWelcome screen for improved structure and readability, including extracting the example preview into a reusable Sketch.card composable. Updated icon usage for RTL support, adjusted layout and padding, and improved the examples list initialization. Also, customized scrollbar style in PDETheme for a more consistent UI appearance. * Add unique window handling to prevent duplicates Introduces a 'unique' parameter to PDESwingWindow and PDEComposeWindow, allowing windows to be identified by a KClass and preventing multiple instances of the same window. If a window with the same unique identifier exists, it is brought to the front and the new one is disposed. This helps avoid duplicate welcome or other singleton windows. * Refactor dialog handling and improve AlertDialog UI Refactored the showDialog function to accept a modifier and updated all AlertDialog usages to use RectangleShape and the modifier parameter. Improved dialog sizing and positioning by dynamically adjusting the window size based on content, and set additional window properties for better integration on macOS. * Set application window icon using Toolkit.setIcon Added calls to Toolkit.setIcon(window) in Start.kt and Window.kt to ensure the application window icon is set consistent * Simplify imports and update scrollbar colors in Theme.kt Consolidated import statements for Compose libraries using wildcard imports to reduce verbosity. Updated scrollbar hover and unhover colors to use the default outlineVariant color without alpha modification. * Removing the Preferences work to keep the PR clean * Update background color in PDEWelcome UI Changed the background color from surfaceContainerLow to surfaceContainerLowest in the PDEWelcome composable for improved visual consistency with the MaterialTheme. * Tweak welcome actions naming and order - Rename `Empty Sketch` to `New Sketch` - Rename `Sketchbook` to `My Sketches` - Move `Open Examples` below `My Sketches` * Rather than setting the decorations app wide, just modify the editor screen --------- Co-authored-by: Raphaël de Courville <[email protected]>
1 parent e9b381b commit e1fcdb1

File tree

24 files changed

+1545
-1007
lines changed

24 files changed

+1545
-1007
lines changed
File renamed without changes.
File renamed without changes.
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 10 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading

app/src/processing/app/Base.java

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,29 @@
2323

2424
package processing.app;
2525

26-
import java.awt.*;
27-
import java.awt.event.ActionListener;
28-
import java.io.*;
29-
import java.lang.reflect.InvocationTargetException;
30-
import java.util.*;
31-
import java.util.List;
32-
import java.util.Map.Entry;
33-
34-
import javax.swing.*;
35-
import javax.swing.tree.DefaultMutableTreeNode;
36-
3726
import com.formdev.flatlaf.FlatDarkLaf;
3827
import com.formdev.flatlaf.FlatLaf;
3928
import com.formdev.flatlaf.FlatLightLaf;
4029
import processing.app.contrib.*;
4130
import processing.app.tools.Tool;
4231
import processing.app.ui.*;
43-
import processing.app.ui.PreferencesKt;
4432
import processing.app.ui.Toolkit;
45-
import processing.core.*;
33+
import processing.core.PApplet;
4634
import processing.data.StringList;
4735

36+
import javax.swing.*;
37+
import javax.swing.tree.DefaultMutableTreeNode;
38+
import java.awt.*;
39+
import java.awt.event.ActionListener;
40+
import java.io.File;
41+
import java.io.FileInputStream;
42+
import java.io.IOException;
43+
import java.io.InputStream;
44+
import java.lang.reflect.InvocationTargetException;
45+
import java.util.*;
46+
import java.util.List;
47+
import java.util.Map.Entry;
48+
4849
/**
4950
* The base class for the main processing application.
5051
* Primary role of this class is for platform identification and
@@ -375,13 +376,7 @@ static private void handleWelcomeScreen(Base base) {
375376
// Needs to be shown after the first editor window opens, so that it
376377
// shows up on top, and doesn't prevent an editor window from opening.
377378
if (Preferences.getBoolean("welcome.four.show")) {
378-
try {
379-
new Welcome(base);
380-
} catch (IOException e) {
381-
Messages.showTrace("Unwelcoming",
382-
"Please report this error to\n" +
383-
"https://github.com/processing/processing4/issues", e, false);
384-
}
379+
PDEWelcomeKt.showWelcomeScreen(base);
385380
}
386381
}
387382

@@ -609,7 +604,7 @@ public JMenu initDefaultFileMenu() {
609604
defaultFileMenu.add(item);
610605

611606
item = Toolkit.newJMenuItemShift(Language.text("menu.file.examples"), 'O');
612-
item.addActionListener(e -> thinkDifferentExamples());
607+
item.addActionListener(e -> showExamplesFrame());
613608
defaultFileMenu.add(item);
614609

615610
return defaultFileMenu;
@@ -1885,7 +1880,7 @@ public void handleRestart() {
18851880
// }
18861881

18871882

1888-
public void thinkDifferentExamples() {
1883+
public void showExamplesFrame() {
18891884
nextMode.showExamplesFrame();
18901885
}
18911886

@@ -2191,7 +2186,10 @@ static private Mode findSketchMode(File folder, List<Mode> modeList) {
21912186
* Show the Preferences window.
21922187
*/
21932188
public void handlePrefs() {
2194-
PreferencesKt.show();
2189+
if (preferencesFrame == null) {
2190+
preferencesFrame = new PreferencesFrame(this);
2191+
}
2192+
preferencesFrame.showFrame();
21952193
}
21962194

21972195

app/src/processing/app/Messages.kt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,27 @@
1818
*/
1919
package processing.app
2020

21+
import androidx.compose.foundation.layout.Column
22+
import androidx.compose.foundation.layout.padding
23+
import androidx.compose.material3.Button
24+
import androidx.compose.material3.Text
25+
import androidx.compose.ui.Modifier
26+
import androidx.compose.ui.unit.DpSize
27+
import androidx.compose.ui.unit.dp
28+
import androidx.compose.ui.window.Window
29+
import androidx.compose.ui.window.application
30+
import androidx.compose.ui.window.rememberWindowState
31+
import com.formdev.flatlaf.FlatLightLaf
2132
import processing.app.ui.Toolkit
33+
import processing.app.ui.theme.PDETheme
2234
import java.awt.EventQueue
2335
import java.awt.Frame
2436
import java.io.PrintWriter
2537
import java.io.StringWriter
2638
import javax.swing.JFrame
2739
import javax.swing.JOptionPane
40+
import javax.swing.UIManager
41+
2842

2943
class Messages {
3044
companion object {
@@ -270,6 +284,37 @@ class Messages {
270284
}
271285
}
272286
}
287+
fun main(){
288+
val types = mapOf(
289+
"message" to { Messages.showMessage("Test Title", "This is a test message.") },
290+
"warning" to { Messages.showWarning("Test Warning", "This is a test warning.", Exception("dfdsfjk")) },
291+
"trace" to { Messages.showTrace("Test Trace", "This is a test trace.", Exception("Test Exception"), false) },
292+
"tiered_warning" to { Messages.showWarningTiered("Test Tiered Warning", "Primary message", "Secondary message", null) },
293+
"yes_no" to { Messages.showYesNoQuestion(null, "Test Yes/No", "Do you want to continue?", "Choose yes or no.") },
294+
"custom_question" to { Messages.showCustomQuestion(null, "Test Custom Question", "Choose an option:", "Select one of the options below.", 1, "Option 1", "Option 2", "Option 3") },
295+
"error" to { Messages.showError("Test Error", "This is a test error.", null) },
296+
)
297+
Platform.init()
298+
UIManager.setLookAndFeel(FlatLightLaf())
299+
application {
300+
val state = rememberWindowState(
301+
size = DpSize(500.dp, 300.dp)
302+
)
303+
Window(state = state, onCloseRequest = ::exitApplication, title = "Test Messages") {
304+
PDETheme {
305+
Column {
306+
for ((type, action) in types) {
307+
Button(onClick = { action() }, modifier = Modifier.padding(8.dp)) {
308+
Text("Show $type dialog")
309+
}
310+
}
311+
}
312+
}
313+
}
314+
315+
}
316+
317+
}
273318

274319
// Helper functions to give the base classes a color
275320
fun String.formatClassName() = this

0 commit comments

Comments
 (0)