Skip to content

Commit

Permalink
Add underline variables to FlxText and FlxTextFormat (#3002)
Browse files Browse the repository at this point in the history
  • Loading branch information
Starmapo authored Jan 7, 2024
1 parent aded8af commit 13e63e0
Showing 1 changed file with 36 additions and 14 deletions.
50 changes: 36 additions & 14 deletions flixel/text/FlxText.hx
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
package flixel.text;

import openfl.Assets;
import openfl.display.BitmapData;
import openfl.geom.ColorTransform;
import openfl.text.TextField;
import openfl.text.TextFieldAutoSize;
import openfl.text.TextFormat;
import openfl.text.TextFormatAlign;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.graphics.FlxGraphic;
Expand All @@ -20,6 +13,13 @@ import flixel.system.FlxAssets;
import flixel.util.FlxColor;
import flixel.util.FlxDestroyUtil;
import flixel.util.helpers.FlxRange;
import openfl.Assets;
import openfl.display.BitmapData;
import openfl.geom.ColorTransform;
import openfl.text.TextField;
import openfl.text.TextFieldAutoSize;
import openfl.text.TextFormat;
import openfl.text.TextFormatAlign;

using flixel.util.FlxStringUtil;
using flixel.util.FlxUnicodeUtil;
Expand Down Expand Up @@ -86,6 +86,11 @@ class FlxText extends FlxSprite
*/
public var italic(get, set):Bool;

/**
* Whether to use underlined text or not (`false` by default).
*/
public var underline(get, set):Bool;

/**
* Whether to use word wrapping and multiline or not (`true` by default).
*/
Expand Down Expand Up @@ -723,6 +728,21 @@ class FlxText extends FlxSprite
return value;
}

inline function get_underline():Bool
{
return _defaultFormat.underline;
}

function set_underline(value:Bool):Bool
{
if (_defaultFormat.underline != value)
{
_defaultFormat.underline = value;
updateDefaultFormat();
}
return value;
}

inline function get_wordWrap():Bool
{
return textField.wordWrap;
Expand Down Expand Up @@ -1097,6 +1117,7 @@ class FlxText extends FlxSprite
to.font = from.font;
to.bold = from.bold;
to.italic = from.italic;
to.underline = from.underline;
to.size = from.size;
to.color = from.color;
to.leading = from.leading;
Expand Down Expand Up @@ -1147,15 +1168,16 @@ class FlxTextFormat
var format(default, null):TextFormat;

/**
* @param FontColor Font color, in `0xRRGGBB` format. Inherits from the default format by default.
* @param Bold Whether the text should be bold (must be supported by the font). `false` by default.
* @param Italic Whether the text should be in italics (must be supported by the font). Only works on Flash. `false` by default.
* @param BorderColor Border color, in `0xAARRGGBB` format. By default, no border (`null` / transparent).
* @param fontColor Font color, in `0xRRGGBB` format. Inherits from the default format by default.
* @param bold Whether the text should be bold (must be supported by the font). `false` by default.
* @param italic Whether the text should be in italics (must be supported by the font). Only works on Flash. `false` by default.
* @param borderColor Border color, in `0xAARRGGBB` format. By default, no border (`null` / transparent).
* @param underline Whether the text should be underlined. `false` by default.
*/
public function new(?FontColor:FlxColor, ?Bold:Bool, ?Italic:Bool, ?BorderColor:FlxColor)
public function new(?fontColor:FlxColor, ?bold:Bool, ?italic:Bool, ?borderColor:FlxColor, ?underline:Bool)
{
format = new TextFormat(null, null, FontColor, Bold, Italic);
borderColor = BorderColor == null ? FlxColor.TRANSPARENT : BorderColor;
format = new TextFormat(null, null, fontColor, bold, italic, underline);
this.borderColor = borderColor == null ? FlxColor.TRANSPARENT : borderColor;
}

function set_leading(value:Int):Int
Expand Down

0 comments on commit 13e63e0

Please sign in to comment.