diff --git a/orx-gui/src/demo/kotlin/DemoXYParameter.kt b/orx-gui/src/demo/kotlin/DemoXYParameter.kt new file mode 100644 index 00000000..f5f0de19 --- /dev/null +++ b/orx-gui/src/demo/kotlin/DemoXYParameter.kt @@ -0,0 +1,32 @@ +import org.openrndr.application +import org.openrndr.extra.gui.GUI +import org.openrndr.extra.parameters.ActionParameter +import org.openrndr.extra.parameters.Description +import org.openrndr.extra.parameters.XYParameter +import org.openrndr.math.Vector2 + +fun main() = application { + configure { + width = 800 + height = 800 + } + + program { + val gui = GUI() + + val settings = @Description("Vector parameter!") object { + @XYParameter("Position", 0.0, 800.0, 0.0, 800.0, + precision = 2, + invertY = true, + showVector = true) + var position: Vector2 = Vector2(0.0,0.0) + } + + gui.add(settings) + + extend(gui) + extend { + drawer.circle(settings.position, 50.0) + } + } +} diff --git a/orx-gui/src/main/kotlin/Gui.kt b/orx-gui/src/main/kotlin/Gui.kt index f67e6f2a..afc2afd9 100644 --- a/orx-gui/src/main/kotlin/Gui.kt +++ b/orx-gui/src/main/kotlin/Gui.kt @@ -463,6 +463,7 @@ class GUI : Extension { precision = parameter.precision!! showVector = parameter.showVector!! invertY = parameter.invertY!! + label = parameter.label events.valueChanged.listen { setAndPersist( diff --git a/orx-panel/src/main/kotlin/org/openrndr/panel/elements/XYPad.kt b/orx-panel/src/main/kotlin/org/openrndr/panel/elements/XYPad.kt index a1ba22de..2e567caf 100644 --- a/orx-panel/src/main/kotlin/org/openrndr/panel/elements/XYPad.kt +++ b/orx-panel/src/main/kotlin/org/openrndr/panel/elements/XYPad.kt @@ -22,6 +22,11 @@ class XYPad : Element(ElementType("xy-pad")) { var maxX = 1.0 var maxY = 1.0 + /** + * The label + */ + var label: String? = null + /** * The precision of the control, default is 2 */ @@ -198,12 +203,13 @@ class XYPad : Element(ElementType("xy-pad")) { drawer.stroke = ColorRGBa.WHITE drawer.circle(ballPosition, 8.0) - val label = "${String.format("%.0${precision}f", value.x)}, ${String.format("%.0${precision}f", value.y)}" + val valueLabel = "${String.format("%.0${precision}f", value.x)}, ${String.format("%.0${precision}f", value.y)}" + (root() as? Body)?.controlManager?.fontManager?.let { val font = it.font(computedStyle) val writer = Writer(drawer) drawer.fontMap = (font) - val textWidth = writer.textWidth(label) + val textWidth = writer.textWidth(valueLabel) val textHeight = font.ascenderLength drawer.fill = ((computedStyle.color as? Color.RGBa)?.color ?: ColorRGBa.WHITE).opacify( @@ -211,7 +217,11 @@ class XYPad : Element(ElementType("xy-pad")) { ) - drawer.text(label, Vector2(layout.screenWidth - textWidth - 4.0, layout.screenHeight - textHeight + 6.0)) + if (label != null) { + drawer.text(label!!, Vector2(0.0, 0.0)) + } + + drawer.text(valueLabel, Vector2(layout.screenWidth - textWidth - 4.0, layout.screenHeight - textHeight + 6.0)) } drawer.popStyle()