Custom Buttons family

Godot Version

4.4.1

Question

I’m creating a reusable all-around button family, not using Godot’s built-in one. Inspired by layouts like this:

The idea is simple: all of these are buttons, and inside each button there are element nodes — text, checkbox, options, etc. Where you can press the button and each element changes its state. Theme is handled by Button’s native theme system.

So to implement this I started with:

Button
└── MarginContainer
    └── RichTextLabel

And here the problem arises. Button node does not adapt to children size the way containers like MarginContainer do.

One solution was to make Button fully copy the size of MarginContainer — and it does work — but the problem is that whenever anything inside changes, you have to manually tell Button to resize itself. That means manually coding a resize call every time something changes, which is not clean or scalable.

Another solution I considered was:

Container
└── Button (full rect)
└── MarginContainer
    └── RichTextLabel

Where the Container owns the sizing naturally, and Button sits inside it as a transparent input-only layer.

In theory this works, but I’m not sure if there are cleaner workarounds to make Button adapt to its children automatically without manual calls.

So what are your thoughts? Is there a clean native way to make Button size from its children? Or is the Container-owns-root approach the right direction?

I got the solution.
If anyone interested or in case they wanna implement someting like this, let margincontainer pass the border values and give a code of:
@tool
extends MarginContainer

func _notification(what: int) → void:
if what == NOTIFICATION_SORT_CHILDREN:
get_parent().custom_minimum_size = get_combined_minimum_size()

so in this case, whenever margin(self) size changes, it will update parent nodes size to match its. While it doesnt work in editor, and manually changes the size, you actually do not need cuz margni should be full rect on button