Skip to content

Comments

Add format property to SpinBox and deprecate prefix/suffix#103998

Open
KoBeWi wants to merge 1 commit intogodotengine:masterfrom
KoBeWi:format_C
Open

Add format property to SpinBox and deprecate prefix/suffix#103998
KoBeWi wants to merge 1 commit intogodotengine:masterfrom
KoBeWi:format_C

Conversation

@KoBeWi
Copy link
Member

@KoBeWi KoBeWi commented Mar 11, 2025

Closes godotengine/godot-proposals#4478 without breaking compatibility. prefix/suffix is used normally if format is not specified.

YM12EoZJbL.mp4

@KoBeWi
Copy link
Member Author

KoBeWi commented Sep 19, 2025

Updated the PR. I resolved the error and default format problems. I used sprintf() instead of vformat(), which allows for nice error handling. If the format is invalid, the SpinBox will show ERROR and the error will be in configuration warning. %s placeholder allows to display the number with default formatting.

godot.windows.editor.dev.x86_64_qc6Dnmuqgh.mp4

I still have to replace usages of old prefix/suffix, but the implementation is ready for review.

@KoBeWi KoBeWi marked this pull request as ready for review September 19, 2025 22:13
@KoBeWi KoBeWi requested a review from a team September 20, 2025 11:23
@KoBeWi KoBeWi requested review from a team as code owners September 20, 2025 11:23
@KoBeWi KoBeWi requested a review from a team September 20, 2025 11:23
@KoBeWi
Copy link
Member Author

KoBeWi commented Sep 20, 2025

Should the old prefix and suffix be hidden from the inspector?

@Mickeon
Copy link
Member

Mickeon commented Sep 20, 2025

I would be inclined to say yes, but part of me wonders what the user reception would be to see an entire property disappearing. I'm not sure how exactly it is handled right now, but perhaps they could be visible only if set previously?

</member>
<member name="prefix" type="String" setter="set_prefix" getter="get_prefix" default="&quot;&quot;">
<member name="format" type="String" setter="set_format" getter="get_format" default="&quot;&quot;">
Specifies formatting of the displayed numeric value, using the same rules as operator [code]%[/code] in [String]. Only applies when the value is not being currently edited. If empty, the value will use default display. Using [code]%s[/code] placeholder will display the value with default formatting. If the format is invalid, the [SpinBox] will show "ERROR", with the actual error message available in the configuration warning.
Copy link
Member

Choose a reason for hiding this comment

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

I swear to God [operator String.operator %] should be a valid reference based on what I have seen of the codebase, and yet it may not be for some reason.

@CsloudX
Copy link

CsloudX commented Jan 25, 2026

Does this feature support displaying hexadecimal numbers as %0X? I really need this function.

@KoBeWi
Copy link
Member Author

KoBeWi commented Jan 25, 2026

Yes

a0yYZsVlFd.mp4

Anything the String formatting supports.

@Repiteo Repiteo requested review from a team as code owners February 17, 2026 20:10
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.

Change SpinBox's prefix and suffix to a single format String

4 participants