Пример #1
0
        public string GetLimitContent(string content)
        {
            float checkWidth = m_MaxWidth > 0 ? m_MaxWidth : m_RelatedTextWidth;

            if (m_RelatedText == null || checkWidth <= 0)
            {
                return(content);
            }
            else
            {
                if (m_Enable)
                {
                    float len       = m_RelatedText.GetPreferredWidth(content);
                    float suffixLen = m_RelatedText.GetPreferredWidth(suffix);
                    if (len >= checkWidth - m_Gap * 2)
                    {
                        return(content.Substring(0, GetAdaptLength(content, suffixLen)) + suffix);
                    }
                    else
                    {
                        return(content);
                    }
                }
                else
                {
                    return(content);
                }
            }
        }
Пример #2
0
 public bool SetText(string text)
 {
     if (m_LabelRect == null)
     {
         return(false);
     }
     if (m_LabelText != null && !m_LabelText.GetText().Equals(text))
     {
         m_LabelText.SetText(text);
         if (m_LabelAutoSize)
         {
             var newSize = string.IsNullOrEmpty(text) ? Vector2.zero :
                           new Vector2(m_LabelText.GetPreferredWidth() + m_LabelPaddingLeftRight * 2,
                                       m_LabelText.GetPreferredHeight() + m_LabelPaddingTopBottom * 2);
             var sizeChange = newSize.x != m_LabelRect.sizeDelta.x || newSize.y != m_LabelRect.sizeDelta.y;
             if (sizeChange)
             {
                 m_LabelRect.sizeDelta  = newSize;
                 m_ObjectRect.sizeDelta = newSize;
             }
             return(sizeChange);
         }
     }
     return(false);
 }
Пример #3
0
 internal void UpdateTooptipLabelText(string text)
 {
     if (m_TooltipLabelText != null)
     {
         m_TooltipLabelText.SetText(text);
         m_TooltipLabelRect.sizeDelta = new Vector2(m_TooltipLabelText.GetPreferredWidth() + 8,
                                                    m_TooltipLabelText.GetPreferredHeight() + 8);
     }
 }
Пример #4
0
 /// <summary>
 /// 设置提示框文本内容
 /// </summary>
 /// <param name="txt"></param>
 public void UpdateContentText(string txt)
 {
     if (m_ContentText != null)
     {
         m_ContentText.SetText(txt);
         float wid, hig;
         if (m_FixedWidth > 0)
         {
             wid = m_FixedWidth;
         }
         else if (m_MinWidth > 0 && m_ContentText.GetPreferredWidth() < m_MinWidth)
         {
             wid = m_MinWidth;
         }
         else
         {
             wid = m_ContentText.GetPreferredWidth() + m_PaddingLeftRight * 2;
         }
         if (m_FixedHeight > 0)
         {
             hig = m_FixedHeight;
         }
         else if (m_MinHeight > 0 && m_ContentText.GetPreferredHeight() < m_MinHeight)
         {
             hig = m_MinHeight;
         }
         else
         {
             hig = m_ContentText.GetPreferredHeight() + m_PaddingTopBottom * 2;
         }
         if (m_ContentRect != null)
         {
             m_ContentRect.sizeDelta = new Vector2(wid, hig);
         }
         if (m_ContentTextRect != null)
         {
             m_ContentTextRect.anchoredPosition = new Vector3(m_PaddingLeftRight, -m_PaddingTopBottom);
         }
     }
 }
Пример #5
0
 public bool SetContent(string content)
 {
     if (m_Text != null && !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);
         }
     }
     return(false);
 }
        public static void AdjustRadiusAxisLabelPos(ChartText txt, Vector3 pos, Vector3 cenPos, float txtHig, Vector3 offset)
        {
            var txtWidth  = txt.GetPreferredWidth();
            var sizeDelta = new Vector2(txtWidth, txt.GetPreferredHeight());

            txt.SetSizeDelta(sizeDelta);
            var diff = pos.y - cenPos.y;

            if (diff > 20f) //left
            {
                pos = new Vector3(pos.x - txtWidth / 2, pos.y);
            }
            else if (diff < -20f) //right
            {
                pos = new Vector3(pos.x + txtWidth / 2, pos.y);
            }
            else
            {
                float y = pos.y > cenPos.y ? pos.y + txtHig / 2 : pos.y - txtHig / 2;
                pos = new Vector3(pos.x, y);
            }
            txt.SetLocalPosition(pos);
        }