Skip to content

Commit

Permalink
fix: Popup can switch more flexible.
Browse files Browse the repository at this point in the history
  • Loading branch information
teletha committed Oct 3, 2023
1 parent 38a1f07 commit 356dbce
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/main/java/viewtify/ui/helper/ReferenceHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ static final synchronized PopOver popover() {
if (popover == null) {
popover = new PopOver();
popover.setDetachable(false);
popover.setOnHidden(e -> popover.setContentNode(null));
}
return popover;
}
Expand Down
26 changes: 23 additions & 3 deletions src/main/java/viewtify/ui/helper/TooltipHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import org.controlsfx.control.PopOver;

import javafx.application.Platform;
import javafx.geometry.Bounds;
import javafx.scene.Node;
import javafx.scene.control.Tooltip;
Expand Down Expand Up @@ -102,16 +103,35 @@ default Self popup(Supplier<UserInterfaceProvider<Node>> builder) {
PopOver p = ReferenceHolder.popover();

if (p.isShowing()) {
p.hide();
if (p.getUserData() == ui()) {
p.hide();
p.setUserData(null);
} else {
p.setOnHidden(e -> show(builder, p));
}
} else {
p.setContentNode(builder.get().ui());
p.show(ui());
show(builder, p);
}
});
}
return (Self) this;
}

/**
* Show popup.
*
* @param builder Create the contents. This callback will be invoked every showing the popup.
* @param popup A singleton popup widget.
*/
private void show(Supplier<UserInterfaceProvider<Node>> builder, PopOver popup) {
Platform.runLater(() -> {
popup.setContentNode(builder.get().ui());
popup.show(ui());
popup.setUserData(ui());
popup.setOnHidden(x -> popup.setContentNode(null));
});
}

/**
* Close the current popup window.
*/
Expand Down

0 comments on commit 356dbce

Please sign in to comment.