-
Notifications
You must be signed in to change notification settings - Fork 546
8372530: Easier placement of stages with positioning anchor #1986
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
base: master
Are you sure you want to change the base?
Conversation
|
👋 Welcome back mstrauss! A progress list of the required criteria for merging this PR into |
|
❗ This change is not yet ready to be integrated. |
| * | ||
| * @since 26 | ||
| */ | ||
| public static final class Anchor { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be a record too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it could, but I don't like the boolean parameter that it would expose. Boolean parameters are usually not a good idea, as they lead to "boolean blindness" at the call site. I've moved this entire class to javafx.geometry, as it might be useful for other code in the future, and I don't want to proliferate two nested versions of an anchor point (one in Stage, the other in PopupWindow).
| 0, 0); | ||
| } | ||
|
|
||
| // Give subclasses a chance to adjust the window bounds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated to this Enhancement, but I wonder if the centerOnScreen line before could also be rewritten using this system (at one point). Now, it looks like he might be centering the Window, and then fix the bounds to something else, wasting some time.
| * @throws NullPointerException if {@code anchor} is {@code null} | ||
| * @since 26 | ||
| */ | ||
| public final void show(double anchorX, double anchorY, AnchorPoint anchor) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it make more sense to move these new methods to Window, so they can also work for the Popup and its hierarchy ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PopupWindow works differently, it has a anchorLocation property which is a bit limited. We also couldn't move PopupWindow.AnchorLocation anywhere else (as this would be a breaking change), which would make the signature of the show() method very awkward: On Stage.show(x, y, PopupWindow.AnchorLocation) you'd have a parameter that is declared on an unrelated class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is unfortunate.
Can we do anything to make the positioning of Popups and its hierarchy easier? Maybe add another show() with a ClampPolicy argument?
Use case: I want to open a PopupWindow below the owner node, but: if the popup cannot be placed there because the whole thing is too close to the bottom of the screen, I want the popup to be above the node, and not on top of it as it works currently.
| * | ||
| * @since 26 | ||
| */ | ||
| public enum ClampPolicy { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe call it RelocationPolicy?
This enhancement allows
Stageto be placed on the screen similar to a popup window, where a user-specified positioning anchor defines a point on the stage that should coincide with a given location on the screen. For this purpose, the following new methods are added toStage:AnchorPointis a point that is either specified in absolute coordinates, or relative to the stage:For example, a stage that sits flush with the bottom-right corner of the screen can be shown as follows:
The position of the stage is automatically adjusted (depending on
ClampPolicy) so that it doesn't extend beyond the edges of the screen; this is similar to howPopupWindowwithautoFixworks. This feature is mainly intended for stages that are positioned relative to a reference point, for example windows that are invoked from the system tray. These windows are top-level windows, but they are positioned like a popup window.ClampPolicycan be eitherNONE,HORIZONTAL,VERTICAL, orBOTH.When clamping is used, the
screenPaddingparameter specifies how much space should be mainainted beween the edges of the window and the edges of the screen.Progress
Issue
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jfx.git pull/1986/head:pull/1986$ git checkout pull/1986Update a local copy of the PR:
$ git checkout pull/1986$ git pull https://git.openjdk.org/jfx.git pull/1986/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 1986View PR using the GUI difftool:
$ git pr show -t 1986Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jfx/pull/1986.diff