Skip to content

Add a configurable spacing between PopupMenu and the button that brought it through a theme constant #14654

Description

@amanullahmenjli

Problem or limitation

While working with OptionButton and MenuButton I like to add a small space between the button and the PopupMenu for aesthetic reasons and to follow my design system.

For now the workaround that I found requires creating a custom nodes that extend OptionButton and MenuButton that does the following:

class_name CustomOptionButton
extends OptionButton

@export var separation: int = 4

var popup: PopupMenu


func _ready() -> void:
	popup = get_popup()
	popup.about_to_popup.connect(_on_popup_about_to_open)


func _on_popup_about_to_open():
	_adjust_popup.call_deferred()


func _adjust_popup():
	# popup.position is read here, AFTER OptionButton has set it
	popup.position = Vector2(popup.position.x, popup.position.y + separation)

which works but would be nicer to have it built-in.

Proposed improvement

Expose a constant in the OptionButton and MenuButton themes to define the separation between the button and the PopupMenu and use it when setting its position in the show_popup method.

Proposal review

  • Yes, this proposal is highly specific and actionable.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions