Skip to content

Commit

Permalink
Refine issue #199 and resizing on Linux/GTK
Browse files Browse the repository at this point in the history
For unknown reason, on Linux/GTK it triggers resize event even though
the window's size doesn't change.
This fix will check manually if there's any changes with table size or
not.

Other fix: Make sure the width of tree column is static as much as
possible unless its width is bigger than the table's width.
  • Loading branch information
laksono committed May 31, 2022
1 parent 0444657 commit ab683a6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
16 changes: 9 additions & 7 deletions edu.rice.cs.hpctree/src/edu/rice/cs/hpctree/ScopeTreeTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,11 @@ public ScopeTreeTable(Composite parent, int style, IScopeTreeData treeData) {

// Fix issue #145: do not listen to table resizing
// fix issue #199: resizing table should at least show 1 metric column
natTable.addControlListener(new ResizeListener(this));

var resizeListener = new ResizeListener(this);
natTable.addControlListener(resizeListener);
natTable.getDisplay().addFilter(SWT.MouseDown, resizeListener);
natTable.getDisplay().addFilter(SWT.MouseUp, resizeListener);

fontConfig.configureHeaderFont(natTable.getConfigRegistry());
visualRefresh();

Expand Down Expand Up @@ -434,8 +437,10 @@ public void pack() {
// - TREE_COLUMN_WIDTH,
// - the current width
// - the calculated recommended width
int w = Math.max(TREE_COLUMN_WIDTH, areaWidth-totSize);
if (w > areaWidth) {
int currentTreeColumnWdith = bodyDataLayer.getColumnWidthByPosition(0);
int recommendedWidth = areaWidth-totSize;
int w = Math.max(currentTreeColumnWdith, Math.max(TREE_COLUMN_WIDTH, recommendedWidth));
if (w >= areaWidth) {
w = areaWidth - widthFirstMetricColumn;
}
bodyDataLayer.setColumnWidthByPosition(0, w);
Expand All @@ -459,9 +464,6 @@ public void pack() {
}





private int getTableWidth() {
Rectangle area = natTable.getClientArea();
if (area.width < 10) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,32 @@ public class ResizeListener implements ControlListener, Runnable, Listener
private final ScopeTreeTable table;

private long lastEvent = 0;
private boolean mouse = true;

private boolean mouse = false;
private int lastWidth = 0;

public ResizeListener(ScopeTreeTable table) {
this.table = table;
}

@Override
public void handleEvent(Event event) {
if (event.type == SWT.MouseDown)
lastWidth = table.getTable().getSize().x;

mouse = event.type == SWT.MouseUp;
}

@Override
public void run() {
if ((lastEvent + 500) < System.currentTimeMillis() && mouse) {
// fix issue #199: at least one metric column is visible when resizing the app
table.pack();
// fix issue #199: Make sure we pack the columns only when we resize the table
// btw, due to unknown issue on SWT or Linux/GTK or both, check manually if resizing occurs
// working on SWT is highly frustrating :-(
var width = table.getTable().getSize().x;
if (width != lastWidth) {
table.pack();
lastWidth = table.getTable().getSize().x;
}
} else {
Display.getDefault().timerExec(500, this);
}
Expand Down

0 comments on commit ab683a6

Please sign in to comment.