Skip to content

Commit

Permalink
Give assembler tabs a bit of default size instead of auto-sizing to b…
Browse files Browse the repository at this point in the history
…e empty
  • Loading branch information
Col-E committed Jan 9, 2024
1 parent 5cf0b94 commit 2311c0a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ public class SideTabs extends BorderPane implements UpdatableNavigable {
private static final PseudoClass PSEUDO_VERTICAL = PseudoClass.getPseudoClass("vertical");
private final ObservableList<Tab> tabs = FXCollections.observableArrayList();
private final ObservableObject<Tab> selectedTab = new ObservableObject<>(null);
private final DoubleProperty initialSize = new SimpleDoubleProperty();
private final Pane tabContainer;
private final ResizeGrip grip;
private final DoubleProperty prefSize;
private double lastSize;
private boolean sizeIsBound;
private PathNode<?> path;
Expand Down Expand Up @@ -104,15 +107,17 @@ public SideTabs(@Nonnull Orientation orientation) {
ResizeGrip grip;
if (orientation == Orientation.VERTICAL) {
prefSize = prefWidthProperty();
grip = new ResizeGrip(orientation, this::getWidth,
grip = new ResizeGrip(initialSize, orientation, this::getWidth,
size -> prefSize.bind(size.map((Function<Number, Number>)
number -> lastSize = Math.min(number.doubleValue(), getMaxWidth()))));
} else {
prefSize = prefHeightProperty();
grip = new ResizeGrip(orientation, this::getHeight,
grip = new ResizeGrip(initialSize, orientation, this::getHeight,
size -> prefSize.bind(size.map((Function<Number, Number>)
number -> lastSize = Math.min(number.doubleValue(), getMaxHeight()))));
}
this.grip = grip;
this.prefSize = prefSize;


// When the selected tab changes display the selected one's content, clear content if no selection.
Expand Down Expand Up @@ -143,10 +148,13 @@ public SideTabs(@Nonnull Orientation orientation) {
// restore the prior size.
BorderPane wrapper = new BorderPane(cur.getContent());
wrapper.getStyleClass().add("side-tab-content");
if (orientation == Orientation.VERTICAL)
if (orientation == Orientation.VERTICAL) {
wrapper.setLeft(grip);
else
wrapper.setPrefWidth(lastSize);
} else {
wrapper.setTop(grip);
wrapper.setPrefHeight(lastSize);
}
setCenter(wrapper);
}
}
Expand Down Expand Up @@ -175,6 +183,19 @@ public ObservableList<Tab> getTabs() {
return tabs;
}


/**
* Sets the size of content that will be shown when a tab is selected.
* By default, the tab content auto-sizes to the content shown.
* In some cases when the auto-size is 0 you may want to use this.
*
* @param initialSize
* Initial size of the tab content.
*/
public void setInitialSize(double initialSize) {
this.initialSize.setValue(initialSize);
}

@Nonnull
@Override
public PathNode<?> getPath() {
Expand Down Expand Up @@ -269,6 +290,8 @@ private static class ResizeGrip extends BorderPane {
private final SimpleDoubleProperty targetSize = new SimpleDoubleProperty();

/**
* @param initialSize
* Initial desired size of the side-tab content.
* @param orientation
* Parent side-tabs orientation.
* @param sizeLookup
Expand All @@ -277,7 +300,8 @@ private static class ResizeGrip extends BorderPane {
* Consumer to take in the desired new size, wrapped in a {@link DoubleProperty} in order to
* support mapping operations.
*/
private ResizeGrip(@Nonnull Orientation orientation,
private ResizeGrip(@Nonnull DoubleProperty initialSize,
@Nonnull Orientation orientation,
@Nonnull DoubleSupplier sizeLookup,
@Nonnull Consumer<DoubleProperty> consumer) {
AtomicInteger startPos = new AtomicInteger();
Expand Down Expand Up @@ -323,7 +347,7 @@ private ResizeGrip(@Nonnull Orientation orientation,

// Trigger call to consumer once with existing parent width once initially added to the UI.
NodeEvents.runOnceOnChange(parentProperty(), parent -> {
targetSize.set(sizeLookup.getAsDouble());
targetSize.set(Math.max(sizeLookup.getAsDouble(), initialSize.doubleValue()));
consumer.accept(targetSize);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public AssemblerToolTabs(@Nonnull Instance<JvmStackAnalysisPane> jvmStackAnalysi
@Nonnull Instance<JvmVariablesPane> jvmVariablesPaneProvider) {
this.jvmStackAnalysisPaneProvider = jvmStackAnalysisPaneProvider;
this.jvmVariablesPaneProvider = jvmVariablesPaneProvider;

// Without an initial size, the first frame of a method has nothing in it. So the auto-size to fit content
// has nothing to fit to, which leads to only table headers being visible. Looks really dumb so giving it
// a little bit of default space regardless mostly solves that.
tabs.setInitialSize(200);
}

/**
Expand Down

0 comments on commit 2311c0a

Please sign in to comment.