123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- namespace SRF.UI
- {
- using Internal;
- using UnityEngine;
- using UnityEngine.EventSystems;
- using UnityEngine.UI;
- [RequireComponent(typeof (RectTransform))]
- [ExecuteInEditMode]
- [AddComponentMenu(ComponentMenuPaths.ContentFitText)]
- public class ContentFitText : UIBehaviour, ILayoutElement
- {
- public SRText CopySource;
- public Vector2 Padding;
- public float minWidth
- {
- get
- {
- if (CopySource == null)
- {
- return -1f;
- }
- return LayoutUtility.GetMinWidth(CopySource.rectTransform) + Padding.x;
- }
- }
- public float preferredWidth
- {
- get
- {
- if (CopySource == null)
- {
- return -1f;
- }
- return LayoutUtility.GetPreferredWidth(CopySource.rectTransform) + Padding.x;
- }
- }
- public float flexibleWidth
- {
- get
- {
- if (CopySource == null)
- {
- return -1f;
- }
- return LayoutUtility.GetFlexibleWidth(CopySource.rectTransform);
- }
- }
- public float minHeight
- {
- get
- {
- if (CopySource == null)
- {
- return -1f;
- }
- return LayoutUtility.GetFlexibleHeight(CopySource.rectTransform) + Padding.y;
- }
- }
- public float preferredHeight
- {
- get
- {
- if (CopySource == null)
- {
- return -1f;
- }
- return LayoutUtility.GetPreferredHeight(CopySource.rectTransform) + Padding.y;
- }
- }
- public float flexibleHeight
- {
- get
- {
- if (CopySource == null)
- {
- return -1f;
- }
- return LayoutUtility.GetFlexibleHeight(CopySource.rectTransform);
- }
- }
- public int layoutPriority
- {
- get { return 0; }
- }
- public void CalculateLayoutInputHorizontal()
- {
- CopySource.CalculateLayoutInputHorizontal();
- }
- public void CalculateLayoutInputVertical()
- {
- CopySource.CalculateLayoutInputVertical();
- }
- protected override void OnEnable()
- {
- SetDirty();
- CopySource.LayoutDirty += CopySourceOnLayoutDirty;
- }
- private void CopySourceOnLayoutDirty(SRText srText)
- {
- SetDirty();
- }
- protected override void OnTransformParentChanged()
- {
- SetDirty();
- }
- protected override void OnDisable()
- {
- CopySource.LayoutDirty -= CopySourceOnLayoutDirty;
- SetDirty();
- }
- protected override void OnDidApplyAnimationProperties()
- {
- SetDirty();
- }
- protected override void OnBeforeTransformParentChanged()
- {
- SetDirty();
- }
- protected void SetDirty()
- {
- if (!IsActive())
- {
- return;
- }
- LayoutRebuilder.MarkLayoutForRebuild(transform as RectTransform);
- }
- }
- }
|