Skip to content

Set a default text for Control nodes (and Label3D) when created in the editor - #119020

Open
Calinou wants to merge 1 commit into
godotengine:masterfrom
Calinou:editor-control-default-text-size
Open

Set a default text for Control nodes (and Label3D) when created in the editor#119020
Calinou wants to merge 1 commit into
godotengine:masterfrom
Calinou:editor-control-default-text-size

Conversation

@Calinou

@Calinou Calinou commented Apr 27, 2026

Copy link
Copy Markdown
Member

This allows for immediate visual feedback when adding Control nodes in the editor. A minimum size is also set for controls that don't resize according to their text, so that the text can be displayed without wrapping, even when placed in a Container.

For compatibility, this does not affect nodes created through code (in a @tool script or otherwise).

Preview

Top: nodes added in master in an HBoxContainer. (The first node is a ColorPickerButton.)
Bottom: nodes added in this PR in an HBoxContainer.

image

TODO

  • Consider moving the naming logic to affect any Node, not just Control and Label3D, so that nodes like Window and FileDialog can have titles set automatically.
  • Add a virtual method in Control to get a default minimum size to apply in the editor, so that we don't have to hardcode exceptions here. This would also be more friendly to plugins.
  • Read the theme font and scale the minimum sizes accordingly using TextServer methods.
    • If this is not feasible because the node isn't created yet, use the default theme scale from the Project Settings to multiply the values.

Comment on lines +3105 to 3110
if (ms.width < 10) {
ms.width = 40;
}
if (ms.height < 4) {
if (ms.height < 10) {
ms.height = 40;
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I've changed the size thresholds for default sizing as the current threshold of (4, 4) didn't catch nodes like TextEdit. I assume this occurs because the current values were set a long time ago, when the default project theme was targeting lower resolutions than today.

@Calinou
Calinou force-pushed the editor-control-default-text-size branch from e402b2d to 96f0a45 Compare April 27, 2026 23:30
@Calinou Calinou changed the title Set a default text for Control nodes when created in the editor Set a default text for Control nodes (and Label3D) when created in the editor Apr 27, 2026
@Calinou
Calinou force-pushed the editor-control-default-text-size branch from 96f0a45 to 5a57cfe Compare April 27, 2026 23:30

@KoBeWi KoBeWi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Add a virtual method in Control to get a default minimum size to apply in the editor, so that we don't have to hardcode exceptions here. This would also be more friendly to plugins.

Something like #81217 could be suitable here.

Comment thread editor/docks/scene_tree_dock.cpp Outdated
Control *control = Object::cast_to<Control>(p_child);
if (control) {
// Set default text to give immediate visual feedback when creating controls in the editor.
if (Object::cast_to<ColorPickerButton>(control)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be

Suggested change
if (Object::cast_to<ColorPickerButton>(control)) {
ColorPickerButton *color_picker_button = Object::cast_to<ColorPickerButton>(control);
if (color_picker_button) {

Then you can use the setter directly instead of using set().

EDIT:
Just like you did for Label3D...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

There are a lot of controls with text or title properties, so I'd need to check for them individually if I wanted to use a typed approach.

Comment thread editor/docks/scene_tree_dock.cpp Outdated
…e editor

This allows for immediate visual feedback when adding Control
nodes in the editor. A minimum size is also set for controls that
don't resize according to their text, so that the text can be
displayed without wrapping, even when placed in a Container.

For compatibility, this does not affect nodes created through code
(in a `@tool` script or otherwise).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Needs Work

Development

Successfully merging this pull request may close these issues.

Add default text to controls when adding Control-derived nodes (and Label3D) in the editor

3 participants