Skip to content

Commit

Permalink
Fixes issue #2452, tooltips flicker when forced under the mouse
Browse files Browse the repository at this point in the history
This scenario can occur when a tooltip is unable to render in the preferred
location due to the screen boundaries, for instance if an item with a really
long tooltip is placed in the lower-right most inventory slot.  Because UILists
define InteractionRegions around their contents by default and tooltips are
rendered last, they are seen as the new top-most interactive element on the
following game tick.  This causes an immediate reset of the tooltip timer due
to the top-most region changing, and the process repeats.  This has been fixed
by preventing tooltips from defining interaction regions through a new optional
flag in UIList that sets whether the list is interactive or not.
  • Loading branch information
segfault802 committed Oct 23, 2016
1 parent 610b6d2 commit 54ebdcb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class UIList<T> extends CoreWidget {
private final List<ItemInteractionListener> itemListeners = Lists.newArrayList();
private final List<ItemActivateEventListener<T>> activateListeners = Lists.newArrayList();
private final List<ItemSelectEventListener<T>> selectionListeners = Lists.newArrayList();
private Binding<Boolean> interactive = new DefaultBinding<>(true);
private Binding<Boolean> selectable = new DefaultBinding<>(true);
private Binding<T> selection = new DefaultBinding<>();
private Binding<List<T>> list = new DefaultBinding<>(new ArrayList<>());
Expand Down Expand Up @@ -80,7 +81,9 @@ public void onDraw(Canvas canvas) {
} else {
canvas.setMode(DEFAULT_MODE);
}
canvas.addInteractionRegion(listener, itemRenderer.getTooltip(item), itemRegion);
if (isInteractive()) {
canvas.addInteractionRegion(listener, itemRenderer.getTooltip(item), itemRegion);
}
} else {
canvas.setMode(DISABLED_MODE);
}
Expand Down Expand Up @@ -134,10 +137,14 @@ public void bindSelectable(Binding<Boolean> binding) {
selectable = binding;
}

public boolean isInteractive() { return interactive.get(); }

public boolean isSelectable() {
return selectable.get();
}

public void setInteractive(boolean value) { interactive.set(value); }

public void setSelectable(boolean value) {
selectable.set(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class ItemIcon extends CoreWidget {

public ItemIcon() {
tooltip = new UIList<>();
tooltip.setInteractive(false);
tooltip.setSelectable(false);
final UISkin defaultSkin = Assets.getSkin("core:itemTooltip").get();
tooltip.setSkin(defaultSkin);
Expand Down

0 comments on commit 54ebdcb

Please sign in to comment.