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.

DropDownTextField.cs 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using System.Collections.Generic;
  2. using UnityEditor;
  3. using UnityEngine;
  4. namespace Unity.PlasticSCM.Editor.UI
  5. {
  6. internal static class DropDownTextField
  7. {
  8. internal static string DoDropDownTextField(
  9. string text,
  10. string controlName,
  11. List<string> dropDownOptions,
  12. GenericMenu.MenuFunction2 optionSelected,
  13. params GUILayoutOption[] options)
  14. {
  15. GUIContent textContent = new GUIContent(text);
  16. Rect textFieldRect = GUILayoutUtility.GetRect(
  17. textContent,
  18. EditorStyles.textField,
  19. options);
  20. return DoDropDownTextField(
  21. text,
  22. controlName,
  23. dropDownOptions,
  24. optionSelected,
  25. textFieldRect);
  26. }
  27. internal static string DoDropDownTextField(
  28. string text,
  29. string controlName,
  30. List<string> dropDownOptions,
  31. GenericMenu.MenuFunction2 optionSelected,
  32. Rect textFieldRect)
  33. {
  34. Texture popupIcon = Images.GetDropDownIcon();
  35. Rect popupButtonRect = new Rect(
  36. textFieldRect.x + textFieldRect.width - BUTTON_WIDTH,
  37. textFieldRect.y,
  38. BUTTON_WIDTH,
  39. textFieldRect.height);
  40. if (GUI.Button(popupButtonRect, string.Empty, EditorStyles.label))
  41. {
  42. GenericMenu menu = new GenericMenu();
  43. foreach (string option in dropDownOptions)
  44. {
  45. menu.AddItem(
  46. new GUIContent(UnityMenuItem.EscapedText(option)),
  47. false,
  48. optionSelected,
  49. option);
  50. }
  51. menu.DropDown(textFieldRect);
  52. }
  53. Rect popupIconRect = new Rect(
  54. popupButtonRect.x,
  55. popupButtonRect.y + UnityConstants.DROPDOWN_ICON_Y_OFFSET,
  56. popupButtonRect.width,
  57. popupButtonRect.height);
  58. GUI.SetNextControlName(controlName);
  59. string result = GUI.TextField(textFieldRect, text);
  60. GUI.Label(popupIconRect, popupIcon);
  61. return result;
  62. }
  63. const int BUTTON_WIDTH = 16;
  64. }
  65. }