diff --git a/Plugins/DynamicPanels/Scripts/Helpers/PanelTab.cs b/Plugins/DynamicPanels/Scripts/Helpers/PanelTab.cs index 823bd81..5e6422a 100644 --- a/Plugins/DynamicPanels/Scripts/Helpers/PanelTab.cs +++ b/Plugins/DynamicPanels/Scripts/Helpers/PanelTab.cs @@ -1,4 +1,5 @@ using UnityEngine; +using UnityEngine.Assertions; using UnityEngine.EventSystems; using UnityEngine.UI; @@ -24,6 +25,7 @@ public void Initialize( Panel panel, RectTransform content ) { tab.m_panel = panel; tab.Content = content; + tab.MinSize = content.rect.size; } public void ChangeCloseButtonVisibility( bool isVisible ) @@ -100,6 +102,8 @@ public Vector2 MinSize { if( m_minSize != value ) { + if (value.x < 0) value = new Vector2(-value.x, value.y); + if (value.y < 0) value = new Vector2(value.x, -value.y); m_minSize = value; m_panel.Internal.RecalculateMinSize(); } @@ -133,7 +137,7 @@ public string Label private void Awake() { - m_minSize = new Vector2( 100f, 100f ); + m_minSize = new Vector2( -1f, -1f ); Internal = new InternalSettings( this ); iconHolder.preserveAspect = true; diff --git a/Plugins/DynamicPanels/Scripts/Panel.cs b/Plugins/DynamicPanels/Scripts/Panel.cs index c48d9b2..ec08a83 100644 --- a/Plugins/DynamicPanels/Scripts/Panel.cs +++ b/Plugins/DynamicPanels/Scripts/Panel.cs @@ -273,7 +273,7 @@ public void OnApplicationQuit() public Vector2 Position { get { return RectTransform.anchoredPosition; } } public Vector2 Size { get { return RectTransform.sizeDelta; } } - private Vector2 m_minSize = new Vector2( 200f, 200f ); + private Vector2 m_minSize = new Vector2( -1f, -1f ); public Vector2 MinSize { get { return m_minSize; } @@ -450,6 +450,7 @@ public PanelTab AddTab( RectTransform tabContent, int tabIndex = -1 ) tabIndex = tabs.Count; int thisTabIndex = GetTabIndex( tabContent ); + Vector2? newTabContentSize = null; if( thisTabIndex == -1 ) { PanelTab tab = PanelUtils.GetAssociatedTab( tabContent ); @@ -458,6 +459,7 @@ public PanelTab AddTab( RectTransform tabContent, int tabIndex = -1 ) tab = (PanelTab) Instantiate( Resources.Load( "DynamicPanelTab" ), tabsParent, false ); tabs.Insert( tabIndex, tab ); + newTabContentSize = tabContent.rect.size; tabContent.anchorMin = Vector2.zero; tabContent.anchorMax = Vector2.one; tabContent.sizeDelta = Vector2.zero; @@ -475,8 +477,9 @@ public PanelTab AddTab( RectTransform tabContent, int tabIndex = -1 ) } tab.Internal.Initialize( this, tabContent ); + if (newTabContentSize != null) tab.MinSize = newTabContentSize.Value; tab.Internal.RectTransform.SetSiblingIndex( tabIndex ); - + tabContent.SetParent( null, false ); // workaround for a rare internal Unity crash tabContent.SetParent( contentParent, false );