-
Notifications
You must be signed in to change notification settings - Fork 166
Adding a recommendation for the usage of setLocation in Control #2147
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
Setting the location of the control before setting its size could cause a DPI_CHANGE event in win32 since the OS is responsible for providing the size to the control upon creation and this size can be very big, causing the control to span across multiple monitors.
Test Results 539 files - 6 539 suites - 6 41m 29s ⏱️ + 5m 55s For more details on these failures, see this check. Results for commit 200934c. ± Comparison against base commit 63048a2. This pull request removes 37 tests.
|
I'm not sure adding such recommendation in doc/spec is a good thing. This seems like documenting and specifying a bug instead of attempting to fix it. |
I don't think that a particular order is something one could expect. It would be better when the control will take care (e.g. setting the position will also update the size (again)). |
Yes, it basically points to a "bug" of how the points coordinate system in SWT works. The coordinate system is by design incapable of properly supporting monitor-specific zooms like we have implemented for Windows. To "properly" support this, one would have to either completely exchange SWT autoscaling or to revise essential parts of the API (in particular using enhanced Rectangles and Points to properly carry monitor-related information). Since this is all rather infeasible (high effort for consumers to adapt), we have instead encapsulated as much as possible in SWT. By now, this seems like doing so and falling back to heuristics in seldom cases works quite fine. Still, at some places the necessary monitor information may be lost or not available (such as recreating Points/Rectangles used for positioning shells). One such situation we have seen is eclipse-platform/eclipse.platform.ui#2948, which leads to this recommendation. Note that following the recommendation is not "crucial" but may lead to undesired effects in the UI. We can also leave it out as we are not aware of any other situations where this has caused problems so far, still it may not hurt to have it documented. |
Setting size/position of Controls is what I also don't see why order should matter here. If we detect that setting the location or size of the control is performed, one should be able to recompute maybe both values or one value base on the old/new values of the other. |
I think this actually shows the flaw in event handling I previously mentioned with using special indirection maps with callback instead of proper event handling in the control itself. That way it would be possible to inhibit a DPI change event for the time of a call, like we do on higher level elsewhere e.g. if updating viewers and so on. |
I just saw that the recommendation here is added to the documentation of
If we find a generic way of doing so properly, that would of course be fine. But you cannot just disable for it for, e.g., |
That would make it less serve, still I think we cannot enforce/recommend that really. Especially if this recommendation should "be changed in Platform repositories" it shows that it actually is not a recommendation but requirement. So we would possible need to change everything else that uses a Shell and position it! That seems not acceptable. If we really have a hard requirement here, then better one would have s
That's another issue here, the recommendation does not explain why and when it happen, and its also unclear for me, actually I would have assumed that setting the position before the size would be better, because then you know the final monitor. So something really feels flawed here and one should better describe why it fails instead of recommend something that feels like a workaround. |
Yeah, we discussed that as well. Do you remember why we dropped it, @akoch-yatta @amartya4256?
Agreed, the current formulation is definitely imprecise. The reason is that a shell is assigned to a monitor by having more than 50% of it's size on it. If
Yes, as I said, the coordinate system is by design limited to one zoom value. Extending it to monitor-specific zooms is conceptually impossible in a completely consistent way, which, you are right, can be considered a flaw. |
I think one must describe the precise conditions under when it causes an issue and if it can be detected. You wrote
So that a Shell is created can be detected quite easy (its when running the constructor). The having a boolean flag (e.g. Now assume I call
I think this is completely orthogonal here, and would be useful anyways as I assume in 90% of the time one wants to use either |
As mentioned in eclipse-platform/eclipse.platform.ui#2948 (review), setting the location of the control before setting the size could cause problems with HiDpi settings. In order to prevent that we are adding a recommendation in java doc for setLocation method of Control.
Usages as per non-recommended way to be changed in Platform repositories in separate issue: vi-eclipse/Eclipse-Platform#304