Skip to content

Commit

Permalink
[orx-gui] Add visible property to Gui
Browse files Browse the repository at this point in the history
  • Loading branch information
edwinRNDR committed Nov 29, 2020
1 parent 182ff7e commit dc411e4
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 14 deletions.
57 changes: 57 additions & 0 deletions orx-gui/src/demo/kotlin/DemoHide01.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.extensions.SingleScreenshot
import org.openrndr.extra.gui.GUI
import org.openrndr.extra.parameters.*
import org.openrndr.math.Vector2
import org.openrndr.shape.Circle

/**
* A simple demonstration of a GUI for drawing some circles
*/
fun main() = application {
program {
// -- this block is for automation purposes only
if (System.getProperty("takeScreenshot") == "true") {
extend(SingleScreenshot()) {
this.outputFile = System.getProperty("screenshotPath")
}
}

val gui = GUI()
gui.compartmentsCollapsedByDefault = false


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)

// note we can only change the visibility after the extend
gui.visible = false

extend {
// determine visibility through mouse x-coordinate
gui.visible = mouse.position.x < 200.0

drawer.fill = settings.color
drawer.circle(settings.position * drawer.bounds.position(1.0, 1.0), settings.radius)
drawer.circles(
settings.radii.mapIndexed { i, radius ->
Circle(width - 50.0, 60.0 + i * 70.0, radius)
}
)
}
}
}
31 changes: 17 additions & 14 deletions orx-gui/src/main/kotlin/Gui.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,23 @@ class GUI : Extension {
private var onChangeListener: ((name: String, value: Any?) -> Unit)? = null
override var enabled = true

private var visible = true
var visible = true
set(value) {
if (field != value) {
field = value
if (field) {
panel?.body?.classes?.remove(collapsed)
} else {
panel?.body?.classes?.add(collapsed)
}
sidebarState().hidden = !field
}
}

var compartmentsCollapsedByDefault = true
var doubleBind = false

private lateinit var panel: ControlManager
private var panel: ControlManager? = null

// Randomize button
private var shiftDown = false
Expand All @@ -95,12 +106,8 @@ class GUI : Extension {
println("f11 pressed")
visible = !visible

if(visible) {
panel.body!!.classes.remove(collapsed)
} else {
panel.body!!.classes.add(collapsed)
}
sidebarState().hidden = !visible


}

if (it.key == KEY_LEFT_SHIFT) {
Expand Down Expand Up @@ -341,13 +348,9 @@ class GUI : Extension {
}

visible = !sidebarState().hidden
if(visible) {
panel.body!!.classes.remove(collapsed)
} else {
panel.body!!.classes.add(collapsed)
}

program.extend(panel)

program.extend(panel ?: error("no panel"))
}

/* 2) control creation. create control, set label, set range, setup event-handler, load values */
Expand Down

0 comments on commit dc411e4

Please sign in to comment.