godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.49k stars 21.07k forks source link

RichTextLabel word breaking rules are wrong when a hyphen is used to create composed words in [fill] alignment #71933

Open TheRealSlander opened 1 year ago

TheRealSlander commented 1 year ago

Godot version

4.0 beta 14

System information

Linux 64 bits (Manjaro)

Issue description

When using a [fill][/fill] tags in RichTextLabel, if a word is composed using an hyphen (-), the second part of the word is separated with a space where it should stick to the first part. Hyphen Bug In my screenshot, both red-circled words should be "one word without space". Screenshot language is French, but the same happens in any language.

The solution would be to consider both parts of the composed word to be "linked" and the whole thing should be considered as a single word. But in the case of breaking the word (if the RichTextLabel is not wide enough), the second part should indeed be put on the next line.

Steps to reproduce

Minimal reproduction project

N/A

akien-mga commented 1 year ago

CC @bruvzg

TheRealSlander commented 1 year ago

Another case of unexpected result with the parenthesis this time: Parenthesis Bug In the screenshot there shouldn't be a space between the opening parenthesis and the "e" letter. The result should be: connecté(e)

EDIT: I have tested many characters to be sure and it happens with all the special ones like slashes / and \, brackets {, square brackets [, parenthesis ( and hyphen -. It does not happen with underscore _ and arobase @ though (which is good).

TheRealSlander commented 1 year ago

Well, I found another case where the RichTextLabel should act differently: Over Spaced The last sentence (in white on my screenshot) should not be stretched accross the whole width of the RichTextLabel but instead act as the last orange line (left alignment).

Maybe checking the width of spaces and avoid "filling" the label if superior to a defined amount / percentage of the label width would be a solution?

Calinou commented 1 year ago

EDIT: I have tested many characters to be sure and it happens with all the special ones like slashes / and \, brackets {, square brackets [, parenthesis ( and hyphen -.

This likely occurs because all the characters you've mentioned are non-word delimiters, but _ and @ are not.

Maybe checking the width of spaces and avoid "filling" the label if superior to a defined amount / percentage of the label width would be a solution?

[fill] is currently "forced" fill – it fills the line even if text isn't remotely close to filling the whole width. This has a few specialized use cases, but I agree it's generally not what you want.

It could probably be changed to accept an optional parameter to use standard left/center/right alignment if the line isn't full (e.g. [fill=center]This is center-aligned if not filled[/center]).

TheRealSlander commented 1 year ago

[fill] is currently "forced" fill – it fills the line even if text isn't remotely close to filling the whole width. This has a few specialized use cases, but I agree it's generally not what you want.

Can you explain why the last 2 words of my orange text ("votre compte.") are not impacted by the "forced fill"? All my text is surrounded by one [fill]...[/fill] flag pair. I use "\n" inside the text to format it like I want, but that's it.

Here is the String value: const my_text : String = "[fill][b][color=#FF8000]Une erreur inconnue s'est produite lors de la tentative de connexion à votre compte.[/color][/b]\ \n\ \nVeuillez réessayer plus tard.[/fill]"

TheRealSlander commented 1 year ago

Closed as the described problems are not present anymore with the 4.0 and 4.0.1.rc1 and as they seem to have been fixed. I hope this is good with you guys?

TheRealSlander commented 1 year ago

Arf, sorry... I closed that too quickly. 1 issue remains (the last discussed with Calinou, corresponding to my last screenshot). Reopened then.