Fix incorrect layout width for tabs on enable.

This commit is contained in:
2023-11-12 01:05:06 +08:00
parent 28234d9587
commit b45cf9cba7

View File

@@ -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<float> _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<float>(
() => m_layoutMinWidth,