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 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. public string Name { get; }
  31. public bool Enabled { set; get; } = true;
  32. public Label(string initialText = null, string name = null)
  33. {
  34. automaticLayout = true;
  35. Text = initialText;
  36. if (name == null)
  37. {
  38. this.Name = typeof(Label).FullName + "::" + initialText;
  39. }
  40. else
  41. {
  42. this.Name = name;
  43. }
  44. IMGUIManager.AddElement(this);
  45. }
  46. public Label(Rect box, string initialText = null, string name = null) : this(initialText, name)
  47. {
  48. this.Box = box;
  49. automaticLayout = false;
  50. }
  51. }
  52. }