[orx-gui] doubleBind default true, add side canvas, add defaultStyles argument
This commit is contained in:
48
orx-jvm/orx-gui/src/demo/kotlin/DemoSideCanvas01.kt
Normal file
48
orx-jvm/orx-gui/src/demo/kotlin/DemoSideCanvas01.kt
Normal file
@@ -0,0 +1,48 @@
|
||||
import org.openrndr.application
|
||||
import org.openrndr.color.ColorRGBa
|
||||
import org.openrndr.extra.gui.GUI
|
||||
import org.openrndr.extra.parameters.*
|
||||
import org.openrndr.math.Vector2
|
||||
import org.openrndr.panel.elements.draw
|
||||
|
||||
|
||||
/**
|
||||
* A simple demonstration of a GUI for drawing some circles
|
||||
*/
|
||||
fun main() = application {
|
||||
configure {
|
||||
width = 800
|
||||
height = 800
|
||||
windowResizable = true
|
||||
|
||||
}
|
||||
program {
|
||||
val gui = GUI(baseColor = ColorRGBa.GRAY.shade(0.25))
|
||||
gui.compartmentsCollapsedByDefault = false
|
||||
gui.enableSideCanvas = true
|
||||
|
||||
|
||||
val settings = @Description("Settings") object {
|
||||
@DoubleParameter("radius", 0.0, 100.0)
|
||||
var radius = 50.0
|
||||
|
||||
@Vector2Parameter("position", 0.0, 1.0)
|
||||
var position = Vector2(0.6, 0.5)
|
||||
|
||||
@ColorParameter("color")
|
||||
var color = ColorRGBa.PINK
|
||||
|
||||
@DoubleListParameter("radii", 5.0, 30.0)
|
||||
var radii = mutableListOf(5.0, 6.0, 8.0, 14.0, 20.0, 30.0)
|
||||
}
|
||||
gui.add(settings)
|
||||
extend(gui)
|
||||
|
||||
gui.canvas?.draw {
|
||||
val width = drawer.width
|
||||
val height = drawer.height
|
||||
drawer.fill = settings.color
|
||||
drawer.circle(width/2.0, height/2.0, 100.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -71,7 +71,7 @@ private fun <T : Any> setAndPersist(compartmentLabel: String, property: KMutable
|
||||
private val logger = KotlinLogging.logger { }
|
||||
|
||||
@Suppress("unused", "UNCHECKED_CAST")
|
||||
class GUI : Extension {
|
||||
class GUI(val baseColor:ColorRGBa = ColorRGBa.GRAY, val defaultStyles: List<StyleSheet> = defaultStyles()) : Extension {
|
||||
private var onChangeListener: ((name: String, value: Any?) -> Unit)? = null
|
||||
override var enabled = true
|
||||
|
||||
@@ -91,10 +91,12 @@ class GUI : Extension {
|
||||
}
|
||||
|
||||
var compartmentsCollapsedByDefault = true
|
||||
var doubleBind = false
|
||||
var doubleBind = true
|
||||
var defaultSaveFolder = "gui-parameters"
|
||||
var persistState = true
|
||||
var enableSideCanvas = false
|
||||
|
||||
var canvas : Canvas? = null
|
||||
private var panel: ControlManager? = null
|
||||
|
||||
// Randomize button
|
||||
@@ -151,7 +153,22 @@ class GUI : Extension {
|
||||
}
|
||||
}
|
||||
|
||||
panel = program.controlManager {
|
||||
panel = program.controlManager(defaultStyles = defaultStyles) {
|
||||
styleSheet(has class_ "fullscreen") {
|
||||
this.width = 100.percent
|
||||
this.height = 100.percent
|
||||
this.flexDirection = FlexDirection.Row
|
||||
this.display = Display.FLEX
|
||||
}
|
||||
styleSheet(has class_ "full-canvas") {
|
||||
this.background = Color.RGBa(ColorRGBa.RED)
|
||||
|
||||
this.flexShrink = FlexGrow.Ratio(1.0)
|
||||
this.flexGrow = FlexGrow.Ratio(1.0)
|
||||
this.height = 100.percent
|
||||
this.width = 100.px
|
||||
}
|
||||
|
||||
styleSheet(has class_ "container") {
|
||||
this.display = Display.FLEX
|
||||
this.flexDirection = FlexDirection.Column
|
||||
@@ -164,10 +181,10 @@ class GUI : Extension {
|
||||
this.flexDirection = FlexDirection.Column
|
||||
this.height = 5.px
|
||||
this.width = 100.percent
|
||||
this.background = Color.RGBa(ColorRGBa.GRAY.shade(0.9))
|
||||
this.background = Color.RGBa(baseColor.shade(0.9))
|
||||
|
||||
and(has state "hover") {
|
||||
this.background = Color.RGBa(ColorRGBa.GRAY.shade(1.1))
|
||||
this.background = Color.RGBa(baseColor.shade(1.1))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,7 +193,7 @@ class GUI : Extension {
|
||||
this.width = 100.percent
|
||||
this.display = Display.FLEX
|
||||
this.flexDirection = FlexDirection.Row
|
||||
this.background = Color.RGBa(ColorRGBa.GRAY.copy(a = 0.99))
|
||||
this.background = Color.RGBa(baseColor.copy(a = 0.99))
|
||||
}
|
||||
|
||||
styleSheet(has class_ "collapsed") {
|
||||
@@ -195,7 +212,7 @@ class GUI : Extension {
|
||||
this.paddingRight = 10.px
|
||||
this.marginRight = 2.px
|
||||
this.height = 100.percent
|
||||
this.background = Color.RGBa(ColorRGBa.GRAY.copy(a = 0.99))
|
||||
this.background = Color.RGBa(baseColor.copy(a = 0.99))
|
||||
this.overflow = Overflow.Scroll
|
||||
|
||||
//<editor-fold desc="1) setup control style">
|
||||
@@ -248,9 +265,8 @@ class GUI : Extension {
|
||||
styleSheet(has type "dropdown-button") {
|
||||
this.width = 175.px
|
||||
}
|
||||
|
||||
|
||||
layout {
|
||||
div("fullscreen") {
|
||||
div("container") {
|
||||
id = "container"
|
||||
@Suppress("UNUSED_VARIABLE") val header = div("toolbar") {
|
||||
@@ -280,14 +296,21 @@ class GUI : Extension {
|
||||
setDefaultPathForContext(contextID = "gui.parameters", file = parameters)
|
||||
} else {
|
||||
if (parameters.mkdirs()) {
|
||||
setDefaultPathForContext(contextID = "gui.parameters", file = parameters)
|
||||
setDefaultPathForContext(
|
||||
contextID = "gui.parameters",
|
||||
file = parameters
|
||||
)
|
||||
} else {
|
||||
logger.warn { "Could not create directory ${parameters.absolutePath}" }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
saveFileDialog(suggestedFilename = "parameters.json", contextID = "gui.parameters", supportedExtensions = listOf("json")) {
|
||||
saveFileDialog(
|
||||
suggestedFilename = "parameters.json",
|
||||
contextID = "gui.parameters",
|
||||
supportedExtensions = listOf("json")
|
||||
) {
|
||||
saveParameters(it)
|
||||
}
|
||||
}
|
||||
@@ -371,12 +394,16 @@ class GUI : Extension {
|
||||
}
|
||||
sidebar.scrollTop = sidebarState().scrollTop
|
||||
}
|
||||
if (enableSideCanvas) {
|
||||
canvas = canvas("full-canvas") {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
visible = !sidebarState().hidden
|
||||
|
||||
|
||||
program.extend(panel ?: error("no panel"))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user