How to justify text in RichTextLabel

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By sirAlexDev

I have a little scene which consists of Control - ColorRect - Label, RichTextLabel, AnimationPlayer(for beautiful output (modulate of container from zero tp default in 1 second) ) I read from file to set RichTextLabel.BbcodeText , because i need something to be centered , right alighned or justified. [center]{text}[/center] and [right]{text}[/right] work perfectly but there is no such teg as “justify” in godot. From godot docs i considered [fill] works similar to justify. But i have unexpected output: it is same as if i dint put [fill] teg and keep it left alighned.

Here is my code

using Godot;
using System;

public class ReadFileScene : Control
{

    public override void _Ready()
    {
        Label title = this.GetNode<Label>("background/container/title");
        RichTextLabel disclaimer = this.GetNode<RichTextLabel>("background/container/main");
        AnimationPlayer fadeIn = this.GetNode<AnimationPlayer>("background/container/fadeIn");

        disclaimer.BbcodeEnabled = true;
        disclaimer.BbcodeText = setText();
        fadeIn.Play("FadeIn");
    }

    private string setText()
    {
        string text = $"{System.Environment.NewLine}";
        string line;
        string[] tags = new string[5]{"center", "right", "fill", "center", "fill"};
        int tagsIndex = 0;

        Godot.File file = new File();
        
        file.Open("res://readMe.txt", File.ModeFlags.Read);
        while (file.EofReached() == false)
        {
            line = file.GetLine();

            if (tags[tagsIndex] == "center")
            {
                text += $"[center]{line}[/center]{System.Environment.NewLine}";
            }
            else if (tags[tagsIndex] == "right")
            {
                text  += $"[right]{line}[/right]{System.Environment.NewLine}";
            }
            else
            {
                text += $"{line}{System.Environment.NewLine}";
            }

            if (String.IsNullOrEmpty(line))
            {
                tagsIndex++;
            }

        }
        file.Close();
        return text;
    }
}

I want it to be like this. IT IS JUSTIFIED IT IS JUSTIFIED

[fill]text[/fill] is the correct tag for justified text. However, form skimming over your code it looks like you never actually add the fill-tag?! Also note that the fill-tag is currently broken in 3.2.2, but has already been fixed and cherrypicked for 3.2.3, so if you run the nightly (or an older version) it should work.

njamster | 2020-08-08 21:54