PRHelper.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using UnityEngine;
  2. namespace Paroxe.PdfRenderer.Internal
  3. {
  4. public class PRHelper : MonoBehaviour
  5. {
  6. static PRHelper()
  7. {
  8. s_Styles = new Styles();
  9. }
  10. public static bool GroupHeader(string text, bool isExpanded)
  11. {
  12. Rect rect = GUILayoutUtility.GetRect(20f, 18f, s_Styles.header);
  13. s_Styles.Backup();
  14. s_Styles.Apply();
  15. if (Event.current.type == EventType.Repaint)
  16. s_Styles.header.Draw(rect, text, isExpanded, isExpanded, isExpanded, isExpanded);
  17. Event e = Event.current;
  18. if (e.type == EventType.MouseDown)
  19. {
  20. if (rect.Contains(e.mousePosition))
  21. {
  22. isExpanded = !isExpanded;
  23. e.Use();
  24. }
  25. }
  26. s_Styles.Revert();
  27. return isExpanded;
  28. }
  29. private static Styles s_Styles;
  30. private class Styles
  31. {
  32. public GUIStyle header = "ShurikenModuleTitle";
  33. internal Styles()
  34. {
  35. header.font = (new GUIStyle("Label")).font;
  36. }
  37. RectOffset m_Border;
  38. float m_FixedHeight;
  39. Vector2 m_ContentOffset;
  40. TextAnchor m_TextAlign;
  41. FontStyle m_TextStyle;
  42. int m_FontSize;
  43. RectOffset m_Margin;
  44. public void Backup()
  45. {
  46. m_Border = s_Styles.header.border;
  47. m_FixedHeight = s_Styles.header.fixedHeight;
  48. m_ContentOffset = s_Styles.header.contentOffset;
  49. m_TextAlign = s_Styles.header.alignment;
  50. m_TextStyle = s_Styles.header.fontStyle;
  51. m_FontSize = s_Styles.header.fontSize;
  52. m_Margin = s_Styles.header.margin;
  53. }
  54. public void Apply()
  55. {
  56. s_Styles.header.border = new RectOffset(7, 7, 4, 4);
  57. s_Styles.header.fixedHeight = 18;
  58. s_Styles.header.contentOffset = new Vector2(3f, -2f);
  59. s_Styles.header.alignment = TextAnchor.MiddleLeft;
  60. s_Styles.header.fontStyle = FontStyle.Normal;
  61. s_Styles.header.fontSize = 11;
  62. s_Styles.header.margin = new RectOffset(0, 0, 0, 0);
  63. }
  64. public void Revert()
  65. {
  66. s_Styles.header.border = m_Border;
  67. s_Styles.header.fixedHeight = m_FixedHeight;
  68. s_Styles.header.contentOffset = m_ContentOffset;
  69. s_Styles.header.alignment = m_TextAlign;
  70. s_Styles.header.fontStyle = m_TextStyle;
  71. s_Styles.header.fontSize = m_FontSize;
  72. s_Styles.header.margin = m_Margin;
  73. }
  74. }
  75. }
  76. }