Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added letterSpacing variable to FlxText. #3027

Merged
merged 5 commits into from
Feb 9, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions flixel/text/FlxText.hx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ class FlxText extends FlxSprite
*/
public var size(get, set):Int;

/**
* A number representing the amount of space that is uniformly distributed
* between all characters. The value specifies the number of pixels that are
* added to the advance after each character.
*
* The default value is `null`, which means that 0 pixels of letter spacing is used.
*/
public var letterSpacing(default, set):Null<Float> = null;
Copy link
Member

@Geokureli Geokureli Feb 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. (default, set) will cause issues, since set_ letterSpacing only sets _defaultFormat.letterSpacing. meaning the following will happen:
text.letterSpacing = 1;
trace(text.letterSpacing); // null

We should add a getter that returns _defaultFormat.letterSpacing

  1. looks like the other fields avoid using Null and just use primitive types, I think Null should be avoided if possible. let's use Float and set the default value to 0, and also set the _defaultFormats initial letterSpacing to 0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The letterSpace is null by default in openfl

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That value cannot be getted

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@Geokureli Geokureli Feb 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That value cannot be getted

Sure it can

The letterSpace is null by default in openfl

I understand, that's why i said "set the _defaultFormats initial letterSpacing to 0", specifically, here


/**
* The font used for this text (assuming that it's using embedded font).
*/
Expand Down Expand Up @@ -640,6 +649,13 @@ class FlxText extends FlxSprite
return Size;
}

function set_letterSpacing(LetterSpacing:Null<Float>):Null<Float>
{
_defaultFormat.letterSpacing = LetterSpacing;
updateDefaultFormat();
return LetterSpacing;
}

override function set_color(Color:FlxColor):Int
{
if (_defaultFormat.color == Color.to24Bit())
Expand Down
Loading