Skip to content

Commit

Permalink
[ui] fix tooltip rendering for stacked sibling components, fix 'Label…
Browse files Browse the repository at this point in the history
…Component#shouldDrawTooltip' in case there is no tooltip but the text has a hover event
  • Loading branch information
gliscowo committed Jan 18, 2024
1 parent 4b2ee66 commit d47a040
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ minecraft_version=1.20.3
yarn_mappings=1.20.3+build.1
loader_version=0.15.0
# Mod Properties
mod_version=0.12.2
mod_version=0.12.3
maven_group=io.wispforest
archives_base_name=owo-lib
# Dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,15 @@ public void draw(OwoUIDrawContext context, int mouseX, int mouseY, float partial
@Override
public void drawTooltip(OwoUIDrawContext context, int mouseX, int mouseY, float partialTicks, float delta) {
super.drawTooltip(context, mouseX, mouseY, partialTicks, delta);

if (!this.isInBoundingBox(mouseX, mouseY)) return;
context.drawHoverEvent(this.textRenderer, this.styleAt(mouseX - this.x, mouseY - this.y), mouseX, mouseY);
}

@Override
public boolean shouldDrawTooltip(double mouseX, double mouseY) {
var hoveredStyle = this.styleAt((int) (mouseX - this.x), (int) (mouseY - this.y));
return super.shouldDrawTooltip(mouseX, mouseY) || (hoveredStyle != null && hoveredStyle.getHoverEvent() != null && this.isInBoundingBox(mouseX, mouseY));
}

@Override
public boolean onMouseDown(double mouseX, double mouseY, int button) {
return this.textClickHandler.apply(this.styleAt((int) mouseX, (int) mouseY)) | super.onMouseDown(mouseX, mouseY, button);
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/io/wispforest/owo/ui/core/ParentComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,16 @@ default void drawTooltip(OwoUIDrawContext context, int mouseX, int mouseY, float
hoveredDescendants.remove(this);

for (int i = hoveredDescendants.size() - 1; i >= 0; i--) {
ParentComponent nextParent = null;
for (int parentIdx = i - 1; parentIdx >= 0; parentIdx--) {
if (hoveredDescendants.get(parentIdx) instanceof ParentComponent parent) {
nextParent = parent;
break;
}
}

var current = hoveredDescendants.get(i);
if (i > 0 && current.parent() != hoveredDescendants.get(i - 1)) break;
if (nextParent != null && current.parent() != nextParent) break;
if (!current.shouldDrawTooltip(mouseX, mouseY)) continue;

context.push();
Expand Down

0 comments on commit d47a040

Please sign in to comment.