public bool SetContent(string content)
 {
     if (m_Text == null)
     {
         return(false);
     }
     if (!m_Text.GetText().Equals(content))
     {
         m_Text.SetText(content);
         if (m_LabelAutoSize)
         {
             var newSize = string.IsNullOrEmpty(content) ? Vector2.zero :
                           new Vector2(m_Text.GetPreferredWidth(), m_Text.GetPreferredHeight());
             var sizeChange = newSize.x != m_TextRect.sizeDelta.x || newSize.y != m_TextRect.sizeDelta.y;
             if (sizeChange)
             {
                 m_TextRect.sizeDelta           = newSize;
                 m_TextRect.anchoredPosition3D  = new Vector3(m_LabelPaddingLeftRight, 0);
                 m_TextBackgroundRect.sizeDelta = new Vector2(m_Text.GetPreferredWidth() + m_LabelPaddingLeftRight * 2,
                                                              m_Text.GetPreferredHeight() + m_LabelPaddingTopBottom * 2 - 4);
             }
             m_Rect.sizeDelta = new Vector3(width, height);
             return(sizeChange);
         }
     }
     m_Rect.sizeDelta = new Vector3(width, height);
     return(false);
 }
Exemple #2
0
        public bool SetText(string text)
        {
            if (m_TextRect == null || m_LabelText == null)
            {
                return(false);
            }

            if (text == null)
            {
                text = "";
            }
            if (!m_LabelText.GetText().Equals(text))
            {
                m_LabelText.SetText(text);
                if (m_AutoSize)
                {
                    var newSize = string.IsNullOrEmpty(text) ? Vector2.zero :
                                  new Vector2(m_LabelText.GetPreferredWidth(),
                                              m_LabelText.GetPreferredHeight());
                    var sizeChange = newSize.x != m_TextRect.sizeDelta.x || newSize.y != m_TextRect.sizeDelta.y;
                    this.m_Width  = newSize.x;
                    this.m_Height = newSize.y;
                    if (sizeChange)
                    {
                        m_TextRect.sizeDelta = newSize;
                        UpdateSize();
                        UpdatePadding();
                        AdjustIconPos();
                    }
                    return(sizeChange);
                }
                AdjustIconPos();
                if (m_HideIconIfTextEmpty && isIconActive)
                {
                    ChartHelper.SetActive(m_IconImage.gameObject, !string.IsNullOrEmpty(text));
                }
            }
            return(false);
        }