mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
Make CapturePreferences only keep track of changes (#1383)
Before `CapturePreferences` would override `LocalPreferences` and halt any changes upstream until `apply` was called, now it will let those changes slip through so we get immediate feedback on changes made in the preferences screen.
This commit is contained in:
@@ -443,7 +443,7 @@ private val LocalModifiablePreferences =
|
||||
compositionLocalOf { ModifiablePreference(null, false, { }, {}) }
|
||||
|
||||
/**
|
||||
* Composable function that provides a modifiable copy of the current preferences.
|
||||
* Composable function that captures an initial copy of the current preferences.
|
||||
* This allows for temporary changes to preferences that can be reset or applied later.
|
||||
*
|
||||
* @param content The composable content that will have access to the modifiable preferences.
|
||||
@@ -500,13 +500,13 @@ private fun CapturePreferences(content: @Composable () -> Unit) {
|
||||
}
|
||||
|
||||
val apply = {
|
||||
modified.entries.forEach { (key, value) ->
|
||||
prefs.setProperty(key as String, (value ?: "") as String)
|
||||
prefs.entries.forEach { (key, value) ->
|
||||
modified.setProperty(key as String, (value ?: "") as String)
|
||||
}
|
||||
}
|
||||
val reset = {
|
||||
modified.entries.forEach { (key, value) ->
|
||||
modified.setProperty(key as String, prefs[key] ?: "")
|
||||
prefs.setProperty(key as String, modified[key] ?: "")
|
||||
}
|
||||
}
|
||||
val state = ModifiablePreference(
|
||||
@@ -517,7 +517,6 @@ private fun CapturePreferences(content: @Composable () -> Unit) {
|
||||
)
|
||||
|
||||
CompositionLocalProvider(
|
||||
LocalPreferences provides modified,
|
||||
LocalModifiablePreferences provides state
|
||||
) {
|
||||
content()
|
||||
|
||||
Reference in New Issue
Block a user