From 34a64f9c37188dd22d515bd60f18107ef82fa090 Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Thu, 19 Sep 2019 09:06:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0Tooltip=E7=9A=84FixedWidth?= =?UTF-8?q?=E3=80=81FixedHeight=E3=80=81MinWidth=E3=80=81MinHeight?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Editor/PropertyDrawers/TooltipDrawer.cs | 14 ++++++++- Scripts/UI/Component/Tooltip.cs | 30 +++++++++++++++++-- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/Scripts/Editor/PropertyDrawers/TooltipDrawer.cs b/Scripts/Editor/PropertyDrawers/TooltipDrawer.cs index 6abc0660..20221592 100644 --- a/Scripts/Editor/PropertyDrawers/TooltipDrawer.cs +++ b/Scripts/Editor/PropertyDrawers/TooltipDrawer.cs @@ -14,6 +14,10 @@ namespace XCharts drawRect.height = EditorGUIUtility.singleLineHeight; SerializedProperty show = prop.FindPropertyRelative("m_Show"); SerializedProperty type = prop.FindPropertyRelative("m_Type"); + SerializedProperty m_FixedWidth = prop.FindPropertyRelative("m_FixedWidth"); + SerializedProperty m_FixedHeight = prop.FindPropertyRelative("m_FixedHeight"); + SerializedProperty m_MinWidth = prop.FindPropertyRelative("m_MinWidth"); + SerializedProperty m_MinHeight = prop.FindPropertyRelative("m_MinHeight"); ChartEditorHelper.MakeFoldout(ref drawRect, ref m_TooltipModuleToggle, "Tooltip", show); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; @@ -21,13 +25,21 @@ namespace XCharts { EditorGUI.PropertyField(drawRect, type); drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + EditorGUI.PropertyField(drawRect, m_FixedWidth); + drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + EditorGUI.PropertyField(drawRect, m_FixedHeight); + drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + EditorGUI.PropertyField(drawRect, m_MinWidth); + drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; + EditorGUI.PropertyField(drawRect, m_MinHeight); + drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; } } public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) { if (m_TooltipModuleToggle) - return 2 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing; + return 6 * EditorGUIUtility.singleLineHeight + 5 * EditorGUIUtility.standardVerticalSpacing; else return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; } diff --git a/Scripts/UI/Component/Tooltip.cs b/Scripts/UI/Component/Tooltip.cs index 4a5fe538..61195925 100644 --- a/Scripts/UI/Component/Tooltip.cs +++ b/Scripts/UI/Component/Tooltip.cs @@ -42,6 +42,10 @@ namespace XCharts [SerializeField] private bool m_Show; [SerializeField] private Type m_Type; + [SerializeField] private float m_FixedWidth = 0; + [SerializeField] private float m_FixedHeight = 0; + [SerializeField] private float m_MinWidth = 0; + [SerializeField] private float m_MinHeight = 0; private GameObject m_GameObject; private GameObject m_Content; @@ -60,6 +64,22 @@ namespace XCharts /// 提示框指示器类型。 /// public Type type { get { return m_Type; } set { m_Type = value; } } + /// + /// 固定宽度。比 minWidth 优先。 + /// + public float fixedWidth { get { return m_FixedWidth; } set { m_FixedWidth = value; } } + /// + /// 固定高度。比 minHeight 优先。 + /// + public float fixedHeight { get { return m_FixedHeight; } set { m_FixedHeight = value; } } + /// + /// 最小宽度。如若 fixedWidth 设有值,优先取 fixedWidth。 + /// + public float minWidth { get { return m_MinWidth; } set { m_MinWidth = value; } } + /// + /// 最小高度。如若 fixedHeight 设有值,优先取 fixedHeight。 + /// + public float minHeight { get { return m_MinHeight; } set { m_MinHeight = value; } } /// /// The data index currently indicated by Tooltip. @@ -179,8 +199,14 @@ namespace XCharts if (m_ContentText) { m_ContentText.text = txt; - m_ContentRect.sizeDelta = new Vector2(m_ContentText.preferredWidth + 8, - m_ContentText.preferredHeight + 8); + float wid, hig; + if (m_FixedWidth > 0) wid = m_FixedWidth; + else if (m_MinWidth > 0 && m_ContentText.preferredWidth < m_MinWidth) wid = m_MinWidth; + else wid = m_ContentText.preferredWidth + 8; + if (m_FixedHeight > 0) hig = m_FixedHeight; + else if (m_MinHeight > 0 && m_ContentText.preferredHeight < m_MinHeight) hig = m_MinHeight; + else hig = m_ContentText.preferredHeight + 8; + m_ContentRect.sizeDelta = new Vector2(wid, hig); } }