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

No way to disable embedded Keyboard-Controls for PopupMenu #301

Open
leohilbert opened this issue Jan 4, 2019 · 1 comment
Open

No way to disable embedded Keyboard-Controls for PopupMenu #301

leohilbert opened this issue Jan 4, 2019 · 1 comment
Labels

Comments

@leohilbert
Copy link

leohilbert commented Jan 4, 2019

Hi, first up: thanks for creating this library, it's helping me out a ton! :)
I'm using the PopupMenu in my game and have a few problems with it.
I implemented my own Keyboard-Handling and the Popup-Menu is interfering with it.
The StageListener that get's created during the construction of the object also listens to keyDown-Events and handles UP and DOWN-Presses to skip to the next item.
I would like to disable this functionality, but everything that I would need to overwrite is private:

  • private void createListeners()
  • private InputListener stageListener

I will use reflections for now, but it would be nice to have an option to disable this out of the box.
If you agree I could create a pull-request to simply make the createListeners-Method protected or create a constructor with a boolean "enableKeyboardSupport" in the constructor which is true by default.

Another thing I noticed is that the "void selectNextItem()"-Method of the PopupMenu runs in an infinite-loop, when you have 2 actors added to the popup that are NOT MenuItems.

private void selectNextItem () {
	SnapshotArray<Actor> children = getChildren();
	if (children.size == 0) return;
	int startIndex = activeItem == null ? 0 : children.indexOf(activeItem, true) + 1;
	for (int i = startIndex; ; i++) {
		if (i >= children.size) i = 0;
		Actor actor = children.get(i);
		if (actor instanceof MenuItem && ((MenuItem) actor).isDisabled() == false) {
			setActiveItem((MenuItem) actor, true);
			break;
		}
	}
}

It will search for a MenuItem and never find one, so the Game freezes.

Thanks :)

@kotcrab
Copy link
Owner

kotcrab commented Jan 5, 2019

I think it would be better to have boolean flag along with getter and setter rather than adding yet another constructor argument. Making method protected would be a bad design so let's not do that.

I've noticed more problems with the keyboard selection so I went ahead and fixed it. Probably unlikely case but still, nice catch.

I've also changed how menu's keyboard events are handled. By returning true when action is performed the event won't be passed to the application under the stage. This might actually fix the issue you're having so we might get away with disabling keyboard support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants