flixel icon indicating copy to clipboard operation
flixel copied to clipboard

`FILL` Alignment Mode for FlxText

Open crowplexus opened this issue 2 years ago • 4 comments

I think some kind of alignment mode that fills itself with the text using the FieldWidth as a basis would be neat to see

Something similar to this image

image (this is what it looks like when I space the zeroes)

- Misses:0 / Score:0 - is what the raw text looks like

crowplexus avatar Jul 19 '23 17:07 crowplexus

turns out this exists: https://api.haxeflixel.com/flixel/text/FlxTextAlign.html#JUSTIFY

Geokureli avatar Jul 19 '23 18:07 Geokureli

I attached the text to a fixed sprite at the center of the screen with this constructor

image

then used setFormat to set the colors and alignment

image

this should just work but apparently it does not

image

I'm assuming JUSTIFY isn't actually doing anything in code because this seems to be the same as LEFT

crowplexus avatar Jul 19 '23 19:07 crowplexus

Please just paste code in code tags, rather than using screenshots

also FlxText is just a openfl TextField rendered to a bitmap and drawn as a FlxSprite, so in order to get this to work we need openfl to implement justify alignment in TextField

Geokureli avatar Jul 19 '23 21:07 Geokureli

indeed it appears that the problem lies with openfl. JUSTIFY will always look the same as LEFT if wordwrap is not enabled or if the text does not fill up an entire line. This matches most word editors. image

Take the following example:

final field = new openfl.text.TextField();
field.wordWrap = true;

final format = field.defaultTextFormat;
format.align = JUSTIFY;
format.color = 0xFFffffff;
format.font = "Arial";
field.defaultTextFormat = format;
        
field.text = "Just as you take my hand"
    + " Just as you write my number down"
    + " Just as the drinks arrive"
    + " Just as they play your favorite song"
    + " As your bad day disappears"
    + " No longer wound up like a spring"
    + " Before you had too much"
    + " Come back in focus again";
field.width = 200;
field.height = 200;
FlxG.game.parent.addChild(field);

Appears like so: Screenshot 2023-07-20 at 1 08 24 PM

and adding hard new lines like this:

field.text = "Just as you take my hand"
    + "\nJust as you write my number down"
    + "\nJust as the drinks arrive"
    + "\nJust as they play your favorite song"
    + "\nAs your bad day disappears"
    + "\nNo longer wound up like a spring"
    + "\nBefore you had too much"
    + "\nCome back in focus again";

result in the following: Screenshot 2023-07-20 at 1 13 51 PM

rather than the desired look: jfip

Geokureli avatar Jul 20 '23 18:07 Geokureli