Skip to content

Conversation

KnifeXRage
Copy link

@KnifeXRage KnifeXRage commented Oct 15, 2025

Added two new properties to ScrollContainer:

  • horizontal_content_align
  • vertical_content_align

Allows ScrollContainer content to be aligned left/center/right and top/center/bottom from Inspector or using GDScript.
And also updated Documentation in doc/classes/ScrollContainer.xml.

Here is a demo video of ScrollContainer Content Alignment Feature:

Scroll.Container.Content.Alignment.Feature.mp4

@KnifeXRage KnifeXRage requested review from a team as code owners October 15, 2025 13:24
@AThousandShips AThousandShips changed the title Added Horizontal and Vertical Content Alignment Options to ScrollContainer Add Horizontal and Vertical Content Alignment Options to ScrollContainer Oct 15, 2025
KnifeXRage and others added 2 commits October 15, 2025 19:31
@AThousandShips
Copy link
Member

Thanks for opening a pull request!

Feature pull requests should be associated to a feature proposal to justify the need for implementing the feature in Godot core. Please open a proposal on the Godot proposals repository (and link to this pull request in the proposal's body).

@KnifeXRage
Copy link
Author

Thank you for the guidance! This is my first pull request, so I really appreciate your help. I will create a feature proposal on the Godot proposals repository and link this pull request in the proposal.

@KoBeWi
Copy link
Member

KoBeWi commented Oct 15, 2025

How is this different from using size flags?

godot.windows.editor.dev.x86_64_LfJ6lo4WnG.mp4

@KnifeXRage
Copy link
Author

Thanks for asking! Size flags control how a child expands or fills space, but they don’t let you explicitly align content inside a ScrollContainer.

With the proposed horizontal_content_align and vertical_content_align properties, developers can directly position content (center, right, bottom, etc.) without adding extra nodes or writing custom scripts and it can be directly controlled using gdscript, which makes layouts simpler and more intuitive.

@KoBeWi
Copy link
Member

KoBeWi commented Oct 15, 2025

But it doesn't need any "extra" nodes. The ScrollContainer already requires one content node (BoxContainer, GridContainer etc.), and that node is the subject to size flags. You even have one in your video, I replicated that layout. You can set the alignment from GDScript using set_anchors_and_offsets_preset().

@KnifeXRage
Copy link
Author

Yes, you are right, but i just added this feature for easier use. it's easy to find and use from the inspector panel.

public:
virtual void gui_input(const Ref<InputEvent> &p_gui_input) override;

void set_horizontal_content_align(int p_align);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should still use the enum type, for both

Comment on lines +52 to +54
H_ALIGN_LEFT = 0,
H_ALIGN_CENTER = 1,
H_ALIGN_RIGHT = 2,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
H_ALIGN_LEFT = 0,
H_ALIGN_CENTER = 1,
H_ALIGN_RIGHT = 2,
CONTENT_H_ALIGN_LEFT,
CONTENT_H_ALIGN_CENTER,
CONTENT_H_ALIGN_RIGHT,

And both should be registered with VARIANT_ENUM_CAST below

Comment on lines +58 to +60
V_ALIGN_TOP = 0,
V_ALIGN_CENTER = 1,
V_ALIGN_BOTTOM = 2,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
V_ALIGN_TOP = 0,
V_ALIGN_CENTER = 1,
V_ALIGN_BOTTOM = 2,
CONTENT_V_ALIGN_TOP,
CONTENT_V_ALIGN_CENTER,
CONTENT_V_ALIGN_BOTTOM,


ClassDB::bind_integer_constant("ScrollContainer", "ContentVAlign", "V_ALIGN_TOP", V_ALIGN_TOP, false);
ClassDB::bind_integer_constant("ScrollContainer", "ContentVAlign", "V_ALIGN_CENTER", V_ALIGN_CENTER, false);
ClassDB::bind_integer_constant("ScrollContainer", "ContentVAlign", "V_ALIGN_BOTTOM", V_ALIGN_BOTTOM, false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should still be registered using the correct type, with BIND_ENUM_CONSTANT like below, and below the other ones

Copy link
Author

@KnifeXRage KnifeXRage Oct 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it but it's not working. And engine compilation fails. But this way it works properly. But I will try again.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should work if done correctly

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file needs to be restored from all the unnecessary changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants