godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.1k stars 21.18k forks source link

OptionButton popup menu opening at incorrect location in combination with Camera2D and a negative x/y coordinate. #48016

Closed elektito closed 3 years ago

elektito commented 3 years ago

Godot version: 3.3 RC9

OS/device including version: Ubuntu 20.04

Issue description: I've seen that when we have an OptionButton with a Camera2D as a child, and the position.x or position.y of the button is negative, the popup menu does not open directly underneath the button, but at an offset.

This also happens if we have a sub-scene with an option menu in it, and then add a Camera2D as the child of the instantiated scene.

Steps to reproduce:

  1. Create a new project.
  2. Add a Node2D as root node
  3. Add an OptionButton as a child to the root
  4. Add a Camera2D as a child of the OptionButton
  5. Move the OptionButton to the left so that it's x coordinate is negative (or move it up so that y is negative)
  6. Run the scene, then click on the option button. The popup menu appears in a wrong location.

Minimal reproduction project: test-option.zip

Calinou commented 3 years ago

Out of curiosity, what do you use a Camera2D as a child of an OptionButton for?

elektito commented 3 years ago

I don't. That's the minimal case I got. The main use case, which I mentioned above was that I had a scene with an OptionButton and I had instantiated that into the main scene. Where I had a camera. The subscene was to the left of the main screen and I had a camera to switch to it. Then I noticed that the popup menu shows right at the edge of the screen.

So the camera doesn't need to be a child of the OptionButton. That was just the easiest method to reproduce the bug. I see that I had written in the description that the camera should be the child of the sub-scene. That's not necessary actually.

menip commented 3 years ago

I can confirm that this happens. The popup seems to have minimum position of (0,0), but can go as positive as need be.


This might have to do with how Popup is designed: "All popup methods ensure correct placement within the viewport."

menip commented 3 years ago

This issue is even more visible in master, as Popups are now Windows. We end up with this: image