-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve editor property capitalization #32734
Improve editor property capitalization #32734
Conversation
26603b4
to
b70aee2
Compare
b70aee2
to
8f65925
Compare
Could there be a way to make that clearer? |
@asheraryam Maybe it could be renamed to |
8f65925
to
94aa68f
Compare
Since it's not strictly Title Case, it would make sense to call it something else. What about |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
capitalize_string_remaps["Gles 3"] = "GLES3"; | ||
capitalize_string_remaps["Hdr"] = "HDR"; | ||
capitalize_string_remaps["Hidpi"] = "hiDPI"; | ||
capitalize_string_remaps["Kb"] = "KB"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is "Kb" used? It might be a good idea to replace it with the binary prefix version "KiB". Also, by the time this will be merged (4.0), GLES3 will have been removed, consider removing it from this list.
@Calinou Any update? This needs to be rebased on the latest master branch. Also, I had an idea which might work for some situations. What if Godot's auto-capitalization had a rule where it only changed lowercase letters, so any pre-existing uppercase letters are kept as uppercase always? This would work for class names and any other situation where uppercase letters are used for acronyms in the name. |
I don't think this is the best solution. IMO we should make it possible to specify a descriptive name in addition to the property name. This way we wouldn't have to rely on the engine's hard-coded list to have the entries we want. It would also allow localization of those settings names. |
@neikeq Your proposal is definitely a better solution, but I don't know if we can afford adding yet another (optional) parameter to ProprertyInfo which already takes quite a lot of parameters. |
Please merge, my eyes have found peace. |
@@ -4636,6 +4636,18 @@ void EditorNode::_scene_tab_changed(int p_tab) { | |||
editor_data.get_undo_redo().commit_action(); | |||
} | |||
|
|||
String EditorNode::capitalize_string(const String &p_string) const { | |||
|
|||
String capitalized_string = p_string.capitalize(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a case where two different strings could result in the same capitalized string? If the answer is yes, then the current implementation is understandable. If not, then this can be optimized by only calling capitalize()
if a remap could not be found below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, and this would remove the awkwardness of having remappings based on the wrongly capitalized property paths (which can change if we ever change what capitalize()
does).
Instead, remap directly based on the property path substrings:
capitalize_string_remaps["s3tc"] = "S3TC";
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I still think the solution I mentioned previously is great as it allows localization, I'm now in favour of merging this because:
- Short-term it's the only solution as mine requires much more work.
- I just realized I can re-use this
capitalize_string
in the C# bindings generator. I had already planned to create my own hard-coded remaps for generating better names (likeAddiOSFramework
instead ofAddIosFramework
). With the newcapitalize_string
I will no longer have to do that as I can re-use this.
According to the .NET Capitalization Conventions, the latter is correct and should be preferred over the former. |
@Vivraan OS is an acronym, so it should be capitalized. Reading the document you linked, I'm confused as to why they chose to treat acronyms of 2 letters and acronyms of more than 2 letters differently, it seems inconsistent. An argument for |
iOS is a three letter acronym, so it becomes Consider BSD - However, I have seen Godot use what you described as PascalCase (consider |
I think both "HttpRequest" and "HTTPRequest" can claim to be PascalCase. These just happen to be different flavors of PascalCase. Either way, Godot has settled on the latter, so I wouldn't change it in our API. |
Here's a note on some camel case variants: https://wiki.c2.com/?CapitalizationRules |
Let's move the C# conversation somewhere else (feel free to open a godot-proposal where we can discuss the desired rules) as it's not the topic of this PR. If the names are not fine for C#, we can always make our own remap table as I initially had intended. |
94aa68f
to
953381c
Compare
@@ -4824,9 +4824,21 @@ void EditorNode::_scene_tab_changed(int p_tab) { | |||
editor_data.get_undo_redo().commit_action(); | |||
} | |||
|
|||
String EditorNode::capitalize_string(const String &p_string) const { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should avoid putting all kinds of helpers in EditorNode as it makes it huge. Not sure where to put this though, maybe @EricEzaM has an idea since he's been reworking this code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it can go into String
itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, in Godot solutions must be local and such editor-specific helper code is not something that should be part of the core String API (just like we wouldn't try to add it to std::string
if we used the STL).
An hardcoded list of exceptions is now used to make property name capitalization more natural.
953381c
to
419541c
Compare
This comment has been minimized.
This comment has been minimized.
I think this PR is mostly good, but I would not further bloat EditorNode, which is already incredibly bloated. Just add a new singleton like EditorStringCapitalization or similar and put stuff there. |
Superseded by #58706. |
An hardcoded list of exceptions is now used to make property name capitalization more natural.
I'm not too happy with this implementation – maybe we should add an optional "friendly name" property hint in the end. Also, it takes more time to run the string replacements (30 µs on average for each string in a debug build, compared to 10 µs with the old method). Still, it's not run every frame so it should be fine performance-wise.
There are other improvements we can do, such as not capitalizing stop words like
at
,in
andto
. We could do this for the general-purposeString::capitalize()
function in 4.0.Preview
Look at the section and property names.
This closes godotengine/godot-proposals#1399.