Merge pull request #18 from ricardomatias/orx-palette
Add onChange listener and addPalette method to orx-palette
This commit is contained in:
@@ -46,7 +46,6 @@ class PaletteStudio(
|
|||||||
var palettes: MutableList<List<ColorRGBa>> = mutableListOf()
|
var palettes: MutableList<List<ColorRGBa>> = mutableListOf()
|
||||||
var palette: Palette = defaultPalette
|
var palette: Palette = defaultPalette
|
||||||
|
|
||||||
|
|
||||||
var randomPaletteKey = 'l'
|
var randomPaletteKey = 'l'
|
||||||
var randomizeKey = 'k'
|
var randomizeKey = 'k'
|
||||||
|
|
||||||
@@ -92,6 +91,8 @@ class PaletteStudio(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var onChangeListener = {}
|
||||||
|
|
||||||
private fun loadCollection(newCollection: Collections) {
|
private fun loadCollection(newCollection: Collections) {
|
||||||
val collectionPath: URL = collectionsResource.getValue(newCollection)
|
val collectionPath: URL = collectionsResource.getValue(newCollection)
|
||||||
palettes = mutableListOf()
|
palettes = mutableListOf()
|
||||||
@@ -159,6 +160,17 @@ class PaletteStudio(
|
|||||||
return Palette(background, foreground, colors1, colors2)
|
return Palette(background, foreground, colors1, colors2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun onChange(fn: () -> Unit) {
|
||||||
|
onChangeListener = fn
|
||||||
|
}
|
||||||
|
|
||||||
|
fun add(newPalette: List<ColorRGBa>) {
|
||||||
|
palette = createPalette(newPalette)
|
||||||
|
|
||||||
|
palettes.add(newPalette)
|
||||||
|
paletteIndex = palettes.lastIndex
|
||||||
|
}
|
||||||
|
|
||||||
fun loadExternal(filePath: String) {
|
fun loadExternal(filePath: String) {
|
||||||
palettes = mutableListOf()
|
palettes = mutableListOf()
|
||||||
|
|
||||||
@@ -205,9 +217,11 @@ class PaletteStudio(
|
|||||||
if (!it.propagationCancelled) {
|
if (!it.propagationCancelled) {
|
||||||
if (it.name == "$randomPaletteKey") {
|
if (it.name == "$randomPaletteKey") {
|
||||||
randomPalette()
|
randomPalette()
|
||||||
|
onChangeListener()
|
||||||
}
|
}
|
||||||
if (it.name == "$randomizeKey") {
|
if (it.name == "$randomizeKey") {
|
||||||
randomize()
|
randomize()
|
||||||
|
onChangeListener()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user