<commit_before>package flixel.ui;

import flixel.text.FlxText;
import flixel.util.FlxPoint;

/**
 * A simple button class that calls a function when clicked by the mouse.
 */
class FlxButton extends FlxTypedButton<FlxText>
{
	/**
	 * Used with public variable status, means not highlighted or pressed.
	 */
	public static inline var NORMAL:Int = 0;
	/**
	 * Used with public variable status, means highlighted (usually from mouse over).
	 */
	public static inline var HIGHLIGHT:Int = 1;
	/**
	 * Used with public variable status, means pressed (usually from mouse click).
	 */
	public static inline var PRESSED:Int = 2;
	
	public var text(get, set):String;
	
	/**
	 * Creates a new FlxButton object with a gray background
	 * and a callback function on the UI thread.
	 * 
	 * @param	X				The X position of the button.
	 * @param	Y				The Y position of the button.
	 * @param	Label			The text that you want to appear on the button.
	 * @param	OnClick			The function to call whenever the button is clicked.
	 */
	public function new(X:Float = 0, Y:Float = 0, ?Label:String, ?OnClick:Void->Void)
	{
		super(X, Y, OnClick);
		
		for (point in labelOffsets)
		{
			point.set(point.x - 1, point.y + 3);
		}
		
		if (Label != null)
		{
			initLabel(Label);
		}
	}
	
	/**
	 * Updates the size of the text field to match the button.
	 */
	override private function resetHelpers():Void
	{
		super.resetHelpers();
		
		if (label != null)
		{
			label.fieldWidth = label.frameWidth = Std.int(width);
			label.size = label.size; // Calls set_size(), don't remove!
		}
	}
	
	private inline function initLabel(Text:String):Void 
	{
		label = new FlxText(x + labelOffsets[NORMAL].x, y + labelOffsets[NORMAL].y, 80, Text);
		label.setFormat(null, 8, 0x333333, "center");
		label.alpha = labelAlphas[status];
	}
	
	private inline function get_text():String 
	{
		if (label == null)
			return "";
		return label.text;
	}
	
	private inline function set_text(Text:String):String 
	{
		if (label == null)
			initLabel(Text);
		return label.text = Text;
	}
}<commit_msg>FlxButton: always create a label so you don't have to guard against null (#962)<commit_after>package flixel.ui;

import flixel.text.FlxText;
import flixel.util.FlxPoint;

/**
 * A simple button class that calls a function when clicked by the mouse.
 */
class FlxButton extends FlxTypedButton<FlxText>
{
	/**
	 * Used with public variable status, means not highlighted or pressed.
	 */
	public static inline var NORMAL:Int = 0;
	/**
	 * Used with public variable status, means highlighted (usually from mouse over).
	 */
	public static inline var HIGHLIGHT:Int = 1;
	/**
	 * Used with public variable status, means pressed (usually from mouse click).
	 */
	public static inline var PRESSED:Int = 2;
	
	/**
	 * Shortcut to setting label.text
	 */
	public var text(get, set):String;
	
	/**
	 * Creates a new FlxButton object with a gray background
	 * and a callback function on the UI thread.
	 * 
	 * @param	X				The X position of the button.
	 * @param	Y				The Y position of the button.
	 * @param	Text			The text that you want to appear on the button.
	 * @param	OnClick			The function to call whenever the button is clicked.
	 */
	public function new(X:Float = 0, Y:Float = 0, ?Text:String, ?OnClick:Void->Void)
	{
		super(X, Y, OnClick);
		
		for (point in labelOffsets)
		{
			point.set(point.x - 1, point.y + 3);
		}
		
		initLabel(Text);
	}
	
	/**
	 * Updates the size of the text field to match the button.
	 */
	override private function resetHelpers():Void
	{
		super.resetHelpers();
		
		if (label != null)
		{
			label.fieldWidth = label.frameWidth = Std.int(width);
			label.size = label.size; // Calls set_size(), don't remove!
		}
	}
	
	private inline function initLabel(Text:String):Void 
	{
		label = new FlxText(x + labelOffsets[NORMAL].x, y + labelOffsets[NORMAL].y, 80, Text);
		label.setFormat(null, 8, 0x333333, "center");
		label.alpha = labelAlphas[status];
	}
	
	private inline function get_text():String 
	{
		return label.text;
	}
	
	private inline function set_text(Text:String):String 
	{
		return label.text = Text;
	}
}
{'fraction_non_alphanumeric': 0.11273792093704246, 'fraction_numerical': 0.009028794533918985, 'mean_word_length': 3.2921465968586388, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '78791', 'n_tokens_mistral': 1483, 'n_tokens_neox': 1317, 'n_words': 452}