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.

59 lines
1.9KB

  1. using UnityEngine;
  2. namespace TechbloxModdingAPI.Interface.IMGUI
  3. {
  4. /// <summary>
  5. /// An image.
  6. /// This wraps Unity's IMGUI Label.
  7. /// </summary>
  8. public class Image : UIElement
  9. {
  10. private bool automaticLayout = false;
  11. /// <summary>
  12. /// The image texture to display
  13. /// </summary>
  14. public Texture Texture { get; set; }
  15. /// <summary>
  16. /// The rectangular area in the window that the image can use
  17. /// </summary>
  18. public Rect Box { get; set; } = Rect.zero;
  19. public override void OnGUI()
  20. {
  21. //if (Texture == null) return;
  22. if (automaticLayout)
  23. {
  24. GUILayout.Label(Texture, Constants.Default.label);
  25. }
  26. else
  27. {
  28. GUI.Label(Box, Texture, Constants.Default.label);
  29. }
  30. }
  31. /// <summary>
  32. /// Initializes a new instance of the <see cref="T:TechbloxModdingAPI.Interface.IMGUI.Image"/> class with automatic layout.
  33. /// </summary>
  34. /// <param name="texture">Image to display.</param>
  35. /// <param name="name">The element's name.</param>
  36. public Image(Texture texture = null, string name = null) : base(texture == null ? "" : $"{texture.name}({texture.width}x{texture.height})", name)
  37. {
  38. automaticLayout = true;
  39. Texture = texture;
  40. }
  41. /// <summary>
  42. /// Initializes a new instance of the <see cref="T:TechbloxModdingAPI.Interface.IMGUI.Image"/> class.
  43. /// </summary>
  44. /// <param name="box">Rectangular area for the image.</param>
  45. /// <param name="texture">Image to display.</param>
  46. /// <param name="name">The element's name.</param>
  47. public Image(Rect box, Texture texture = null, string name = null) : this(texture, name)
  48. {
  49. this.Box = box;
  50. automaticLayout = false;
  51. }
  52. }
  53. }