Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 23 additions & 22 deletions Editor/UIToolkit/Controls/TabController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public class TabController
{
readonly Dictionary<string, VisualElement> m_Tabs = new Dictionary<string, VisualElement>();

readonly ButtonStrip m_TabsButtons;
readonly ScrollView m_TabsContainer;
readonly ButtonStrip m_Buttons;
readonly ScrollView m_Container;

/// <summary>
/// Available tabs' labels.
Expand All @@ -28,7 +28,17 @@ public class TabController
/// <summary>
/// Active tab label from <see cref="Tabs"/>.
/// </summary>
public string ActiveTab => m_TabsButtons.Value;
public string ActiveTab => m_Buttons.Value;

/// <summary>
/// Button elements in the header of the control
/// </summary>
public ButtonStrip Buttons => m_Buttons;

/// <summary>
/// Container where tab content is displayed
/// </summary>
public ScrollView Container => m_Container;

/// <summary>
/// This constructor will looking for already existing elements:
Expand All @@ -38,8 +48,8 @@ public class TabController
/// <param name="root">Element that contains <see cref="ButtonStrip"/> and <see cref="ScrollView"/> named tabs-container</param>
public TabController(VisualElement root)
{
m_TabsButtons = root.Q<ButtonStrip>();
m_TabsContainer = root.Q<ScrollView>("tabs-container");
m_Buttons = root.Q<ButtonStrip>();
m_Container = root.Q<ScrollView>("tabs-container");

Init();
}
Expand All @@ -54,7 +64,7 @@ public void AddTab(string label, VisualElement content)
{
if (!m_Tabs.ContainsKey(label))
{
m_TabsButtons.AddChoice(label, label);
m_Buttons.AddChoice(label, label);
m_Tabs.Add(label, content);
content.viewDataKey = label;
}
Expand All @@ -75,16 +85,7 @@ public void ActivateTab(string label)
return;
}

m_TabsButtons.SetValue(label);
}

/// <summary>
/// Set the flexible growth property of tabs content container
/// </summary>
/// <param name="styleFloat"></param>
public void ContentContainerFlexGrow(StyleFloat styleFloat)
{
m_TabsContainer.contentContainer.style.flexGrow = styleFloat;
m_Buttons.SetValue(label);
}

/// <summary>
Expand All @@ -102,17 +103,17 @@ public void RefreshActiveTab()
tab.Value.RemoveFromHierarchy();
}

var element = m_Tabs.First(i => i.Key.Equals(m_TabsButtons.Value)).Value;
m_TabsContainer.Add(element);
var element = m_Tabs.First(i => i.Key.Equals(m_Buttons.Value)).Value;
m_Container.Add(element);
}

void Init()
{
Assert.IsNotNull(m_TabsButtons);
Assert.IsNotNull(m_TabsContainer);
Assert.IsNotNull(m_Buttons);
Assert.IsNotNull(m_Container);

m_TabsButtons.CleanUp();
m_TabsButtons.OnButtonClick += RefreshActiveTab;
m_Buttons.CleanUp();
m_Buttons.OnButtonClick += RefreshActiveTab;

RefreshActiveTab();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protected override PackageInfo GetPackageInfo()

protected override void OnActivate(string searchContext, VisualElement rootElement)
{
ContentContainerFlexGrow(1);
TabController.Container.contentContainer.style.flexGrow = 1;
AddTab("About", new AboutTab());
}

Expand Down
15 changes: 5 additions & 10 deletions Editor/UIToolkit/PreferencesWindow/PackagePreferencesWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public abstract class PackagePreferencesWindow
/// Structure describing a Unity Package.
/// </summary>
protected abstract UnityEditor.PackageManager.PackageInfo GetPackageInfo();


/// <summary>
/// Gets Path used to place the SettingsProvider in the tree view of the Preferences or Project Settings window.
Expand All @@ -35,6 +34,11 @@ public abstract class PackagePreferencesWindow
/// </summary>
protected abstract SettingsScope Scope { get; }

/// <summary>
/// Tab control element.
/// </summary>
protected TabController TabController => m_TabController;

/// <summary>
/// Add tab to the window top bar.
/// </summary>
Expand All @@ -55,15 +59,6 @@ protected void ActivateTab(string name)
m_TabController.ActivateTab(name);
}

/// <summary>
/// Set the flexible growth property of tabs content container
/// </summary>
/// <param name="styleFloat"></param>
protected void ContentContainerFlexGrow(StyleFloat styleFloat)
{
m_TabController.ContentContainerFlexGrow(styleFloat);
}

/// <summary>
/// Overrides SettingsProvider.OnActivate.
/// </summary>
Expand Down
9 changes: 0 additions & 9 deletions Editor/UIToolkit/SettingsWindow/PackageSettingsWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,6 @@ public abstract class PackageSettingsWindow<TWindow> : EditorWindow where TWindo
TabController m_TabController;
readonly string m_WindowUIFilesRootPath = $"{PluginsDevKitPackage.UIToolkitPath}/SettingsWindow";

/// <summary>
/// Set/Get the flexible growth property of tabs content container
/// </summary>
public StyleFloat ContentFlexGrow
{
get => m_TabsContainer.contentContainer.style.flexGrow;
set => m_TabsContainer.contentContainer.style.flexGrow = value;
}

void OnEnable()
{
// This is a workaround due to a very weird bug.
Expand Down