[orx-panel] Add isHidden method to skip hidden elements during event handling

This commit is contained in:
Edwin Jakobs
2025-08-22 18:28:32 +02:00
parent e6766aa1ce
commit 9c1fa98d68
3 changed files with 46 additions and 1 deletions

View File

@@ -18,4 +18,5 @@ dependencies {
testRuntimeOnly(libs.kotlin.reflect)
demoImplementation(libs.openrndr.dialogs)
demoImplementation(libs.gson)
demoImplementation(project(":orx-jvm:orx-panel"))
}

View File

@@ -11,6 +11,7 @@ import org.openrndr.panel.layout.Layouter
import org.openrndr.panel.style.*
import org.openrndr.panel.style.Display
import org.openrndr.shape.Rectangle
import org.w3c.dom.Node
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract
@@ -63,6 +64,9 @@ class ControlManager : Extension {
fun press(event: KeyEvent) {
target?.let {
if (it.isHidden()) {
return
}
var current: Element? = it
while (current != null) {
if (!event.propagationCancelled) {
@@ -96,6 +100,10 @@ class ControlManager : Extension {
}
fun release(event: KeyEvent) {
if (target?.isHidden() == true) {
return
}
target?.keyboard?.released?.trigger(event)
if (target != null) {
checkForManualRedraw()
@@ -103,6 +111,10 @@ class ControlManager : Extension {
}
fun repeat(event: KeyEvent) {
if (target?.isHidden() == true) {
return
}
target?.keyboard?.repeated?.trigger(event)
if (target != null) {
checkForManualRedraw()
@@ -110,6 +122,10 @@ class ControlManager : Extension {
}
fun character(event: CharacterEvent) {
if (target?.isHidden() == true) {
return
}
target?.keyboard?.character?.trigger(event)
if (target != null) {
checkForManualRedraw()
@@ -156,6 +172,9 @@ class ControlManager : Extension {
logger.debug { "click target: $clickTarget" }
clickTarget?.let {
if (it.isHidden()) {
return
}
if (it.handlesDoubleClick) {
if (ct - lastClick > 500) {
logger.debug { "normal click on $clickTarget" }
@@ -223,7 +242,14 @@ class ControlManager : Extension {
fun drag(event: MouseEvent) {
logger.debug { "drag event $event" }
dragTarget?.mouse?.dragged?.trigger(event)
dragTarget?.let {
if (it.isHidden()) {
dragTarget = null
return
}
it.mouse.dragged.trigger(event)
}
if (event.propagationCancelled) {
logger.debug { "propagation cancelled by $dragTarget setting clickTarget to null" }
clickTarget = null

View File

@@ -140,6 +140,24 @@ open class Element(val type: ElementType) {
}
/**
* Determines whether the current element, or any of its ancestors, has a display style of `Display.NONE`.
*
* @return `true` if the element or any of its ancestors is hidden (has `Display.NONE` style), `false` otherwise.
*/
fun isHidden() : Boolean {
var current: Element? = this
while (current != null) {
if (current.computedStyle.display == Display.NONE) {
return true
}
current = current.parent
}
return false
}
fun root(): Element {
return parent?.root() ?: this
}