Godot 4’s AcceptDialog resets its buttons’ custom_minimum_size on every popup — size them through the theme constants instead

A code review flagged that the OK and Cancel buttons of my two « erase everything? » confirmation dialogs were about 31×37 px on a phone, far below the 48 dp a finger needs. I set custom_minimum_size on get_ok_button() and get_cancel_button() in _ready(), the test asserting the size passed, and the buttons were still tiny on screen. The assertion was checking the wrong moment.

TL;DR — AcceptDialog recomputes its buttons’ custom_minimum_size from the theme constants buttons_min_width and buttons_min_height inside _update_child_rects(), which runs on every popup_centered(). Override those two constants on the dialog; a direct custom_minimum_size write is overwritten at the first popup.

The setup

An Android game in Godot 4.7.1 with an Options screen. The destructive « reset progress » action goes through two ConfirmationDialog nodes in a row (the second one with OK moved to the left). All other buttons in the game are 88 px tall in a 1280×720 logical viewport, which is roughly 48 dp on a 1080p phone. The dialogs are plain scene nodes, opened with popup_centered().

What I expected

get_ok_button() returns a normal Button. Setting custom_minimum_size on a Button is the standard way to make it bigger, and nothing in the class reference says the dialog will touch that property afterwards. I wrote the size in _ready() and moved on.

What actually happens

A small bench script made the behaviour visible:

extends SceneTree
func _init() -> void:
    var d := ConfirmationDialog.new()
    root.add_child(d)
    d.get_ok_button().custom_minimum_size = Vector2(160, 88)
    print("before popup: ", d.get_ok_button().custom_minimum_size)  # (160, 88)
    d.popup_centered()
    print("after popup:  ", d.get_ok_button().custom_minimum_size)  # (0, 0)
    quit()

After the first popup the value is back to (0, 0) and the button takes its theme size, about 31×37 px with the default theme. Setting the size again after popup_centered() works until the next popup, which is why a test that asserts right after the write passes while the running game shows small buttons.

Left: custom_minimum_size set in _ready is wiped by popup_centered, buttons come back at 31×37 px. Right: theme constant overrides buttons_min_width/height are read by the same code path and survive every popup at 160×88 px

The fix

One helper, called once per dialog from _ready():

class_name DialogStyle
extends Object

## Touch-sized OK/Cancel buttons that survive every popup_centered().
static func fit_touch_targets(dialog: AcceptDialog, min_size := Vector2(160, 88)) -> void:
    dialog.add_theme_constant_override("buttons_min_width", int(min_size.x))
    dialog.add_theme_constant_override("buttons_min_height", int(min_size.y))
    # Also set the direct size so the very first layout (before any popup) is right.
    dialog.get_ok_button().custom_minimum_size = min_size
    var confirm := dialog as ConfirmationDialog
    if confirm != null:
        confirm.get_cancel_button().custom_minimum_size = min_size
func _ready() -> void:
    for d in [%ResetDialog1, %ResetDialog2]:
        DialogStyle.fit_touch_targets(d)

And the test that would have caught the regression measures after the popup, not before:

%ResetDialog1.popup_centered()
assert_gte(%ResetDialog1.get_ok_button().custom_minimum_size.y, 88.0)

Why it works

AcceptDialog::_update_child_rects() lays out the label, the content and the button row every time the dialog is shown or resized. Part of that routine assigns each button’s custom_minimum_size from the dialog’s own theme items buttons_min_width and buttons_min_height. Those constants default to 0, so the buttons fall back to their text size. add_theme_constant_override() on the dialog node is exactly the lookup that routine performs, so the override becomes the value written on every popup. The direct custom_minimum_size write in the helper only covers the window before the first _update_child_rects() call.

The same constants exist on ConfirmationDialog since it inherits AcceptDialog; FileDialog and other subclasses go through the same layout code.

What I did not test

Only Godot 4.7.1 with the default theme and embedded subwindows (display/window/subwindows/embed_subwindows left at its default). I did not check whether a project-wide Theme resource that sets AcceptDialog/constants/buttons_min_height behaves identically — it should, since it feeds the same lookup, but I did not run it.

Facts

context: Godot 4.7.1 AcceptDialog / ConfirmationDialog buttons needing 48 dp touch targets
problem: custom_minimum_size set on get_ok_button() is reset to (0,0) by popup_centered()
solution: add_theme_constant_override("buttons_min_width"/"buttons_min_height") on the dialog, and assert sizes after the popup in tests
verified_on: 2026-09-12
applies_to: Godot 4.7.1 (AcceptDialog and subclasses), default theme
does_not_apply_to: custom Window subclasses that do not use AcceptDialog's layout

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Retour en haut