godotengine / godot

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

RichText Justified Behavior is Not Correct #92561

Open shadowfox87 opened 3 months ago

shadowfox87 commented 3 months ago

Tested versions

System information

Windows 11 - Godot v4.3.beta.mono.custom_build [afbb108e3]

Issue description

I've tried using the [fill] but it does not behave like the word justify, for example, on lines where theres little text and then a line break, it does extend them up until the box width, making it have super large empty spaces, instead of simply treating that as normal left align (i feel its lacking a thing like, if space width on line exceeds x value then treat this line as left align instead of [fill]).

Basically, what i would like is this: image

but fill gives me this image

It should detect the line break, and justify the text on the space from beginning up to where the line were broken, not up until to the end of the actual line past the line break.

Someone opened a similar issue but it didn't really fix the issue: https://github.com/godotengine/godot/issues/74359 @cal

Steps to reproduce

To reproduce this: image

Minimal reproduction project (MRP)

richtextlabelfill.zip

HKunogi commented 3 months ago

I suffer from this exact problem, the fill tag does not reproduce what is seem on word software justify, if it should, then its definitely not doing so, and if its a totally different meaning tag, then the richtextlabel is lacking an justify option.

Calinou commented 3 months ago

The current fill alignment is actually forced justification. To support standard justification, we would need to expose 3 additional alignment options:

The alignment determines the last line's alignment only, with other lines using fill.

shadowfox87 commented 3 months ago

Ok so it's a confirmed bug. Thank you for looking into it. Would these alignment options be available in the next update?

bruvzg commented 3 months ago

Default justification options include JUSTIFICATION_DO_NOT_SKIP_SINGLE_LINE flag which forces first line justification, you are supposed to be able to override it by using [p justification_flags=word,kashida,skip_last align=fill] instead of [fill], but there's a bug and default flags aren't cleared (fix https://github.com/godotengine/godot/pull/92565).

bruvzg commented 3 months ago

To support standard justification, we would need to expose 3 additional alignment options:

Fill Left Fill Center Fill Right

The alignment determines the last line's alignment only, with other lines using fill.

Might be also useful to add a configurable threshold to skip justification for any line that is too short.

Calinou commented 3 months ago

Default justification options include JUSTIFICATION_DO_NOT_SKIP_SINGLE_LINE flag which forces first line justification, you are supposed to be able to override it by using [p justification_flags=word,kashida,skip_last align=fill] instead of [fill], but there's a bug and default flags aren't cleared (fix #92565).

For RichTextLabel in particular, I wonder if the skip_last parameter should be used by default in the [fill] tag, with [fill align=left|center|right] being added and [fill force=true] for forced justification on the last line (i.e. no skip_last).

This would incur a small visual breakage in existing projects that use [fill], but I don't think the current behavior is being relied upon a lot. Most of the time, people expect the last line not to use justification by default.