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

Missing mouse click event when closing a popup. #98

Open
eugen-paul opened this issue Jun 14, 2020 · 3 comments
Open

Missing mouse click event when closing a popup. #98

eugen-paul opened this issue Jun 14, 2020 · 3 comments

Comments

@eugen-paul
Copy link

I create and show a popup with the property ClickMode=Close.
A click outside of the popup on another Lemur-GUI-Element will close the current popup and a MouseButtonEvent=pressed pass through to the real UI (to the JME analog listener) not to the Lemur-GUI-Element.
But the MouseButtonEvent=release will be catched by Lemur-GUI-Element and will be not pass through to the JME.
Thats why the MouseButtonEvent=pressed will be triggered by each update loop.

Example:
Click on "Open Popup" button two times. The message "MouseInput.BUTTON_LEFT" will be continuously logged on the console until you click somewhere.

import com.jme3.app.SimpleApplication;
import com.jme3.input.MouseInput;
import com.jme3.input.controls.AnalogListener;
import com.jme3.input.controls.MouseButtonTrigger;
import com.simsilica.lemur.Button;
import com.simsilica.lemur.Command;
import com.simsilica.lemur.Container;
import com.simsilica.lemur.GuiGlobals;
import com.simsilica.lemur.event.PopupState;

public class TestPopup extends SimpleApplication {
  public static void main(String[] args) {
    TestPopup app = new TestPopup();
    app.start();
  }

  @Override
  public void simpleInitApp() {
    GuiGlobals.initialize(this);

    Container myWindow = new Container();
    getGuiNode().attachChild(myWindow);

    myWindow.setLocalTranslation(0, getContext().getSettings().getHeight(), 0);

    Button startButton = myWindow.addChild(new Button("Open Popup"));
    startButton.addClickCommands(new Command<Button>() {
      @Override
      public void execute(Button source) {
        Button popUpButton = new Button("don't click on me");
        popUpButton.setLocalTranslation(300, getContext().getSettings().getHeight(), 0);
        PopupState popupState = GuiGlobals.getInstance().getPopupState();
        popupState.showPopup(popUpButton);
      }
    });

    initKeys();
  }

  private void initKeys() {
    inputManager.addMapping("mouseClick", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    // Add the names to the action listener.
    inputManager.addListener(analogListener, "mouseClick");
  }

  private final AnalogListener analogListener = new AnalogListener() {
    @Override
    public void onAnalog(String name, float value, float tpf) {
      if (name.equals("mouseClick")) {
        System.out.println("MouseInput.BUTTON_LEFT.");
      }
    }
  };
}
@pspeed42
Copy link
Contributor

pspeed42 commented Jul 2, 2020

Note: I'm not ignoring this report but every time I read it, I'm not sure what to do about yet and then life gets in the way again.

Curious if it would also happen if the mouse click was handled with Lemur's InputMapper instead of JME's cludgy InputManager. I assume it would, though.

@eugen-paul
Copy link
Author

When describing "PopupState.ClickMode=Close" it says that "A click outside of the current popup will close the current popup and the event will otherwise propagate to whatever was below.". But when I click a button (or another GUI element) that is behind the popup, the popup is closed. The event (MouseButtonEvent = pressed) is not caught by the button, but passed on directly to the JME's InputManager. Since a click consists of two events, the second event (MouseButtonEvent = release) is intercepted by the button.

I expected that both events would be handled by the button in this case.
In my example, if you click on the "Open Popup" button while a popup is open, then only the current popup is closed but no new popup is opened.

@eugen-paul eugen-paul closed this as not planned Won't fix, can't repro, duplicate, stale Jul 18, 2023
@pspeed42
Copy link
Contributor

There is some weirdness with event delivery in the case of the popup blockers. It's frustrating because I really do want that first 'down' event to be passed on but it would require a sensitive refactoring of the mouse propagation code.

So to me your issue is kind of a real one but it's just difficult to accomplish a fix. I'm going to leave it open.

@pspeed42 pspeed42 reopened this Jul 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants