A stable modding interface between Techblox and mods https://mod.exmods.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Label.cs 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using UnityEngine;
  2. namespace GamecraftModdingAPI.Interface.IMGUI
  3. {
  4. /// <summary>
  5. /// A simple text label.
  6. /// This wraps Unity IMGUI's Label.
  7. /// </summary>
  8. public class Label : UIElement
  9. {
  10. private bool automaticLayout = false;
  11. /// <summary>
  12. /// String to display on the label.
  13. /// </summary>
  14. public string Text { get; set; }
  15. /// <summary>
  16. /// The rectangular area that the label can use.
  17. /// </summary>
  18. public Rect Box { get; set; } = Rect.zero;
  19. public void OnGUI()
  20. {
  21. if (automaticLayout)
  22. {
  23. GUILayout.Label(Text, Constants.Default.label);
  24. }
  25. else
  26. {
  27. GUI.Label(Box, Text, Constants.Default.label);
  28. }
  29. }
  30. /// <summary>
  31. /// The label's unique name.
  32. /// </summary>
  33. public string Name { get; }
  34. /// <summary>
  35. /// Whether to display the label.
  36. /// </summary>
  37. public bool Enabled { set; get; } = true;
  38. /// <summary>
  39. /// Initializes a new instance of the <see cref="T:GamecraftModdingAPI.Interface.IMGUI.Label"/> class with automatic layout.
  40. /// </summary>
  41. /// <param name="initialText">Initial string to display on the label.</param>
  42. /// <param name="name">The element's name.</param>
  43. public Label(string initialText = null, string name = null)
  44. {
  45. automaticLayout = true;
  46. Text = initialText;
  47. if (name == null)
  48. {
  49. this.Name = typeof(Label).FullName + "::" + initialText;
  50. }
  51. else
  52. {
  53. this.Name = name;
  54. }
  55. IMGUIManager.AddElement(this);
  56. }
  57. /// <summary>
  58. /// Initializes a new instance of the <see cref="T:GamecraftModdingAPI.Interface.IMGUI.Label"/>.
  59. /// </summary>
  60. /// <param name="box">Rectangular area for the label.</param>
  61. /// <param name="initialText">Initial string to display on the label.</param>
  62. /// <param name="name">The element's name.</param>
  63. public Label(Rect box, string initialText = null, string name = null) : this(initialText, name)
  64. {
  65. this.Box = box;
  66. automaticLayout = false;
  67. }
  68. }
  69. }