[orx-file-watcher, orx-property-watchers] Add events and documentation

This commit is contained in:
Edwin Jakobs
2023-03-19 09:00:37 +01:00
parent e820885ea4
commit f21422359a
4 changed files with 83 additions and 40 deletions

View File

@@ -1,12 +1,17 @@
package org.openrndr.extra.propertywatchers
import org.openrndr.Program
import org.openrndr.draw.ColorBuffer
import org.openrndr.draw.loadImage
import java.io.File
import kotlin.reflect.KProperty0
fun Program.watchingImagePath(pathProperty: KProperty0<String>, imageTransform: (ColorBuffer) -> ColorBuffer = { it }) =
/**
* Delegate property value by watching a path property
* @param pathProperty the property holding a path to watch
* @param imageTransform an optional image transform function
* @since 0.4.3
*/
fun watchingImagePath(pathProperty: KProperty0<String>, imageTransform: (ColorBuffer) -> ColorBuffer = { it }) =
watchingProperty(pathProperty, cleaner = { it.destroy() }) {
val file = File(it)
require(file.exists()) { "$it does not exist" }
@@ -17,4 +22,4 @@ fun Program.watchingImagePath(pathProperty: KProperty0<String>, imageTransform:
image.destroy()
}
transformedImage
}
}