Buttons in popups only update position if they're hidden and shown again, after a resolution change

PopeRigbyPopeRigby Posts: 41Member
in GUI

I'm using code to set the anchors and margins, if that changes anything.



  • SaitodepaulaSaitodepaula Posts: 48Member
    edited June 9

    I think you don't need to use code to set anchors and margins, it would be better to just make a tree of containers to achieve what you want. This way, all buttons are going to be positioned automatically.

    Have you seen the Godot's official GUI tutorial?https://docs.godotengine.org/en/stable/getting_started/step_by_step/ui_game_user_interface.html

    Or, if you want to always use code, maybe you can use the signal item_rect_changed ( ): https://docs.godotengine.org/en/stable/classes/class_canvasitem.html#signals

  • PopeRigbyPopeRigby Posts: 41Member

    The reason I'm using code is because this particular part of the menu is an instanced scene. The layout that I have edited inside that separate scene is setup for a pause menu. I'm modifying the scene before it pops up so it will look good in my main menu.

    func _on_OptionsButton_pressed():
        $OptionsMenu/Buttons.anchor_left = 0.055
        $OptionsMenu/Buttons.anchor_top = 0.102
        $OptionsMenu/Buttons.anchor_right = 0.554
        $OptionsMenu/Buttons.anchor_bottom = 0.902
        $OptionsMenu/Buttons.margin_left = 0
        $OptionsMenu/Buttons.margin_top = 0
        $OptionsMenu/Buttons.margin_right = 0
        $OptionsMenu/Buttons.margin_bottom = 0
        $OptionsMenu/VideoOptions.anchor_left = 0.055
        $OptionsMenu/VideoOptions.anchor_top = 0.102
        $OptionsMenu/VideoOptions.anchor_right = 0.554
        $OptionsMenu/VideoOptions.anchor_bottom = 0.902
        $OptionsMenu/VideoOptions.margin_left = 0
        $OptionsMenu/VideoOptions.margin_top = 0
        $OptionsMenu/VideoOptions.margin_right = 0
        $OptionsMenu/VideoOptions.margin_bottom = 0
        $OptionsMenu/AudioOptions.anchor_left = 0.055
        $OptionsMenu/AudioOptions.anchor_top = 0.102
        $OptionsMenu/AudioOptions.anchor_right = 0.554
        $OptionsMenu/AudioOptions.anchor_bottom = 0.902
        $OptionsMenu/AudioOptions.margin_left = 0
        $OptionsMenu/AudioOptions.margin_top = 0
        $OptionsMenu/AudioOptions.margin_right = 0
        $OptionsMenu/AudioOptions.margin_bottom = 0

    Is that a bad way to do this?

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file