Help understanding the documentation e.g looking at the label control

Godot Version

4.3-rc3

Question

I’m struggling to understand the correct syntax when consulting the godot docs to implement using c#.

An example looking at how to change label alightment property in code:

HorizontalAlignment horizontal_alignment = 0

void set_horizontal_alignment ( HorizontalAlignment value )

HorizontalAlignment get_horizontal_alignment ( )

Controls the text’s horizontal alignment. Supports left, center, right, and fill, or justify. Set it to one of the HorizontalAlignment constants.

I had to consult chatgpt because I just wasn’t getting it. It actually gave me a correct answer, well an answer that worked.

How do you get from the above to:

HorizontalAlignment = HorizontalAlignment.Center

I’m using it like this running through a dictoinary and creating dynamic labels:

Label label = new Label
{
	Text = entry.Key,
	Name = entry.Key,
	CustomMinimumSize = new Vector2(150, 60),
	VerticalAlignment = VerticalAlignment.Center,
	HorizontalAlignment = HorizontalAlignment.Center,
}

I think using a custom theme in godot would be much easier, but I’m interested in how to do a better job of reading the docs.

If you use c# I recommend you use as external editor Visual Studio or VSCode, it just checkbox in Godot - Editor-Preferences -Mono … somewhere here. Ofc it must be installed, but you can look inside classes and get a code assistance (Ctrl+Space)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.