I don't think you need any code for this (apart from the set_text
for the label).
I couldn't get it working with a center container - it kept my nine_patch_rect
at it's minimum size regardless of the size flags. My working setup looks like this:
margin_container
nine_patch_rect
center_container
label
When the text inside the label expands, the label's minimum size increases, forcing the center_container
to expand and therefore forcing the margin_container
to expand. The nine_patch_rect
has size flags set to fill (the default) so its size follows the margin_container's size (within the margin specified, of course).
You may want another margin_container
that the center_container
is inside so you can ensure that even if the text expands it won't hit the edges of the ninepatch - this solves the "make sure it's always larger than the text" problem:
margin_container
nine_patch_rect
margin_container
center_container
label