-
Notifications
You must be signed in to change notification settings - Fork 187
Remove the SORT_WIDTH spacing logic in Table column rendering. #2477
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
Conversation
BeckerWdf
left a comment
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 did a code review. Changes look good to me.
As I am on macOS I cannot test these changes.
f3f6fe5 to
3e05faa
Compare
Since Windows 7, the sort indicator in tree columns is rendered above the column header text, whereas in Windows XP it was placed next to the text. The original SWT implementation added extra pixels (SORT_WIDTH) to the column width to make space for the indicator.
3e05faa to
f9ea6d7
Compare
|
Have tested the changes with a table with image the changes look good |
fedejeanne
left a comment
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.
Same as with #2476 (see #2476 (comment)), the image in the column gets lost when the column is selected. I know this PR didn't introduce this behavior (bug?) but I'd like to point it out anyway.
Since I can see that you didn't remove/ignore any instance Image in this PR, I am approving it and merging it, but please keep in mind my comment about preserving the image in the other PR and, if necessary, create a follow-up issue for Table too.
By the way, I tested your changes with a slight adaptation of Arun's snippet:
TableColumnImageHeaderExample (Code)
package org.eclipse.swt.snippets;
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
public class TableColumnImageHeaderExample {
public static void main(String[] args) {
final Display display = new Display();
System.setProperty("swt.autoScale", "quarter");
System.setProperty("swt.autoScale.updateOnRuntime", "true");
Shell shell = new Shell(display);
shell.setText("Table with Images in Header");
shell.setLayout(new FillLayout());
final Table table = new Table(shell, SWT.MULTI | SWT.FULL_SELECTION);
table.setHeaderVisible(true);
table.setLinesVisible(true);
int columnCount = 4;
Image[] headerImages = new Image[columnCount];
// Load sample images (replace with your own image paths)
for (int i = 0; i < columnCount; i++) {
headerImages[i] = new Image(display, 16, 16); // Placeholder blank image
GC gc = new GC(headerImages[i]);
System.out.println("image[" + i + "]=" + headerImages[i]);
gc.setBackground(display.getSystemColor(SWT.COLOR_BLUE));
gc.fillRectangle(0, 0, 16, 16); // Simple colored square as image
gc.dispose();
}
// Create columns with text and images
for (int i = 0; i < columnCount; i++) {
TableColumn column = new TableColumn(table, SWT.NONE);
column.setText("Column " + i);
column.setImage(headerImages[i]);
}
// Populate tree items
int itemCount = 3;
for (int i = 0; i < itemCount; i++) {
TableItem item1 = new TableItem(table, SWT.NONE);
item1.setText("item " + i);
for (int c = 1; c < columnCount; c++) {
item1.setText(c, "item [" + i + "-" + c + "]");
}
}
// Optional: Custom selection gradient (kept from your original snippet)
table.addListener(SWT.EraseItem, event -> {
event.detail &= ~SWT.HOT;
if ((event.detail & SWT.SELECTED) != 0) {
GC gc = event.gc;
Rectangle rect = event.getBounds();
Color foreground = gc.getForeground();
Color background = gc.getBackground();
gc.setForeground(display.getSystemColor(SWT.COLOR_RED));
gc.setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND));
gc.fillGradientRectangle(0, rect.y, 500, rect.height, false);
gc.setForeground(foreground);
gc.setBackground(background);
event.detail &= ~SWT.SELECTED;
}
});
table.setSortColumn(table.getColumn(2));
table.setSortColumn(table.getColumn(1));
table.setSortDirection(SWT.UP);
for (int i = 0; i < columnCount; i++) {
table.getColumn(i).pack();
}
table.setSelection(table.getItem(0));
shell.setSize(500, 200);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
// Dispose images to avoid memory leaks
for (Image img : headerImages) {
img.dispose();
}
display.dispose();
}
}
Since Windows 7, the sort indicator in tree columns is rendered above the column header text, whereas in Windows XP it was placed next to the text. The original SWT implementation added extra pixels (SORT_WIDTH) to the column width to make space for the indicator.