Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mouse enter event not being emitted on root component fix #233

Open
wants to merge 3 commits into
base: 1.20.5
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/io/wispforest/owo/ui/base/BaseComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ protected void updateHoveredState(int mouseX, int mouseY, boolean nowHovered) {
this.hovered = nowHovered;

if (nowHovered) {
if (this.root() == null || this.root().childAt(mouseX, mouseY) != this) {
if (this.root() != null && this.root().childAt(mouseX, mouseY) != this) {
this.hovered = false;
return;
}
Expand Down
21 changes: 19 additions & 2 deletions src/main/java/io/wispforest/owo/ui/base/BaseParentComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import io.wispforest.owo.ui.util.FocusHandler;
import io.wispforest.owo.ui.util.ScissorStack;
import io.wispforest.owo.util.Observable;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.math.MathHelper;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.glfw.GLFW;
Expand Down Expand Up @@ -51,6 +50,23 @@ public final void update(float delta, int mouseX, int mouseY) {
}
}

@Override
protected void updateHoveredState(int mouseX, int mouseY, boolean nowHovered) {
this.hovered = nowHovered;

if (nowHovered) {
ParentComponent root = this.root();
if ((root != null && root.childAt(mouseX, mouseY) != this) || (root == null && this.childAt(mouseX, mouseY) != this)) {
this.hovered = false;
return;
}

this.mouseEnterEvents.sink().onMouseEnter();
} else {
this.mouseLeaveEvents.sink().onMouseLeave();
}
}

/**
* Update the state of this component before drawing
* the next frame. This method is separated from
Expand All @@ -61,7 +77,8 @@ public final void update(float delta, int mouseX, int mouseY) {
* @param mouseX The mouse pointer's x-coordinate
* @param mouseY The mouse pointer's y-coordinate
*/
protected void parentUpdate(float delta, int mouseX, int mouseY) {}
protected void parentUpdate(float delta, int mouseX, int mouseY) {
}

@Override
public void draw(OwoUIDrawContext context, int mouseX, int mouseY, float partialTicks, float delta) {
Expand Down