-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent tooltip popover flicker upon mouseover
Provide a wrapper for PopOver components used as tooltips, to debounce the 'MouseEntered' and 'MouseExited' events used to show/hide it, in order to prevent it flickering open/closed in a loop. This fixes #3016. To this end, use a ..->HIDDEN->SHOWING->SHOWN->HIDING->.. state field, together with a target visibility boolean field, where the transition between HIDDEN and SHOWN incurs a small fixed delay.
- Loading branch information
Showing
5 changed files
with
114 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
desktop/src/main/java/bisq/desktop/components/PopOverWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* This file is part of Bisq. | ||
* | ||
* Bisq is free software: you can redistribute it and/or modify it | ||
* under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or (at | ||
* your option) any later version. | ||
* | ||
* Bisq is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public | ||
* License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with Bisq. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package bisq.desktop.components; | ||
|
||
import bisq.common.UserThread; | ||
|
||
import org.controlsfx.control.PopOver; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
import java.util.function.Supplier; | ||
|
||
public class PopOverWrapper { | ||
|
||
private PopOver popover; | ||
private Supplier<PopOver> popoverSupplier; | ||
private boolean hidePopover; | ||
private PopOverState state = PopOverState.HIDDEN; | ||
|
||
enum PopOverState { | ||
HIDDEN, SHOWING, SHOWN, HIDING | ||
} | ||
|
||
public void showPopOver(Supplier<PopOver> popoverSupplier) { | ||
this.popoverSupplier = popoverSupplier; | ||
hidePopover = false; | ||
|
||
if (state == PopOverState.HIDDEN) { | ||
state = PopOverState.SHOWING; | ||
popover = popoverSupplier.get(); | ||
|
||
UserThread.runAfter(() -> { | ||
state = PopOverState.SHOWN; | ||
if (hidePopover) { | ||
// For some reason, this can result in a brief flicker when invoked | ||
// from a 'runAfter' callback, rather than directly. So make the delay | ||
// very short (25ms) so that we don't reach here often: | ||
hidePopOver(); | ||
} | ||
}, 25, TimeUnit.MILLISECONDS); | ||
} | ||
} | ||
|
||
public void hidePopOver() { | ||
hidePopover = true; | ||
|
||
if (state == PopOverState.SHOWN) { | ||
state = PopOverState.HIDING; | ||
popover.hide(); | ||
|
||
UserThread.runAfter(() -> { | ||
state = PopOverState.HIDDEN; | ||
if (!hidePopover) { | ||
showPopOver(popoverSupplier); | ||
} | ||
}, 250, TimeUnit.MILLISECONDS); | ||
} | ||
} | ||
} |