Skip to content

Commit

Permalink
Apply large padding only when image for tab item shall not be shown e…
Browse files Browse the repository at this point in the history
…clipse-platform#945

Currently, all headers in CTabFolders without an image have a large text
padding. This applies to both the case where no image is assigned to a
tab item and the case where images shall not be shown as the properties
showSelectedImage and showUnselectedImage are both false.
While the latter is intended behavior to switch between image-based tab
folders and image-less, padding-based tab folders (see eclipse-platform#785), the former
unintentionally breaks with the existing UI experience for CTabFolders
that do not use images.

This change makes the identification of whether large text padding shall
be applied explicit by factoring it out into a method (which may be
replaced by a different implementation later on). It reduces the cases
in which the large text padding is applied to the intended case
(showSelectedImage = showUnselectedImage = false) and restores the
behavior for all existing use cases.

Contributes to
eclipse-platform#945
  • Loading branch information
HeikoKlare committed Dec 19, 2023
1 parent f19db14 commit 2d095b1
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,7 @@ protected Point computeSize (int part, int state, GC gc, int wHint, int hHint) {

if (parent.showClose || item.showClose) {
if ((state & SWT.SELECTED) != 0 || parent.showUnselectedClose) {
if (((state & SWT.SELECTED) != 0 && parent.showSelectedImage)
|| ((state & SWT.SELECTED) == 0 && parent.showUnselectedImage)) {
if (showLargeTextPadding(parent)) {
if (width > 0) width += INTERNAL_SPACING;
} else {
if (width > 0) width -= INTERNAL_SPACING;
Expand All @@ -389,18 +388,21 @@ protected Point computeSize (int part, int state, GC gc, int wHint, int hHint) {
*/
private int getTextPadding(CTabItem item, int state) {
CTabFolder parent = item.getParent();
Image image = item.getImage();
String text = item.getText();

if (text != null && parent.getMinimumCharacters() != 0) {
if (image == null || image.isDisposed() || ((state & SWT.SELECTED) != 0 && !parent.showSelectedImage)
|| ((state & SWT.SELECTED) == 0 && !parent.showUnselectedImage))
if (showLargeTextPadding(parent)) {
return TABS_WITHOUT_ICONS_PADDING;
}
}

return 0;
}

private boolean showLargeTextPadding(CTabFolder tabFolder) {
return !tabFolder.showSelectedImage && !tabFolder.showUnselectedImage;
}

/**
* Given a desired <em>client area</em> for the part
* (as described by the arguments), returns the bounding
Expand Down

0 comments on commit 2d095b1

Please sign in to comment.