Skip to content

Commit

Permalink
Improve submenu postion choosing, close #220
Browse files Browse the repository at this point in the history
  • Loading branch information
kotcrab committed Oct 3, 2016
1 parent 8d2c754 commit faa6765
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions ui/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#### Version: 1.2.4-SNAPSHOT (LibGDX 1.9.4)
- **Fixed**: `Spinner.TextFieldEventPolicy` is now public (was package-private)
- **Improved**: [#220](https://github.com/kotcrab/vis-editor/issues/220) when sub menu can't fit on the right side of parent menu, it will be shown on the side that has more available space (before in such case it was always shown on the left side)

#### Version: 1.2.3 (LibGDX 1.9.4)
- **Added**: constructor `LinkLabel (CharSequence text, CharSequence url, LinkLabelStyle style)`
Expand Down
10 changes: 7 additions & 3 deletions ui/src/main/java/com/kotcrab/vis/ui/widget/MenuItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,16 @@ void showSubMenu () {
Stage stage = getStage();
Vector2 pos = localToStageCoordinates(tmpVector.setZero());

float availableSpaceLeft = pos.x;
float availableSpaceRight = stage.getWidth() - (pos.x + getWidth());
boolean canFitOnTheRight = pos.x + getWidth() + subMenu.getWidth() <= stage.getWidth();
float subMenuX;
if (pos.x + getWidth() + subMenu.getWidth() >= stage.getWidth()) { //if won't fit on screen
subMenuX = pos.x - subMenu.getWidth() + 1;
} else {
if (canFitOnTheRight || availableSpaceRight > availableSpaceLeft) {
subMenuX = pos.x + getWidth() - 1;
} else {
subMenuX = pos.x - subMenu.getWidth() + 1;
}

subMenu.setPosition(subMenuX, pos.y - subMenu.getHeight() + getHeight());

if (subMenu.getY() < 0) {
Expand Down

0 comments on commit faa6765

Please sign in to comment.