Skip to content

Commit

Permalink
Fix quirks with the movable tabs.
Browse files Browse the repository at this point in the history
Especially around minimize/maximize behaviour. Now using our own
layout logic for finer control.
  • Loading branch information
pmuetschard committed Sep 20, 2017
1 parent 0c59ecb commit c63dbf5
Show file tree
Hide file tree
Showing 5 changed files with 401 additions and 177 deletions.
8 changes: 4 additions & 4 deletions gapic/src/main/com/google/gapid/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public FolderInfo[] restore() {
});
tabs.setLeftVisible(!models().settings.hideLeft);
tabs.setRightVisible(!models().settings.hideRight);
return tabs.getControl();
return tabs;
}
};
splitter.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
Expand Down Expand Up @@ -489,7 +489,7 @@ public static FolderInfo[] getFolders(
}
}

int[] weights = models.settings.tabWeights;
double[] weights = models.settings.tabWeights;
return new FolderInfo[] {
new FolderInfo(false, left.toArray(new TabInfo[left.size()]), weights[0]),
new FolderInfo(false, center.toArray(new TabInfo[center.size()]), weights[1]),
Expand All @@ -508,8 +508,8 @@ private static String[] getNames(TabInfo[] tabs) {
return Arrays.stream(tabs).map(tab -> ((Type)tab.id).name()).toArray(len -> new String[len]);
}

private static int[] getWeights(FolderInfo[] folders) {
return new int[] { folders[0].weight, folders[1].weight, folders[2].weight };
private static double[] getWeights(FolderInfo[] folders) {
return new double[] { folders[0].weight, folders[1].weight, folders[2].weight };
}

private static List<TabInfo> getTabs(
Expand Down
25 changes: 22 additions & 3 deletions gapic/src/main/com/google/gapid/models/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class Settings {
public int splitterTopHeight = 200;
public String[] leftTabs = new String[0], centerTabs = new String[0], rightTabs = new String[0];
public String[] hiddenTabs = new String[] { "Log" };
public int[] tabWeights = new int[] { 20, 60, 20 };
public double[] tabWeights = new double[] { 0.2, 0.6, 0.2 };
public String lastOpenDir = "";
public int[] reportSplitterWeights = new int[] { 75, 25 };
public int[] shaderSplitterWeights = new int[] { 70, 30 };
Expand Down Expand Up @@ -150,7 +150,7 @@ private void updateFrom(Properties properties) {
centerTabs = getStringList(properties, "tabs.center", centerTabs);
rightTabs = getStringList(properties, "tabs.right", rightTabs);
hiddenTabs = getStringList(properties, "tabs.hidden", hiddenTabs);
tabWeights = getIntList(properties, "tabs.weights", tabWeights);
tabWeights = getDoubleList(properties, "tabs.weights", tabWeights);
lastOpenDir = properties.getProperty("lastOpenDir", lastOpenDir);
reportSplitterWeights =
getIntList(properties, "report.splitter.weights", reportSplitterWeights);
Expand Down Expand Up @@ -188,7 +188,7 @@ private void updateTo(Properties properties) {
setStringList(properties, "tabs.center", centerTabs);
setStringList(properties, "tabs.right", rightTabs);
setStringList(properties, "tabs.hidden", hiddenTabs);
setIntList(properties, "tabs.weights", tabWeights);
setDoubleList(properties, "tabs.weights", tabWeights);
properties.setProperty("lastOpenDir", lastOpenDir);
setIntList(properties, "report.splitter.weights", reportSplitterWeights);
setIntList(properties, "shader.splitter.weights", shaderSplitterWeights);
Expand Down Expand Up @@ -265,6 +265,21 @@ private static int[] getIntList(Properties properties, String name, int[] dflt)
}
}

private static double[] getDoubleList(Properties properties, String name, double[] dflt) {
String value = properties.getProperty(name);
if (value == null) {
return dflt;
}

try {
return stream(Splitter.on(',').split(value).spliterator(), false)
.mapToDouble(Double::parseDouble).toArray();
} catch (NumberFormatException e) {
return dflt;
}
}


private static String[] getStringList(Properties properties, String name, String[] dflt) {
String value = properties.getProperty(name);
if (value == null) {
Expand All @@ -286,6 +301,10 @@ private static void setIntList(Properties properties, String name, int[] value)
properties.setProperty(name, stream(value).mapToObj(String::valueOf).collect(joining(",")));
}

private static void setDoubleList(Properties properties, String name, double[] value) {
properties.setProperty(name, stream(value).mapToObj(String::valueOf).collect(joining(",")));
}

private static void setStringList(Properties properties, String name, String[] value) {
properties.setProperty(name, stream(value).collect(joining(",")));
}
Expand Down
32 changes: 32 additions & 0 deletions gapic/src/main/com/google/gapid/util/GeoUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,36 @@ public static Point bottomLeft(Rectangle r) {
public static Point bottomRight(Rectangle r) {
return new Point(r.x + r.width, r.y + r.height);
}

public static Rectangle withX(Rectangle r, int x) {
r.x = x;
return r;
}

public static Rectangle withXW(Rectangle r, int x, int width) {
r.x = x;
r.width = width;
return r;
}

public static Rectangle withXH(Rectangle r, int x, int height) {
r.x = x;
r.height = height;
return r;
}

public static Rectangle withY(Rectangle r, int y) {
r.y = y;
return r;
}

public static Rectangle withW(Rectangle r, int width) {
r.width = width;
return r;
}

public static Rectangle withH(Rectangle r, int height) {
r.height = height;
return r;
}
}
8 changes: 5 additions & 3 deletions gapic/src/main/com/google/gapid/widgets/FixedTopSplitter.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import org.eclipse.swt.widgets.Sash;

public abstract class FixedTopSplitter extends Composite {
private static final int MIN_SIZE = 30;

private final Control top, bottom;
private final Sash sash;

Expand All @@ -43,9 +45,9 @@ public FixedTopSplitter(Composite parent, int topHeight) {
sash.addListener(SWT.Selection, e -> {
Rectangle size = getClientArea();
Rectangle sashSize = sash.getBounds();
int y = Math.min(e.y, size.height - sashSize.height);
if (y != sashSize.y) {
((FormData)sash.getLayoutData()).top = new FormAttachment(0, y);
e.y = Math.max(MIN_SIZE, Math.min(size.height - sashSize.height - MIN_SIZE, e.y));
if (e.y != sashSize.y) {
((FormData)sash.getLayoutData()).top = new FormAttachment(0, e.y);
layout();
}
});
Expand Down
Loading

0 comments on commit c63dbf5

Please sign in to comment.