godotengine / godot

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

Popup menu node not taking relative position #38171

Open deermen001 opened 4 years ago

deermen001 commented 4 years ago

Note: This issue has been confirmed several times already. No need to confirm it further.


OS : Windows 10 Godot version : 3.2 Issue.zip

I attached popup menu as child node of a 2d node. I moved the parent node with which the popup menu node moved in the editor but on running it still shows it at previous position.

I think the popup menu relative position property is interpreted as absolute global position.

Calinou commented 4 years ago

@deermen001 Please upload a minimal reproduction project to make this easier to troubleshoot.

Also, which Godot version and operating system are you using? (Please fill in the issue template if you plan on reporting other issues.)

deermen001 commented 4 years ago

@deermen001 Please upload a minimal reproduction project to make this easier to troubleshoot.

Also, which Godot version and operating system are you using? (Please fill in the issue template if you plan on reporting other issues.)

I edited my comment as per your guidelines. Please correct me if there is still something wrong.

alexontheweb commented 3 years ago

I second the issue. Both PopupMenu and PopupPanel don't use relative to parent position.

Godot version: Godot Engine v3.2.3.stable.official OS/device including version: Windows 7

Steps to reproduce:

  1. Create a scene:
    - Node2D 
    -- PopupMenu (or PopupPanel)
  2. Move Node2D away from default top left corner. Editor shows child popup node moves along with parent as expected.
  3. Run project: Popup node would appear at window's top left corner instead of near parent node.

Minimal reproduction project: popup_issue.zip

abardess commented 3 years ago

As of 3/3/2021 this is still an issue. The PopupMenu node does not seem to inherent relative position from its parent.

Godot Version: Godot Engine v3.2.3.stable.official OS: Windows 10

I am able to work around it by making a function to set the inheritance manually in its parent:

Scene:

 -Node2D
--Popup Menu

Script attached to Node2D:

extends Node

onready var popup = $PopupMenu

func _process(delta):
     popup.rect_global_position = self.position

Alternatively, if you don't need to update the position every frame, you can put "popup.rect_global_position = self.position" right before you need to show the actual popup, assuming that behavior is controlled from the parent node.

JonathanGrant92 commented 2 years ago

This is an annoying problem. I want the popup to popup, aside: popup() for vector2 parameter should be an issue, above the button, not over it. So, I worked out a solution that is dynamic to changing game window resolutions/resizing.

extends {parent node; preferably HBoxContainer or other control derived node}

var menu_position
var vertical_offset = 0

onready var zoning_button = get_node("Zoning")           # Button
onready var zoning_menu = get_node("Zoning/ZoningMenu")  # PopupMenu 

# I know I should use MenuButton, but this is just how I did it.

func _ready():
    menu_position = zoning_button.rect_position
    vertical_offset = zoning_button.rect_size.y + zoning_menu.rect_size.y

func _on_Zoning_pressed():
        # If you don't plan a resizable window, then move assignment and setter code to bottom of _ready()
    menu_position.y = OS.get_window_safe_area().size.y - vertical_offset
    zoning_menu.set_position(menu_position)
    zoning_menu.show()

Feels like a hacky workaround, but it works for Godot 3.3.2!

OS.get_window_safe_area() is a very useful function. which helped me solve many positioning problems in past projects. Probably should not be the go to function, but it is a fix to position vexing nodes like Popup and its derivatives. Layout button and container nodes are best for positioning gui.

Alec-15 commented 2 years ago

I'm having the same issue in 3.3.3 stable on macos

BirkTorpmannHagen commented 7 months ago

This still does not seem to be solved.

kongehund commented 1 month ago

I also got this bug.

This may or may not be helpful for the devs when debugging:

I only started encountering this bug once I created a Window HelpWindow somewhere else in the scene tree. Before that, the Position of i.e. File was relative to FileButton.

Further, the issue goes away if I set "Embed Subwindows" to true, but that won't work for my project.

image