Skip to content
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

Spaces are counted in RichTextLabel but not Label when using get_total_character_count() #27896

Open
Tracked by #39144
TheRadMatt opened this issue Apr 10, 2019 · 13 comments

Comments

@TheRadMatt
Copy link

Godot version:
3.1

There are differences in how richtextlabel and label hadle spaces in their texts. richtextlabel counts spaces when using get_total_character_count() while label does not:
Bug?

This isn't that much of a problem because you can just use text.length() BUT when you use label.visible_characters += 1, that becomes a problem. For examle I wrote a system that shows the same text for both of those nodes and it works only with one of them at a time because each node handles spaces differently.

This is very annoying and messy. It would be great if both of them counted spaces.

@toger5
Copy link
Contributor

toger5 commented Apr 10, 2019

maybe renaming both to get_visible_character_count (and let them behave that way)
and for total count use text.length()?

@bergmannf
Copy link
Contributor

bergmannf commented Oct 16, 2019

I was taking a look at this, but I haven't worked with the codebase before, so maybe my comment is wrong - so take it with a grain of salt, but: it seems at least the change to label was deliberate to not include spaces (and that is also documented):

922f2d6

This fix was in response to #23720

Maybe it would make more sense to update rich_text_label instead to make it behave like label?
However - the docs for the rich_text_label do not say that it excludes whitespace so that (right now) also seems deliberate.

@Ranoller
Copy link
Contributor

Ranoller commented Nov 28, 2019

Well, today i found that after some headache hours....
I think this is a bug. Space is a visible character. You can´t compare your strings.length() or the Label.text with the visible characters, and that is very bad. A workaround is count the " " in every text and sub that to the character count to get the real visible characters....
tricky and bad...
very bad...
There should be an option to not ignore spaces, or directly not ignore by default (not good reason to do that)... or this incoherence between RichTextLabel and Label should be very well documented (But I still think that there is not good reason for this behavior).

@elizaho
Copy link

elizaho commented Mar 31, 2020

I would like to work on this.

@Calinou
Copy link
Member

Calinou commented Mar 31, 2020

@elizaho It seems nobody is currently working on a fix, so go ahead 🙂

@elizaho
Copy link

elizaho commented Apr 11, 2020

What are the steps to reproduce this error?

@Janglee123
Copy link
Contributor

@elizaho Create a rich text label and label with the same text above and use get_total_character_count() function for both of them.

@elizaho
Copy link

elizaho commented Apr 16, 2020

get_total_character_count returns 0 for a non-empty RichTextLabel. Is this expected behaviour?

get_node("RTLabelCount").text = str(get_node("RichTextLabel").get_total_character_count())

@Calinou
Copy link
Member

Calinou commented Apr 17, 2020

If you've set the text immediately before calling get_total_character_count(), you may have to wait a frame for the value to be valid. This is because RichTextLabel isn't fully synchronous (#36381).

Use yield(get_tree(), "idle_frame") before calling get_total_character_count() to wait for a frame.

elizaho added a commit to elizaho/godot that referenced this issue Apr 17, 2020
@Calinou Calinou changed the title Spaces in Label and RichTextLabel Spaces are counted in RichTextLabel but not Label when using get_total_character_count() May 19, 2020
@Xascoria
Copy link

Just ran into this problem, would definitely love to have at least an alternate option to include space on Label/exclude space on RichTextLabel

@Lucas3H
Copy link

Lucas3H commented Sep 12, 2021

In 4.0 version this function "get_total_character_count()" return equal values for both Label and RichTextLabel, but it counts spaces and the documentation says it doesn't. Can I try to fix the function or is it better to just change the documentation?

@Calinou
Copy link
Member

Calinou commented Sep 13, 2021

In 4.0 version this function "get_total_character_count()" return equal values for both Label and RichTextLabel, but it counts spaces and the documentation says it doesn't. Can I try to fix the function or is it better to just change the documentation?

See #37969 which modifies Label's character counting to include spaces.

Either way, I think this should be discussed in a proposal since this would change either functions' behaviors (and is therefore a compatibility-breaking change). My suggestions would be:

  • For master, make both Label and RichTextLabel include spaces by default in their respective character counting functions. Add an optional include_spaces boolean parameter that defaults to true; set it to false to exclude spaces from the character counting.
  • For 3.x, add an optional include_spaces boolean parameter that defaults to false for Label and true for RichTextLabel. Set it to false to exclude spaces from the character counting. Explicitly document the default behavior difference in the class reference.

@Lucas3H
Copy link

Lucas3H commented Sep 13, 2021

In 4.0 version this function "get_total_character_count()" return equal values for both Label and RichTextLabel, but it counts spaces and the documentation says it doesn't. Can I try to fix the function or is it better to just change the documentation?

See #37969 which modifies Label's character counting to include spaces.

Either way, I think this should be discussed in a proposal since this would change either functions' behaviors (and is therefore a compatibility-breaking change). My suggestions would be:

* For `master`, make both Label and RichTextLabel include spaces by default in their respective character counting functions. Add an optional `include_spaces` boolean parameter that defaults to `true`; set it to `false` to exclude spaces from the character counting.

* For `3.x`, add an optional `include_spaces` boolean parameter that defaults to `false` for Label and `true` for RichTextLabel. Set it to `false` to exclude spaces from the character counting. Explicitly document the default behavior difference in the class reference.

Ah, sorry for the ignorance, I thought that this PR #37969 was not merged yet, so the function hasn't changed...

Anyway, I'll try to do what you have said. Thanks a lot!

@KoBeWi KoBeWi moved this to To Assess in 4.x Priority Issues Apr 10, 2022
@KoBeWi KoBeWi moved this from To Assess to In Progress in 4.x Priority Issues Apr 10, 2022
@YuriSizov YuriSizov modified the milestones: 4.0, 4.x Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment