59 lines
No EOL
1.5 KiB
C#
59 lines
No EOL
1.5 KiB
C#
using UnityEngine;
|
|
|
|
namespace GamecraftModdingAPI.Interface.IMGUI
|
|
{
|
|
/// <summary>
|
|
/// A simple text label.
|
|
/// This wraps Unity IMGUI's Label.
|
|
/// </summary>
|
|
public class Label : UIElement
|
|
{
|
|
private bool automaticLayout = false;
|
|
|
|
/// <summary>
|
|
/// String to display on the label.
|
|
/// </summary>
|
|
public string Text { get; set; }
|
|
|
|
/// <summary>
|
|
/// The rectangular area that the label can use.
|
|
/// </summary>
|
|
public Rect Box { get; set; } = Rect.zero;
|
|
|
|
public void OnGUI()
|
|
{
|
|
if (automaticLayout)
|
|
{
|
|
GUILayout.Label(Text, Constants.Default.label);
|
|
}
|
|
else
|
|
{
|
|
GUI.Label(Box, Text, Constants.Default.label);
|
|
}
|
|
}
|
|
|
|
public string Name { get; }
|
|
public bool Enabled { set; get; } = true;
|
|
|
|
public Label(string initialText = null, string name = null)
|
|
{
|
|
automaticLayout = true;
|
|
Text = initialText;
|
|
if (name == null)
|
|
{
|
|
this.Name = typeof(Label).FullName + "::" + initialText;
|
|
}
|
|
else
|
|
{
|
|
this.Name = name;
|
|
}
|
|
IMGUIManager.AddElement(this);
|
|
}
|
|
|
|
public Label(Rect box, string initialText = null, string name = null) : this(initialText, name)
|
|
{
|
|
this.Box = box;
|
|
automaticLayout = false;
|
|
}
|
|
}
|
|
} |