Skip to content
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

8252236: TabPane: must keep header of selected tab visible #300

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter
Filter file types
Jump to
Jump to file
Failed to load files.

Always

Just for now

@@ -152,7 +152,6 @@
private Rectangle clipRect;
private Rectangle tabHeaderAreaClipRect;
private Tab selectedTab;
private boolean isSelectingTab;

private final TabPaneBehavior behavior;

@@ -200,8 +199,14 @@ public TabPaneSkin(TabPane control) {

registerChangeListener(control.selectionModelProperty(), e -> updateSelectionModel());
registerChangeListener(control.sideProperty(), e -> updateTabPosition());
registerChangeListener(control.widthProperty(), e -> clipRect.setWidth(getSkinnable().getWidth()));
registerChangeListener(control.heightProperty(), e -> clipRect.setHeight(getSkinnable().getHeight()));
registerChangeListener(control.widthProperty(), e -> {
tabHeaderArea.invalidateScrollOffset();
clipRect.setWidth(getSkinnable().getWidth());
});
registerChangeListener(control.heightProperty(), e -> {
tabHeaderArea.invalidateScrollOffset();
clipRect.setHeight(getSkinnable().getHeight());
});

selectedTab = getSkinnable().getSelectionModel().getSelectedItem();
// Could not find the selected tab try and get the selected tab using the selected index
@@ -214,7 +219,6 @@ public TabPaneSkin(TabPane control) {
getSkinnable().getSelectionModel().selectFirst();
}
selectedTab = getSkinnable().getSelectionModel().getSelectedItem();
isSelectingTab = false;

initializeSwipeHandlers();
}
@@ -432,7 +436,7 @@ public TabPaneSkin(TabPane control) {

private SelectionModel<Tab> selectionModel;
private InvalidationListener selectionChangeListener = observable -> {
isSelectingTab = true;
tabHeaderArea.invalidateScrollOffset();
selectedTab = getSkinnable().getSelectionModel().getSelectedItem();
getSkinnable().requestLayout();
};
@@ -678,7 +682,7 @@ private void removeTabContent(Tab tab) {
}

private void updateTabPosition() {
tabHeaderArea.setScrollOffset(0.0F);
tabHeaderArea.invalidateScrollOffset();
getSkinnable().applyCss();
getSkinnable().requestLayout();
}
@@ -809,6 +813,7 @@ private boolean isFloatingStyleClass() {
private boolean measureClosingTabs = false;

private double scrollOffset;
private boolean scrollOffsetDirty = true;

public TabHeaderArea() {
getStyleClass().setAll("tab-header-area");
@@ -842,13 +847,13 @@ public TabHeaderArea() {
if (tabsFit()) {
setScrollOffset(0.0);
} else {
if (isSelectingTab) {
if (scrollOffsetDirty) {
ensureSelectedTabIsVisible();
} else {
validateScrollOffset();
scrollOffsetDirty = false;
}
// ensure there's no gap between last visible tab and trailing edge
validateScrollOffset();
}
isSelectingTab = false;

Side tabPosition = getSkinnable().getSide();
double tabBackgroundHeight = snapSize(prefHeight(-1));
@@ -981,20 +986,23 @@ private void updateHeaderClip() {
private void addTab(Tab tab, int addToIndex) {
TabHeaderSkin tabHeaderSkin = new TabHeaderSkin(tab);
headersRegion.getChildren().add(addToIndex, tabHeaderSkin);
invalidateScrollOffset();
}

private void removeTab(Tab tab) {
TabHeaderSkin tabHeaderSkin = getTabHeaderSkin(tab);
if (tabHeaderSkin != null) {
headersRegion.getChildren().remove(tabHeaderSkin);
}
invalidateScrollOffset();
}

private void moveTab(int moveToIndex, TabHeaderSkin tabHeaderSkin) {
if (moveToIndex != headersRegion.getChildren().indexOf(tabHeaderSkin)) {
headersRegion.getChildren().remove(tabHeaderSkin);
headersRegion.getChildren().add(moveToIndex, tabHeaderSkin);
}
invalidateScrollOffset();
}

private TabHeaderSkin getTabHeaderSkin(Tab tab) {
@@ -1053,6 +1061,10 @@ public double getScrollOffset() {
return scrollOffset;
}

public void invalidateScrollOffset() {
scrollOffsetDirty = true;
}

private void validateScrollOffset() {
setScrollOffset(getScrollOffset());
}
@@ -2241,6 +2253,7 @@ private void stopDrag() {
dragHeaderTransitionX = dragHeaderDestX - dragHeaderSourceX;
dragHeaderAnim.playFromStart();
}
tabHeaderArea.invalidateScrollOffset();
}

private void reorderTabs() {
@@ -2294,4 +2307,16 @@ void test_disableAnimations() {
closeTabAnimation.set(TabAnimation.NONE);
openTabAnimation.set(TabAnimation.NONE);
}

double test_getHeaderAreaScrollOffset() {
return tabHeaderArea.getScrollOffset();
}

void test_setHeaderAreaScrollOffset(double offset) {
tabHeaderArea.setScrollOffset(offset);
}

boolean test_isTabsFit() {
return tabHeaderArea.tabsFit();
}
}
@@ -46,4 +46,20 @@ public static void disableAnimations(TabPaneSkin tpSkin) {
StackPane headersRegion = (StackPane) tabPane.lookup(".headers-region");
return headersRegion.getChildren();
}

public static double getHeaderAreaScrollOffset(TabPane tabPane) {
TabPaneSkin skin = (TabPaneSkin) tabPane.getSkin();
return skin.test_getHeaderAreaScrollOffset();
}

public static void setHeaderAreaScrollOffset(TabPane tabPane, double offset) {
TabPaneSkin skin = (TabPaneSkin) tabPane.getSkin();
skin.test_setHeaderAreaScrollOffset(offset);
}

public static boolean isTabsFit(TabPane tabPane) {
TabPaneSkin skin = (TabPaneSkin) tabPane.getSkin();
return skin.test_isTabsFit();
}

}
ProTip! Use n and p to navigate between commits in a pull request.