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.

58 lines
1.9KB

  1. using UnityEngine;
  2. namespace TechbloxModdingAPI.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 override 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. /// Initializes a new instance of the <see cref="T:TechbloxModdingAPI.Interface.IMGUI.Label"/> class with automatic layout.
  32. /// </summary>
  33. /// <param name="initialText">Initial string to display on the label.</param>
  34. /// <param name="name">The element's name.</param>
  35. public Label(string initialText = null, string name = null) : base(initialText, name)
  36. {
  37. automaticLayout = true;
  38. Text = initialText;
  39. }
  40. /// <summary>
  41. /// Initializes a new instance of the <see cref="T:TechbloxModdingAPI.Interface.IMGUI.Label"/>.
  42. /// </summary>
  43. /// <param name="box">Rectangular area for the label.</param>
  44. /// <param name="initialText">Initial string to display on the label.</param>
  45. /// <param name="name">The element's name.</param>
  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. }