-
Notifications
You must be signed in to change notification settings - Fork 177
Fix label cutoff #2381
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?
Fix label cutoff #2381
Conversation
e48df64
to
4e2fcda
Compare
This commit contributes to enable GridLayout:layout to utilize Point.OfFloat in GridData to calculate precise size on scaling. contributes to eclipse-platform#2166
This commit adapts Label to return Point.OfFloat object on Label:computeSizeInPixels ultimately returning Point.OfFloat on calling Label:computeSize. This allows precise scaling of Label by its parents. contributes to eclipse-platform#2166
4e2fcda
to
fc7dedf
Compare
cacheWidth = cacheHeight = -1; | ||
defaultWidth = defaultHeight = -1; | ||
currentWidth = currentHeight = -1; | ||
cacheSize = new Point.OfFloat(-1, -1); |
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.
cacheSize = new Point.OfFloat(-1, -1); | |
cacheSize = new Point.OfFloat(SWT.DEFAULT, SWT.DEFAULT); |
@@ -487,34 +489,28 @@ public GridData (int width, int height) { | |||
} | |||
|
|||
void computeSize (Control control, int wHint, int hHint, boolean flushCache) { | |||
if (cacheWidth != -1 && cacheHeight != -1) return; | |||
if (cacheSize.x != -1 && cacheSize.y != -1) return; |
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.
I think the -1 in all comparisons in this function should be replaced with SWT.DEFAULT
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.
Another option I think is cleaner is to have
public static final OfFloat UNDEFINED = new OfFloat(-1f, -1f);
in the point class so comparisons could be
cacheSize == Point.OfFloat.UNDEFINED;
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.
We cannot set UNDEFINED = new OfFloat(-1f, -1f) since -1, -1 can also represent a point in the coordinate system and it's only valid for cacheSize in the case of Grid data. Hence, that should be handled in GridData. I like the idea of checking with SWT.DEFAULT.
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.
One general question on this: wouldn't it possible or even reasonable to stick to width/height values inside GridData
but just make them floats and only use Point.OfFloat
for the returns of API methods?
Two reasons for this:
- SWT is generally lacking some
Size
object and, unfortunately, at many placesPoint
is used to represent a size (even though that semantically does not make that much sense). Thus, we usually try to stick towidth
/height
when considering sizes. - It would be less error prone as now if you accidentally use, e.g.,
size.x
instead ofsize.getX()
, you may calculate with a wrong value.
I agree, I'll make the changes. |
@@ -705,7 +712,7 @@ Point layout (Composite composite, boolean move, int x, int y, int width, int he | |||
|
|||
// clean up cache | |||
for (int i = 0; i < flushLength; i++) { | |||
flush [i].cacheWidth = flush [i].cacheHeight = -1; | |||
flush [i].cacheSize = new Point.OfFloat(SWT.DEFAULT, SWT.DEFAULT); |
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 be ok to simply change the existing point instead of creating a new one?
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.
I mean: to avoid unnecessary object creation. I assume that layout
is called pretty often?
This PR contributes to precise scaling of computation of size inside gridLayout by using float precision. This fixes the issue reported in #2166
How to test
Before:

After:
