From 3d56ff19437c60fa085614beff0d2d1a175db382 Mon Sep 17 00:00:00 2001 From: Pavel Klymentenko Date: Thu, 28 Sep 2023 09:11:13 +0200 Subject: [PATCH] fix: fixed compilation error, removed special method to set a content flexGrow of a Tab Control --- Editor/UIToolkit/Controls/TabController.cs | 45 ++++++++++--------- .../AboutPreferencesWindow.cs | 2 +- .../PackagePreferencesWindow.cs | 15 +++---- .../SettingsWindow/PackageSettingsWindow.cs | 9 ---- 4 files changed, 29 insertions(+), 42 deletions(-) diff --git a/Editor/UIToolkit/Controls/TabController.cs b/Editor/UIToolkit/Controls/TabController.cs index 8a5451f..4076e91 100644 --- a/Editor/UIToolkit/Controls/TabController.cs +++ b/Editor/UIToolkit/Controls/TabController.cs @@ -17,8 +17,8 @@ public class TabController { readonly Dictionary m_Tabs = new Dictionary(); - readonly ButtonStrip m_TabsButtons; - readonly ScrollView m_TabsContainer; + readonly ButtonStrip m_Buttons; + readonly ScrollView m_Container; /// /// Available tabs' labels. @@ -28,7 +28,17 @@ public class TabController /// /// Active tab label from . /// - public string ActiveTab => m_TabsButtons.Value; + public string ActiveTab => m_Buttons.Value; + + /// + /// Button elements in the header of the control + /// + public ButtonStrip Buttons => m_Buttons; + + /// + /// Container where tab content is displayed + /// + public ScrollView Container => m_Container; /// /// This constructor will looking for already existing elements: @@ -38,8 +48,8 @@ public class TabController /// Element that contains and named tabs-container public TabController(VisualElement root) { - m_TabsButtons = root.Q(); - m_TabsContainer = root.Q("tabs-container"); + m_Buttons = root.Q(); + m_Container = root.Q("tabs-container"); Init(); } @@ -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; } @@ -75,16 +85,7 @@ public void ActivateTab(string label) return; } - m_TabsButtons.SetValue(label); - } - - /// - /// Set the flexible growth property of tabs content container - /// - /// - public void ContentContainerFlexGrow(StyleFloat styleFloat) - { - m_TabsContainer.contentContainer.style.flexGrow = styleFloat; + m_Buttons.SetValue(label); } /// @@ -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(); } diff --git a/Editor/UIToolkit/PreferencesWindow/AboutPreferencesWindow.cs b/Editor/UIToolkit/PreferencesWindow/AboutPreferencesWindow.cs index c1a6900..17d6462 100644 --- a/Editor/UIToolkit/PreferencesWindow/AboutPreferencesWindow.cs +++ b/Editor/UIToolkit/PreferencesWindow/AboutPreferencesWindow.cs @@ -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()); } diff --git a/Editor/UIToolkit/PreferencesWindow/PackagePreferencesWindow.cs b/Editor/UIToolkit/PreferencesWindow/PackagePreferencesWindow.cs index 56a94c8..44720c1 100644 --- a/Editor/UIToolkit/PreferencesWindow/PackagePreferencesWindow.cs +++ b/Editor/UIToolkit/PreferencesWindow/PackagePreferencesWindow.cs @@ -21,7 +21,6 @@ public abstract class PackagePreferencesWindow /// Structure describing a Unity Package. /// protected abstract UnityEditor.PackageManager.PackageInfo GetPackageInfo(); - /// /// Gets Path used to place the SettingsProvider in the tree view of the Preferences or Project Settings window. @@ -35,6 +34,11 @@ public abstract class PackagePreferencesWindow /// protected abstract SettingsScope Scope { get; } + /// + /// Tab control element. + /// + protected TabController TabController => m_TabController; + /// /// Add tab to the window top bar. /// @@ -55,15 +59,6 @@ protected void ActivateTab(string name) m_TabController.ActivateTab(name); } - /// - /// Set the flexible growth property of tabs content container - /// - /// - protected void ContentContainerFlexGrow(StyleFloat styleFloat) - { - m_TabController.ContentContainerFlexGrow(styleFloat); - } - /// /// Overrides SettingsProvider.OnActivate. /// diff --git a/Editor/UIToolkit/SettingsWindow/PackageSettingsWindow.cs b/Editor/UIToolkit/SettingsWindow/PackageSettingsWindow.cs index b2b0356..2898602 100644 --- a/Editor/UIToolkit/SettingsWindow/PackageSettingsWindow.cs +++ b/Editor/UIToolkit/SettingsWindow/PackageSettingsWindow.cs @@ -21,15 +21,6 @@ public abstract class PackageSettingsWindow : EditorWindow where TWindo TabController m_TabController; readonly string m_WindowUIFilesRootPath = $"{PluginsDevKitPackage.UIToolkitPath}/SettingsWindow"; - /// - /// Set/Get the flexible growth property of tabs content container - /// - 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.