From b45cf9cba79d79daf5d8019d50015ad669f19cf4 Mon Sep 17 00:00:00 2001 From: PopSlime Date: Sun, 12 Nov 2023 01:05:06 +0800 Subject: [PATCH] Fix incorrect layout width for tabs on enable. --- .../Crtr/Browsing/UI/BrowserTabLayout.cs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/Assets/Cryville/Crtr/Browsing/UI/BrowserTabLayout.cs b/Assets/Cryville/Crtr/Browsing/UI/BrowserTabLayout.cs index e7b31f2..68326e0 100644 --- a/Assets/Cryville/Crtr/Browsing/UI/BrowserTabLayout.cs +++ b/Assets/Cryville/Crtr/Browsing/UI/BrowserTabLayout.cs @@ -17,6 +17,15 @@ namespace Cryville.Crtr.Browsing.UI { } } + float GetTargetLayoutMinWidth() { + var width = MinWidth; + if (Selected) { + var preferredWidth = LayoutUtility.GetPreferredWidth(transform as RectTransform); + if (preferredWidth > width) width = preferredWidth; + } + return width; + } + float m_layoutMinWidth = -1; float ILayoutElement.minWidth { get { return m_layoutMinWidth; } } void UpdateLayoutMinWidth(float value) { @@ -47,12 +56,7 @@ namespace Cryville.Crtr.Browsing.UI { PropertyTweener _tweener; void UpdateTweener() { - var width = MinWidth; - if (Selected) { - var preferredWidth = LayoutUtility.GetPreferredWidth(transform as RectTransform); - if (preferredWidth > width) width = preferredWidth; - } - _tweener.Start(width, m_tweenDuration); + _tweener.Start(GetTargetLayoutMinWidth(), m_tweenDuration); } void Update() { _tweener.Advance(Time.deltaTime); @@ -63,7 +67,7 @@ namespace Cryville.Crtr.Browsing.UI { protected override void OnEnable() { base.OnEnable(); - m_layoutMinWidth = Selected ? -1 : MinWidth; + m_layoutMinWidth = GetTargetLayoutMinWidth(); if (_tweener == null) _tweener = new PropertyTweener( () => m_layoutMinWidth,