Skip to content

Commit fc91a2d

Browse files
committed
Interaction passthrough changes
1 parent 1cf9550 commit fc91a2d

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

common/src/main/kotlin/com/lambda/newgui/Layout.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ open class Layout(
6161
}
6262

6363
private var owningRenderer = false
64-
protected open val passInteractions = false
64+
protected open val interactionPassthrough = false
6565

6666
// Actions
6767
private var showActions = mutableListOf<() -> Unit>()
@@ -165,16 +165,18 @@ open class Layout(
165165

166166
fun onEvent(e: GuiEvent) {
167167
// Select an element that's on foreground
168-
selectedChild = if (mousePosition in rect) children.lastOrNull {
169-
!it.passInteractions && mousePosition in it.rect
168+
selectedChild = if (isHovered) children.lastOrNull {
169+
!it.interactionPassthrough && mousePosition in it.rect
170170
} else null
171171

172172
// Update children
173173
children.forEach { child ->
174174
if (e is GuiEvent.Render) return@forEach
175175

176176
if (e is GuiEvent.MouseClick) {
177-
val newAction = if (child == selectedChild || (child.passInteractions)) e.action else Mouse.Action.Release
177+
val hovered = child == selectedChild || (child.isHovered && child.interactionPassthrough)
178+
val newAction = if (hovered) e.action else Mouse.Action.Release
179+
178180
val newEvent = GuiEvent.MouseClick(e.button, newAction, e.mouse)
179181
child.onEvent(newEvent)
180182
return@forEach

common/src/main/kotlin/com/lambda/newgui/component/core/TextField.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class TextField(
2626
var offset = initialOffset
2727

2828
// Let user interact through the text
29-
override val passInteractions = true
29+
override val interactionPassthrough = true
3030

3131
init {
3232
rect {

0 commit comments

Comments
 (0)