Implement drafted new UI.
This commit is contained in:
100
Assets/Cryville/Crtr/Browsing/UI/BrowserTabLayout.cs
Normal file
100
Assets/Cryville/Crtr/Browsing/UI/BrowserTabLayout.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
using Cryville.Common;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Cryville.Crtr.Browsing.UI {
|
||||
[ExecuteAlways]
|
||||
internal class BrowserTabLayout : UIBehaviour, ILayoutElement {
|
||||
[SerializeField]
|
||||
float m_minWidth = 150;
|
||||
public float MinWidth {
|
||||
get { return m_minWidth; }
|
||||
set {
|
||||
if (m_minWidth == value) return;
|
||||
m_minWidth = value;
|
||||
UpdateTweener();
|
||||
}
|
||||
}
|
||||
|
||||
float m_layoutMinWidth = -1;
|
||||
float ILayoutElement.minWidth { get { return m_layoutMinWidth; } }
|
||||
void UpdateLayoutMinWidth(float value) {
|
||||
if (m_layoutMinWidth == value) return;
|
||||
m_layoutMinWidth = value;
|
||||
SetDirty();
|
||||
}
|
||||
|
||||
public float preferredWidth { get { return -1; } }
|
||||
public float flexibleWidth { get { return -1; } }
|
||||
public float minHeight { get { return -1; } }
|
||||
public float preferredHeight { get { return -1; } }
|
||||
public float flexibleHeight { get { return -1; } }
|
||||
public int layoutPriority { get { return 1; } }
|
||||
|
||||
bool m_selected;
|
||||
public bool Selected {
|
||||
get { return m_selected; }
|
||||
set {
|
||||
if (m_selected == value) return;
|
||||
m_selected = value;
|
||||
UpdateTweener();
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
float m_tweenDuration = 0.2f;
|
||||
|
||||
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);
|
||||
}
|
||||
void Update() {
|
||||
_tweener.Advance(Time.deltaTime);
|
||||
}
|
||||
|
||||
public void CalculateLayoutInputHorizontal() { }
|
||||
public void CalculateLayoutInputVertical() { }
|
||||
|
||||
protected override void OnEnable() {
|
||||
base.OnEnable();
|
||||
m_layoutMinWidth = Selected ? -1 : MinWidth;
|
||||
if (_tweener == null)
|
||||
_tweener = new PropertyTweener<float>(
|
||||
() => m_layoutMinWidth,
|
||||
v => UpdateLayoutMinWidth(v),
|
||||
Tweeners.Float.With(EasingFunctions.OutQuad)
|
||||
);
|
||||
SetDirty();
|
||||
}
|
||||
protected override void OnBeforeTransformParentChanged() {
|
||||
base.OnBeforeTransformParentChanged();
|
||||
SetDirty();
|
||||
}
|
||||
protected override void OnTransformParentChanged() {
|
||||
base.OnTransformParentChanged();
|
||||
SetDirty();
|
||||
}
|
||||
protected override void OnDidApplyAnimationProperties() {
|
||||
base.OnDidApplyAnimationProperties();
|
||||
SetDirty();
|
||||
}
|
||||
protected override void OnValidate() {
|
||||
base.OnValidate();
|
||||
SetDirty();
|
||||
}
|
||||
protected override void OnDisable() {
|
||||
SetDirty();
|
||||
base.OnDisable();
|
||||
}
|
||||
void SetDirty() {
|
||||
if (!IsActive()) return;
|
||||
LayoutRebuilder.MarkLayoutForRebuild(transform as RectTransform);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user