Fix incorrect layout width for tabs on enable.
This commit is contained in:
@@ -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 m_layoutMinWidth = -1;
|
||||||
float ILayoutElement.minWidth { get { return m_layoutMinWidth; } }
|
float ILayoutElement.minWidth { get { return m_layoutMinWidth; } }
|
||||||
void UpdateLayoutMinWidth(float value) {
|
void UpdateLayoutMinWidth(float value) {
|
||||||
@@ -47,12 +56,7 @@ namespace Cryville.Crtr.Browsing.UI {
|
|||||||
|
|
||||||
PropertyTweener<float> _tweener;
|
PropertyTweener<float> _tweener;
|
||||||
void UpdateTweener() {
|
void UpdateTweener() {
|
||||||
var width = MinWidth;
|
_tweener.Start(GetTargetLayoutMinWidth(), m_tweenDuration);
|
||||||
if (Selected) {
|
|
||||||
var preferredWidth = LayoutUtility.GetPreferredWidth(transform as RectTransform);
|
|
||||||
if (preferredWidth > width) width = preferredWidth;
|
|
||||||
}
|
|
||||||
_tweener.Start(width, m_tweenDuration);
|
|
||||||
}
|
}
|
||||||
void Update() {
|
void Update() {
|
||||||
_tweener.Advance(Time.deltaTime);
|
_tweener.Advance(Time.deltaTime);
|
||||||
@@ -63,7 +67,7 @@ namespace Cryville.Crtr.Browsing.UI {
|
|||||||
|
|
||||||
protected override void OnEnable() {
|
protected override void OnEnable() {
|
||||||
base.OnEnable();
|
base.OnEnable();
|
||||||
m_layoutMinWidth = Selected ? -1 : MinWidth;
|
m_layoutMinWidth = GetTargetLayoutMinWidth();
|
||||||
if (_tweener == null)
|
if (_tweener == null)
|
||||||
_tweener = new PropertyTweener<float>(
|
_tweener = new PropertyTweener<float>(
|
||||||
() => m_layoutMinWidth,
|
() => m_layoutMinWidth,
|
||||||
|
Reference in New Issue
Block a user