説明なし
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

TabView.cs 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using System.Collections.Generic;
  2. using UnityEngine.UIElements;
  3. using Unity.PlasticSCM.Editor;
  4. namespace Unity.PlasticSCM.Editor.UI.UIElements
  5. {
  6. internal class TabView : VisualElement
  7. {
  8. internal TabView()
  9. {
  10. InitializeLayoutAndStyles();
  11. BuildComponents();
  12. }
  13. internal Button AddTab(string name, VisualElement content)
  14. {
  15. mTabs.Add(name, content);
  16. Button newButton = new Button()
  17. {
  18. text = name,
  19. name = name
  20. };
  21. newButton.AddToClassList("tab-button");
  22. mButtons.Add(name, newButton);
  23. newButton.clickable.clickedWithEventInfo += OnClickButton;
  24. mTabArea.Add(newButton);
  25. if (mTabs.Count == 1)
  26. ButtonClicked(newButton);
  27. return newButton;
  28. }
  29. internal void SwitchContent(VisualElement content)
  30. {
  31. mContentArea.Clear();
  32. mContentArea.Add(content);
  33. foreach (Button button in mButtons.Values)
  34. button.RemoveFromClassList("active");
  35. }
  36. void OnClickButton(EventBase eventBase)
  37. {
  38. ButtonClicked((Button)eventBase.target);
  39. }
  40. void ButtonClicked(Button clickedButton)
  41. {
  42. VisualElement content;
  43. mTabs.TryGetValue(clickedButton.text, out content);
  44. mContentArea.Clear();
  45. mContentArea.Add(content);
  46. foreach (Button button in mButtons.Values)
  47. button.RemoveFromClassList("active");
  48. clickedButton.AddToClassList("active");
  49. }
  50. void BuildComponents()
  51. {
  52. mTabArea = this.Query<VisualElement>("TabArea").First();
  53. mContentArea = this.Query<VisualElement>("ContentArea").First();
  54. }
  55. void InitializeLayoutAndStyles()
  56. {
  57. name = "TabView";
  58. this.LoadLayout(typeof(TabView).Name);
  59. this.LoadStyle(typeof(TabView).Name);
  60. }
  61. VisualElement mContentArea;
  62. VisualElement mTabArea;
  63. Dictionary<string, VisualElement> mTabs = new Dictionary<string, VisualElement>();
  64. Dictionary<string, Button> mButtons = new Dictionary<string, Button>();
  65. }
  66. }