using UnityEngine;
namespace GamecraftModdingAPI.Interface.IMGUI
{
///
/// An image.
/// This wraps Unity's IMGUI Label.
///
public class Image : UIElement
{
private bool automaticLayout = false;
///
/// The image texture to display
///
public Texture Texture { get; set; }
///
/// The rectangular area in the window that the image can use
///
public Rect Box { get; set; } = Rect.zero;
public void OnGUI()
{
//if (Texture == null) return;
if (automaticLayout)
{
GUILayout.Label(Texture, Constants.Default.label);
}
else
{
GUI.Label(Box, Texture, Constants.Default.label);
}
}
///
/// The image element's unique name.
///
public string Name { get; }
///
/// Whether to display the image and everything in it.
///
public bool Enabled { set; get; } = true;
///
/// Initializes a new instance of the class with automatic layout.
///
/// Image to display.
/// The element's name.
public Image(Texture texture = null, string name = null)
{
automaticLayout = true;
Texture = texture;
if (name == null)
{
if (texture == null)
{
this.Name = typeof(Image).FullName + "::" + texture;
}
else
{
this.Name = typeof(Image).FullName + "::" + texture.name + "(" + texture.width + "x" + texture.height + ")";
}
}
else
{
this.Name = name;
}
IMGUIManager.AddElement(this);
}
///
/// Initializes a new instance of the class.
///
/// Rectangular area for the image.
/// Image to display.
/// The element's name.
public Image(Rect box, Texture texture = null, string name = null) : this(texture, name)
{
this.Box = box;
automaticLayout = false;
}
}
}