-
Notifications
You must be signed in to change notification settings - Fork 143
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
Fix size of tab items when large text padding is used #989
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -358,17 +358,11 @@ protected Point computeSize (int part, int state, GC gc, int wHint, int hHint) { | |||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
width += getTextPadding(item, state) * 2; | ||||||||||||||||
|
||||||||||||||||
if (parent.showClose || item.showClose) { | ||||||||||||||||
if ((state & SWT.SELECTED) != 0 || parent.showUnselectedClose) { | ||||||||||||||||
if (!applyLargeTextPadding(parent)) { | ||||||||||||||||
if (width > 0) width += INTERNAL_SPACING; | ||||||||||||||||
} else { | ||||||||||||||||
if (width > 0) width -= INTERNAL_SPACING; | ||||||||||||||||
} | ||||||||||||||||
width += computeSize(PART_CLOSE_BUTTON, SWT.NONE, gc, SWT.DEFAULT, SWT.DEFAULT).x; | ||||||||||||||||
} | ||||||||||||||||
if (shouldApplyLargeTextPadding(parent)) { | ||||||||||||||||
HeikoKlare marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
width += getLargeTextPadding(item) * 2; | ||||||||||||||||
} else if (shouldDrawCloseIcon(item)) { | ||||||||||||||||
if (width > 0) width += INTERNAL_SPACING; | ||||||||||||||||
width += computeSize(PART_CLOSE_BUTTON, SWT.NONE, gc, SWT.DEFAULT, SWT.DEFAULT).x; | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
break; | ||||||||||||||||
|
@@ -379,27 +373,27 @@ protected Point computeSize (int part, int state, GC gc, int wHint, int hHint) { | |||||||||||||||
return new Point(width, height); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
private boolean shouldDrawCloseIcon(CTabItem item) { | ||||||||||||||||
CTabFolder folder = item.getParent(); | ||||||||||||||||
boolean showClose = folder.showClose || item.showClose; | ||||||||||||||||
boolean isSelectedOrShowCloseForUnselected = (item.state & SWT.SELECTED) != 0 || folder.showUnselectedClose; | ||||||||||||||||
return showClose && isSelectedOrShowCloseForUnselected; | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
/** | ||||||||||||||||
* Returns padding for the text of a tab when image is not available or is hidden. | ||||||||||||||||
* | ||||||||||||||||
* @param item CTabItem | ||||||||||||||||
* @param state current state | ||||||||||||||||
* | ||||||||||||||||
* Returns padding for the text of a tab item when showing images is disabled for the tab folder. | ||||||||||||||||
*/ | ||||||||||||||||
private int getTextPadding(CTabItem item, int state) { | ||||||||||||||||
private int getLargeTextPadding(CTabItem item) { | ||||||||||||||||
CTabFolder parent = item.getParent(); | ||||||||||||||||
String text = item.getText(); | ||||||||||||||||
|
||||||||||||||||
if (text != null && parent.getMinimumCharacters() != 0) { | ||||||||||||||||
if (applyLargeTextPadding(parent)) { | ||||||||||||||||
return TABS_WITHOUT_ICONS_PADDING; | ||||||||||||||||
} | ||||||||||||||||
return TABS_WITHOUT_ICONS_PADDING; | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
return 0; | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
private boolean applyLargeTextPadding(CTabFolder tabFolder) { | ||||||||||||||||
private boolean shouldApplyLargeTextPadding(CTabFolder tabFolder) { | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The present condition results in a large text padding only when showing images is disabled for all tabs (selected and unselected) of the tab folder.
Similarly, there is no margin or padding applied to the selected tab when only the selected tab image is set to be hidden.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's true, but that is the behavior even without the changes in this PR. And in particular, that is the behavior that has been existing for years and must not be changed. Note that #945 is also still open for this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the context of avoiding regression it makes sense to not apply this suggestion. Will evaluate this on #945 👍 |
||||||||||||||||
return !tabFolder.showSelectedImage && !tabFolder.showUnselectedImage; | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
|
@@ -1416,7 +1410,7 @@ void drawSelected(int itemIndex, GC gc, Rectangle bounds, int state ) { | |||||||||||||||
// draw Image | ||||||||||||||||
Rectangle trim = computeTrim(itemIndex, SWT.NONE, 0, 0, 0, 0); | ||||||||||||||||
int xDraw = x - trim.x; | ||||||||||||||||
if (parent.single && (parent.showClose || item.showClose)) xDraw += item.closeRect.width; | ||||||||||||||||
if (parent.single && shouldDrawCloseIcon(item)) xDraw += item.closeRect.width; | ||||||||||||||||
Image image = item.getImage(); | ||||||||||||||||
if (image != null && !image.isDisposed() && parent.showSelectedImage) { | ||||||||||||||||
Rectangle imageBounds = image.getBounds(); | ||||||||||||||||
|
@@ -1433,7 +1427,7 @@ void drawSelected(int itemIndex, GC gc, Rectangle bounds, int state ) { | |||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
// draw Text | ||||||||||||||||
xDraw += getTextPadding(item, state); | ||||||||||||||||
xDraw += getLeftTextMargin(item); | ||||||||||||||||
int textWidth = rightEdge - xDraw - (trim.width + trim.x); | ||||||||||||||||
if (!parent.single && item.closeRect.width > 0) textWidth -= item.closeRect.width + INTERNAL_SPACING; | ||||||||||||||||
if (textWidth > 0) { | ||||||||||||||||
|
@@ -1469,8 +1463,19 @@ void drawSelected(int itemIndex, GC gc, Rectangle bounds, int state ) { | |||||||||||||||
gc.setBackground(orginalBackground); | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
if (parent.showClose || item.showClose) drawClose(gc, item.closeRect, item.closeImageState); | ||||||||||||||||
if (shouldDrawCloseIcon(item)) drawClose(gc, item.closeRect, item.closeImageState); | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
private int getLeftTextMargin(CTabItem item) { | ||||||||||||||||
int margin = 0; | ||||||||||||||||
if (shouldApplyLargeTextPadding(parent)) { | ||||||||||||||||
HeikoKlare marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
margin += getLargeTextPadding(item); | ||||||||||||||||
if (shouldDrawCloseIcon(item)) { | ||||||||||||||||
margin -= item.closeRect.width / 2; | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
return margin; | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
void drawTabArea(GC gc, Rectangle bounds, int state) { | ||||||||||||||||
|
@@ -1631,7 +1636,7 @@ void drawUnselected(int index, GC gc, Rectangle bounds, int state) { | |||||||||||||||
Rectangle imageBounds = image.getBounds(); | ||||||||||||||||
// only draw image if it won't overlap with close button | ||||||||||||||||
int maxImageWidth = x + width - xDraw - (trim.width + trim.x); | ||||||||||||||||
if (parent.showUnselectedClose && (parent.showClose || item.showClose)) { | ||||||||||||||||
if (shouldDrawCloseIcon(item)) { | ||||||||||||||||
maxImageWidth -= item.closeRect.width + INTERNAL_SPACING; | ||||||||||||||||
} | ||||||||||||||||
if (imageBounds.width < maxImageWidth) { | ||||||||||||||||
|
@@ -1647,9 +1652,9 @@ void drawUnselected(int index, GC gc, Rectangle bounds, int state) { | |||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
// draw Text | ||||||||||||||||
xDraw += getTextPadding(item, state); | ||||||||||||||||
xDraw += getLeftTextMargin(item); | ||||||||||||||||
int textWidth = x + width - xDraw - (trim.width + trim.x); | ||||||||||||||||
if (parent.showUnselectedClose && (parent.showClose || item.showClose)) { | ||||||||||||||||
if (shouldDrawCloseIcon(item)) { | ||||||||||||||||
textWidth -= item.closeRect.width + INTERNAL_SPACING; | ||||||||||||||||
} | ||||||||||||||||
if (textWidth > 0) { | ||||||||||||||||
|
@@ -1667,7 +1672,7 @@ void drawUnselected(int index, GC gc, Rectangle bounds, int state) { | |||||||||||||||
gc.setFont(gcFont); | ||||||||||||||||
} | ||||||||||||||||
// draw close | ||||||||||||||||
if (parent.showUnselectedClose && (parent.showClose || item.showClose)) drawClose(gc, item.closeRect, item.closeImageState); | ||||||||||||||||
if (shouldDrawCloseIcon(item)) drawClose(gc, item.closeRect, item.closeImageState); | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
|
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 was a "dangerous" optimization as it assumes that tab items only have changed (and need some recalculation) if their size changed. That assumptions breaks with this PR.