I have a scene 224 pixels wide and I'm trying to code a simple UI rather than using the visual editor.
I'm trying to get a hboxcontainer to expand to the full width of the screen and hold two labels. I'm trying to get one label left aligned and the other right aligned to the far right of the container. I can get this to work perfectly in the editor but not in code.
extends Node2D
func _ready():
var hbox = HBoxContainer.new()
hbox.set_h_size_flags(Control.SIZE_EXPAND_FILL)
hbox.set_anchors_preset(Control.PRESET_WIDE)
var label_left = Label.new()
label_left.set_text('LEFT TEXT')
hbox.add_child(label_left)
var label_right = Label.new()
label_right.set_align(Label.ALIGN_RIGHT)
label_right.set_text('RIGHT TEXT')
label_right.set_h_size_flags(Control.SIZE_EXPAND_FILL)
hbox.add_child(label_right)
add_child(hbox)
I feel that I'm not managing to get the container to match the layout selection which I can use in the editor which is the either the TOP WIDE or FULL RECT option.
Here's how it looks when I design it in the editor:
https://postimg.cc/Jyvknjq8
Here's how it looks when I attempt the code:
https://postimg.cc/7GzTTbs2
Hoping someone has done this type of thing in code before and can advise me how to do this. Thanks for any help.