No Description
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.

DrawTreeViewEmptyState.cs 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. using PlasticGui;
  2. using Unity.PlasticSCM.Editor.Help;
  3. using UnityEditor;
  4. using UnityEngine;
  5. namespace Unity.PlasticSCM.Editor.UI.Tree
  6. {
  7. internal static class DrawTreeViewEmptyState
  8. {
  9. internal static void For(
  10. Rect rect,
  11. string text)
  12. {
  13. GUIContent content = new GUIContent(text);
  14. Vector2 contentSize = GetContentSize(content);
  15. GUI.BeginGroup(rect);
  16. DrawLabel(
  17. content,
  18. contentSize,
  19. (rect.width - contentSize.x) / 2,
  20. rect.height / 2);
  21. GUI.EndGroup();
  22. }
  23. internal static void For(
  24. Rect rect,
  25. string text,
  26. Texture2D icon)
  27. {
  28. GUIContent content = new GUIContent(text);
  29. Vector2 contentSize = GetContentSize(content);
  30. GUI.BeginGroup(rect);
  31. DrawLabelWithIcon(
  32. content,
  33. contentSize,
  34. (rect.width - contentSize.x) / 2,
  35. rect.height / 2,
  36. icon);
  37. GUI.EndGroup();
  38. }
  39. internal static void For(
  40. Rect rect,
  41. string text,
  42. Texture2D icon,
  43. ExternalLink externalLink)
  44. {
  45. GUIContent textContent = new GUIContent(text);
  46. Vector2 textContentSize = GetContentSize(textContent);
  47. GUIContent linkContent = new GUIContent(externalLink.Label);
  48. Vector2 linkContentSize = GetContentSize(linkContent, EditorStyles.linkLabel);
  49. float textContentOffsetY = (rect.height - (textContentSize.y + linkContentSize.y)) / 2;
  50. float linkContentOffsetY = textContentOffsetY + textContentSize.y;
  51. GUI.BeginGroup(rect);
  52. DrawLabelWithIcon(
  53. textContent,
  54. textContentSize,
  55. (rect.width - textContentSize.x) / 2,
  56. textContentOffsetY,
  57. icon);
  58. DrawLink(
  59. externalLink,
  60. linkContent,
  61. linkContentSize,
  62. (rect.width - linkContentSize.x) / 2,
  63. linkContentOffsetY);
  64. GUI.EndGroup();
  65. }
  66. static void DrawLabel(
  67. GUIContent content,
  68. Vector2 contentSize,
  69. float offsetX,
  70. float offsetY)
  71. {
  72. GUI.Label(
  73. new Rect(offsetX, offsetY, contentSize.x, contentSize.y),
  74. content,
  75. UnityStyles.Tree.StatusLabel);
  76. }
  77. static void DrawLabelWithIcon(
  78. GUIContent content,
  79. Vector2 contentSize,
  80. float offsetX,
  81. float offsetY,
  82. Texture2D icon)
  83. {
  84. int iconSize = UnityConstants.TREEVIEW_STATUS_ICON_SIZE;
  85. int padding = UnityConstants.TREEVIEW_STATUS_CONTENT_PADDING;
  86. float iconOffsetX = offsetX - iconSize + padding;
  87. float contentOffsetX = offsetX + iconSize - padding;
  88. GUI.DrawTexture(
  89. new Rect(iconOffsetX, offsetY + padding, iconSize, iconSize),
  90. icon,
  91. ScaleMode.ScaleToFit);
  92. DrawLabel(
  93. content,
  94. contentSize,
  95. contentOffsetX,
  96. offsetY);
  97. }
  98. static void DrawLink(
  99. ExternalLink externalLink,
  100. GUIContent linkContent,
  101. Vector2 linkContentSize,
  102. float offsetX,
  103. float offsetY)
  104. {
  105. Rect buttonPosition = new Rect(
  106. offsetX,
  107. offsetY,
  108. linkContentSize.x,
  109. linkContentSize.y);
  110. EditorGUIUtility.AddCursorRect(buttonPosition, MouseCursor.Link);
  111. if (GUI.Button(buttonPosition, linkContent, EditorStyles.linkLabel))
  112. {
  113. Application.OpenURL(externalLink.Url);
  114. }
  115. }
  116. static Vector2 GetContentSize(GUIContent content)
  117. {
  118. return GetContentSize(content, UnityStyles.Tree.StatusLabel);
  119. }
  120. static Vector2 GetContentSize(GUIContent content, GUIStyle guiStyle)
  121. {
  122. return guiStyle.CalcSize(content);
  123. }
  124. }
  125. }