123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- using System.Collections.Generic;
-
- using UnityEngine.UIElements;
-
- using Unity.PlasticSCM.Editor;
-
- namespace Unity.PlasticSCM.Editor.UI.UIElements
- {
- internal class TabView : VisualElement
- {
- internal TabView()
- {
- InitializeLayoutAndStyles();
-
- BuildComponents();
- }
-
- internal Button AddTab(string name, VisualElement content)
- {
- mTabs.Add(name, content);
-
- Button newButton = new Button()
- {
- text = name,
- name = name
- };
- newButton.AddToClassList("tab-button");
-
- mButtons.Add(name, newButton);
-
- newButton.clickable.clickedWithEventInfo += OnClickButton;
-
- mTabArea.Add(newButton);
-
- if (mTabs.Count == 1)
- ButtonClicked(newButton);
-
- return newButton;
- }
-
- internal void SwitchContent(VisualElement content)
- {
- mContentArea.Clear();
- mContentArea.Add(content);
-
- foreach (Button button in mButtons.Values)
- button.RemoveFromClassList("active");
- }
-
- void OnClickButton(EventBase eventBase)
- {
- ButtonClicked((Button)eventBase.target);
- }
-
- void ButtonClicked(Button clickedButton)
- {
- VisualElement content;
- mTabs.TryGetValue(clickedButton.text, out content);
-
- mContentArea.Clear();
- mContentArea.Add(content);
-
- foreach (Button button in mButtons.Values)
- button.RemoveFromClassList("active");
-
- clickedButton.AddToClassList("active");
- }
-
- void BuildComponents()
- {
- mTabArea = this.Query<VisualElement>("TabArea").First();
- mContentArea = this.Query<VisualElement>("ContentArea").First();
- }
-
- void InitializeLayoutAndStyles()
- {
- name = "TabView";
-
- this.LoadLayout(typeof(TabView).Name);
-
- this.LoadStyle(typeof(TabView).Name);
- }
-
- VisualElement mContentArea;
- VisualElement mTabArea;
-
- Dictionary<string, VisualElement> mTabs = new Dictionary<string, VisualElement>();
- Dictionary<string, Button> mButtons = new Dictionary<string, Button>();
- }
- }
|