Skip to content

Commit

Permalink
Fixed out of bounds exception when switch between TabView and another…
Browse files Browse the repository at this point in the history
… navigation type
  • Loading branch information
tomcashman committed Sep 15, 2018
1 parent f0e4e1d commit ec10827
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[1.7.13-SNAPSHOT]
- Fixed out of bounds exception when switch between TabView and another navigation type

[1.7.12]
- Added IntTreeMap implementation
Expand Down
10 changes: 6 additions & 4 deletions ui/src/main/java/org/mini2Dx/ui/element/TabView.java
Original file line number Diff line number Diff line change
Expand Up @@ -424,10 +424,7 @@ public void setZIndex(int zIndex) {
* @return Null if no {@link Tab} is visible
*/
public Tab getCurrentTab() {
if (currentTabIndex >= tabs.size()) {
return null;
}
return tabs.get(currentTabIndex);
return tabs.get(getCurrentTabIndex());
}

/**
Expand All @@ -452,6 +449,11 @@ public void setCurrentTab(Tab tab) {
* @return 0 by default
*/
public int getCurrentTabIndex() {
if(currentTabIndex < 0) {
currentTabIndex = 0;
} else if(currentTabIndex >= tabs.size()) {
currentTabIndex = 0;
}
return currentTabIndex;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public void layout(ScreenSize screenSize) {

@Override
public Actionable getCursor() {
if(tabs.isEmpty()) {
return null;
}
UiNavigation navigation = tabs.get(tabView.getCurrentTabIndex()).getNavigation();
if(navigation == null) {
return null;
Expand All @@ -45,6 +48,9 @@ public Actionable getCursor() {

@Override
public Actionable resetCursor() {
if(tabs.isEmpty()) {
return null;
}
UiNavigation navigation = tabs.get(tabView.getCurrentTabIndex()).getNavigation();
if(navigation == null) {
return null;
Expand Down Expand Up @@ -74,6 +80,9 @@ public void set(int index, Actionable actionable) {

@Override
public Actionable navigate(int keycode) {
if(tabs.isEmpty()) {
return null;
}
UiNavigation navigation = tabs.get(tabView.getCurrentTabIndex()).getNavigation();
if(navigation == null) {
return null;
Expand Down

0 comments on commit ec10827

Please sign in to comment.