Fix isHovered being false when outside of parent's bounds

This commit is contained in:
DBotThePony 2022-09-04 17:02:53 +07:00
parent 9f6b884c8c
commit bc6bb15874
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -382,11 +382,15 @@ open class EditablePanel @JvmOverloads constructor(
absoluteX = x absoluteX = x
absoluteY = y absoluteY = y
} else { } else {
isHovered = parent.isHovered && if (x < 0f || y < 0f || x + width > parent.width || y + height > parent.height) {
mouseX >= absoluteX && // no op - we updated ourselves in tickHover
mouseX < absoluteX + width && } else {
mouseY >= absoluteY && isHovered = parent.isHovered &&
mouseY < absoluteY + height mouseX >= absoluteX &&
mouseX < absoluteX + width &&
mouseY >= absoluteY &&
mouseY < absoluteY + height
}
} }
val scissor = this.scissor val scissor = this.scissor
@ -426,6 +430,23 @@ open class EditablePanel @JvmOverloads constructor(
} }
open fun tickHover(mouse_x: Float, mouse_y: Float): Boolean { open fun tickHover(mouse_x: Float, mouse_y: Float): Boolean {
if (boundingHeight > height || boundingWidth > width || boundingX < 0 || boundingY < 0) {
var hit = false
for (child in children) {
if (child.tickHover(mouse_x, mouse_y)) {
hit = true
}
}
isHovered = mouse_x >= absoluteX &&
mouse_x <= absoluteX + width &&
mouse_y >= absoluteY &&
mouse_y <= absoluteY + height
return hit
}
isHovered = isHovered =
mouse_x >= absoluteX && mouse_x >= absoluteX &&
mouse_x <= absoluteX + width && mouse_x <= absoluteX + width &&