From: Kevin Lamonte Date: Tue, 22 Aug 2017 23:38:18 +0000 (-0400) Subject: Fix mouse on menu line X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=159f076db8ec60010cdf87b1164a875d51875dd4;p=fanfix-jexer.git Fix mouse on menu line --- diff --git a/src/jexer/TApplication.java b/src/jexer/TApplication.java index 3d93e56..abd69ca 100644 --- a/src/jexer/TApplication.java +++ b/src/jexer/TApplication.java @@ -2009,8 +2009,8 @@ public class TApplication implements Runnable { // They selected the menu, go activate it for (TMenu menu: menus) { - if ((mouse.getAbsoluteX() >= menu.getX()) - && (mouse.getAbsoluteX() < menu.getX() + if ((mouse.getAbsoluteX() >= menu.getTitleX()) + && (mouse.getAbsoluteX() < menu.getTitleX() + menu.getTitle().length() + 2) ) { menu.setActive(true); @@ -2037,8 +2037,8 @@ public class TApplication implements Runnable { // See if we should switch menus for (TMenu menu: menus) { - if ((mouse.getAbsoluteX() >= menu.getX()) - && (mouse.getAbsoluteX() < menu.getX() + if ((mouse.getAbsoluteX() >= menu.getTitleX()) + && (mouse.getAbsoluteX() < menu.getTitleX() + menu.getTitle().length() + 2) ) { menu.setActive(true); @@ -2299,6 +2299,7 @@ public class TApplication implements Runnable { int x = 0; for (TMenu menu: menus) { menu.setX(x); + menu.setTitleX(x); x += menu.getTitle().length() + 2; // Don't let the menu window exceed the screen width diff --git a/src/jexer/menu/TMenu.java b/src/jexer/menu/TMenu.java index 7cf6eb5..b9641e1 100644 --- a/src/jexer/menu/TMenu.java +++ b/src/jexer/menu/TMenu.java @@ -56,6 +56,29 @@ public final class TMenu extends TWindow { */ boolean isSubMenu = false; + /** + * The X position of the menu's title. + */ + private int titleX; + + /** + * Set the menu title X position. + * + * @param titleX the position + */ + public void setTitleX(final int titleX) { + this.titleX = titleX; + } + + /** + * Get the menu title X position. + * + * @return the position + */ + public int getTitleX() { + return titleX; + } + /** * The shortcut and title. */