|
- 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);
- }
- }
-
- /// <summary>
- /// The label's unique name.
- /// </summary>
- public string Name { get; }
-
- /// <summary>
- /// Whether to display the label.
- /// </summary>
- public bool Enabled { set; get; } = true;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="T:GamecraftModdingAPI.Interface.IMGUI.Label"/> class with automatic layout.
- /// </summary>
- /// <param name="initialText">Initial string to display on the label.</param>
- /// <param name="name">The element's name.</param>
- 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);
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="T:GamecraftModdingAPI.Interface.IMGUI.Label"/>.
- /// </summary>
- /// <param name="box">Rectangular area for the label.</param>
- /// <param name="initialText">Initial string to display on the label.</param>
- /// <param name="name">The element's name.</param>
- public Label(Rect box, string initialText = null, string name = null) : this(initialText, name)
- {
- this.Box = box;
- automaticLayout = false;
- }
- }
- }
|