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; AdjustIconPos(); } return(sizeChange); } AdjustIconPos(); if (m_AutoHideIconWhenLabelEmpty && isIconActive) { ChartHelper.SetActive(m_IconImage.gameObject, !string.IsNullOrEmpty(text)); } } return(false); }
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); }
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); } }
public static ChartText AddTextObject(string name, Transform parent, Vector2 anchorMin, Vector2 anchorMax, Vector2 pivot, Vector2 sizeDelta, TextStyle textStyle, ComponentTheme theme) { GameObject txtObj = AddObject(name, parent, anchorMin, anchorMax, pivot, sizeDelta); txtObj.transform.localEulerAngles = new Vector3(0, 0, textStyle.rotate); var chartText = new ChartText(); #if dUI_TextMeshPro RemoveComponent <Text>(txtObj); chartText.tmpText = GetOrAddComponent <TextMeshProUGUI>(txtObj); chartText.tmpText.font = textStyle.tmpFont == null ? theme.tmpFont : textStyle.tmpFont; chartText.tmpText.fontStyle = textStyle.tmpFontStyle; chartText.tmpText.alignment = textStyle.tmpAlignment; chartText.tmpText.richText = true; chartText.tmpText.raycastTarget = false; chartText.tmpText.enableWordWrapping = false; #else chartText.text = GetOrAddComponent <Text>(txtObj); chartText.text.font = textStyle.font == null ? theme.font : textStyle.font; chartText.text.fontStyle = textStyle.fontStyle; chartText.text.alignment = textStyle.alignment; chartText.text.horizontalOverflow = HorizontalWrapMode.Overflow; chartText.text.verticalOverflow = VerticalWrapMode.Overflow; chartText.text.supportRichText = true; chartText.text.raycastTarget = false; #endif chartText.SetColor(textStyle.GetColor(theme.textColor)); chartText.SetFontSize(textStyle.fontSize > 0 ? textStyle.fontSize : theme.fontSize); chartText.SetText("Text"); chartText.SetLineSpacing(textStyle.lineSpacing); RectTransform rect = GetOrAddComponent <RectTransform>(txtObj); rect.localPosition = Vector3.zero; rect.sizeDelta = sizeDelta; rect.anchorMin = anchorMin; rect.anchorMax = anchorMax; rect.pivot = pivot; return(chartText); }
/// <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); } } }
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); }