mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 20:58:03 +00:00
Improve handling of submenus
This commit is contained in:
@@ -57,6 +57,7 @@ public abstract class FDropDown extends FScrollPane {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVisible(boolean visible0) {
|
||||
if (this.isVisible() == visible0) { return; }
|
||||
|
||||
@@ -144,12 +145,13 @@ public abstract class FDropDown extends FScrollPane {
|
||||
|
||||
@Override
|
||||
public boolean tap(float x, float y, int count) {
|
||||
FDisplayObject owner = getDropDownOwner();
|
||||
if (owner != null && owner.contains(owner.getLeft() + owner.screenToLocalX(x), owner.getTop() + owner.screenToLocalY(y))) {
|
||||
hide(); //auto-hide when owner tapped
|
||||
return true; //prevent owner handling this tap
|
||||
hide(); //always hide if tapped
|
||||
|
||||
//prevent owner handling this tap unless it's a sub menu
|
||||
if (getDropDownOwner() instanceof FSubMenu) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -64,6 +64,9 @@ public abstract class FDropDownMenu extends FDropDown {
|
||||
@Override
|
||||
public boolean tap(float x, float y, int count) {
|
||||
hide(); //hide when item tapped
|
||||
if (getDropDownOwner() instanceof FSubMenu) {
|
||||
return false; //return false so owning sub menu can be hidden
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,32 @@
|
||||
package forge.menu;
|
||||
|
||||
import forge.assets.FImage;
|
||||
import forge.toolbox.FEvent;
|
||||
import forge.toolbox.FEvent.FEventHandler;
|
||||
|
||||
public class FSubMenu extends FMenuItem {
|
||||
public FSubMenu(String text0, FPopupMenu popupMenu) {
|
||||
this(text0, null, popupMenu, true);
|
||||
FPopupMenu popupMenu;
|
||||
|
||||
public FSubMenu(String text0, FPopupMenu popupMenu0) {
|
||||
this(text0, null, popupMenu0, true);
|
||||
}
|
||||
public FSubMenu(String text0, FPopupMenu popupMenu, boolean enabled0) {
|
||||
this(text0, null, popupMenu, enabled0);
|
||||
public FSubMenu(String text0, FPopupMenu popupMenu0, boolean enabled0) {
|
||||
this(text0, null, popupMenu0, enabled0);
|
||||
}
|
||||
public FSubMenu(String text0, FImage icon0, final FPopupMenu popupMenu) {
|
||||
this(text0, icon0, popupMenu, true);
|
||||
public FSubMenu(String text0, FImage icon0, final FPopupMenu popupMenu0) {
|
||||
this(text0, icon0, popupMenu0, true);
|
||||
}
|
||||
public FSubMenu(String text0, FImage icon0, final FPopupMenu popupMenu, boolean enabled0) {
|
||||
super(text0, icon0, new FEventHandler() {
|
||||
@Override
|
||||
public void handleEvent(FEvent e) {
|
||||
popupMenu.show(e.getSource(), e.getSource().getWidth(), 0);
|
||||
}
|
||||
}, enabled0);
|
||||
public FSubMenu(String text0, FImage icon0, final FPopupMenu popupMenu0, boolean enabled0) {
|
||||
super(text0, icon0, null, enabled0);
|
||||
popupMenu = popupMenu0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean tap(float x, float y, int count) {
|
||||
if (popupMenu.isVisible()) {
|
||||
popupMenu.hide();
|
||||
}
|
||||
else {
|
||||
popupMenu.show(this, getWidth(), 0);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user