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.

TestRunnerGUI.cs 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System;
  2. using UnityEditor.TestTools.TestRunner.GUI.Controls;
  3. using UnityEngine;
  4. namespace UnityEditor.TestTools.TestRunner.GUI
  5. {
  6. internal static class TestRunnerGUI
  7. {
  8. private static Styles s_Styles;
  9. private static Styles Style => s_Styles ?? (s_Styles = new Styles());
  10. internal static void TestPlatformSelectionDropDown(ISelectionDropDownContentProvider contentProvider)
  11. {
  12. var text = Style.TestPlatformButtonString;
  13. for (int i = 0; i < contentProvider.Count; i++)
  14. {
  15. if (contentProvider.IsSelected(i))
  16. {
  17. text += " " + contentProvider.GetName(i);
  18. break;
  19. }
  20. }
  21. var content = new GUIContent(text);
  22. SelectionDropDown(contentProvider, content, GUILayout.Width(EditorStyles.toolbarDropDown.CalcSize(content).x));
  23. }
  24. internal static void CategorySelectionDropDown(ISelectionDropDownContentProvider contentProvider)
  25. {
  26. SelectionDropDown(contentProvider, Style.CategoryButtonContent, GUILayout.Width(Style.CategoryButtonWidth));
  27. }
  28. private static void SelectionDropDown(ISelectionDropDownContentProvider listContentProvider, GUIContent buttonContent,
  29. params GUILayoutOption[] options)
  30. {
  31. var rect = EditorGUILayout.GetControlRect(false, EditorGUI.kSingleLineHeight, Styles.DropdownButton, options);
  32. if (!EditorGUI.DropdownButton(rect, buttonContent, FocusType.Passive, Styles.DropdownButton))
  33. {
  34. return;
  35. }
  36. var selectionDropDown = new SelectionDropDown(listContentProvider);
  37. PopupWindow.Show(rect, selectionDropDown);
  38. }
  39. private class Styles
  40. {
  41. public static readonly GUIStyle DropdownButton = EditorStyles.toolbarDropDown;
  42. public readonly string TestPlatformButtonString = "Run Location:";
  43. public readonly GUIContent CategoryButtonContent = new GUIContent("Category");
  44. public readonly float CategoryButtonWidth;
  45. public Styles()
  46. {
  47. CategoryButtonWidth = DropdownButton.CalcSize(CategoryButtonContent).x;
  48. }
  49. }
  50. }
  51. }