mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-22 00:20:18 +00:00
增加Editor下Data的添加、删除、上下移动操作按钮
This commit is contained in:
@@ -73,6 +73,7 @@ slug: /changelog
|
|||||||
|
|
||||||
## master
|
## master
|
||||||
|
|
||||||
|
* (2024.06.15) 增加`Editor`下`Data`的添加、删除、上下移动操作按钮
|
||||||
* (2024.06.11) 修复`Axis`的`IndicatorLabel`可能会遮挡住`Tooltip`的问题
|
* (2024.06.11) 修复`Axis`的`IndicatorLabel`可能会遮挡住`Tooltip`的问题
|
||||||
* (2024.06.11) 修复`Tooltip`在`Cross`时`Axis`的`IndicatorLabel`可能不显示的问题 (#315)
|
* (2024.06.11) 修复`Tooltip`在`Cross`时`Axis`的`IndicatorLabel`可能不显示的问题 (#315)
|
||||||
* (2024.06.10) 调整`Tooltip`的`Corss`重命名为`Cross`
|
* (2024.06.10) 调整`Tooltip`的`Corss`重命名为`Cross`
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ namespace XCharts.Editor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawSerieDataHeader(Rect drawRect,HeaderCallbackContext context)
|
private void DrawSerieDataHeader(Rect drawRect, HeaderCallbackContext context)
|
||||||
{
|
{
|
||||||
var serieData = context.serieData;
|
var serieData = context.serieData;
|
||||||
var fieldCount = context.fieldCount;
|
var fieldCount = context.fieldCount;
|
||||||
@@ -180,12 +180,18 @@ namespace XCharts.Editor
|
|||||||
var sereName = serieData.FindPropertyRelative("m_Name");
|
var sereName = serieData.FindPropertyRelative("m_Name");
|
||||||
var data = serieData.FindPropertyRelative("m_Data");
|
var data = serieData.FindPropertyRelative("m_Data");
|
||||||
#if UNITY_2019_3_OR_NEWER
|
#if UNITY_2019_3_OR_NEWER
|
||||||
var gap = 2;
|
var gap = 2;
|
||||||
var namegap = 3;
|
var namegap = 3;
|
||||||
|
var buttomLength = 30;
|
||||||
#else
|
#else
|
||||||
var gap = 0;
|
var gap = 0;
|
||||||
var namegap = 0;
|
var namegap = 0;
|
||||||
|
var buttomLength = 30;
|
||||||
#endif
|
#endif
|
||||||
|
if (showName)
|
||||||
|
{
|
||||||
|
buttomLength += 12;
|
||||||
|
}
|
||||||
if (fieldCount <= 1)
|
if (fieldCount <= 1)
|
||||||
{
|
{
|
||||||
while (2 > data.arraySize)
|
while (2 > data.arraySize)
|
||||||
@@ -197,13 +203,13 @@ namespace XCharts.Editor
|
|||||||
SerializedProperty element = data.GetArrayElementAtIndex(1);
|
SerializedProperty element = data.GetArrayElementAtIndex(1);
|
||||||
var startX = drawRect.x + EditorGUIUtility.labelWidth - EditorGUI.indentLevel * 15 + gap;
|
var startX = drawRect.x + EditorGUIUtility.labelWidth - EditorGUI.indentLevel * 15 + gap;
|
||||||
drawRect.x = startX;
|
drawRect.x = startX;
|
||||||
drawRect.xMax = maxX;
|
drawRect.xMax = maxX - buttomLength;
|
||||||
EditorGUI.PropertyField(drawRect, element, GUIContent.none);
|
EditorGUI.PropertyField(drawRect, element, GUIContent.none);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var startX = drawRect.x + EditorGUIUtility.labelWidth - EditorGUI.indentLevel * 15 + gap;
|
var startX = drawRect.x + EditorGUIUtility.labelWidth - EditorGUI.indentLevel * 15 + gap;
|
||||||
var dataWidTotal = (currentWidth - (startX + 20.5f + 1));
|
var dataWidTotal = currentWidth - (startX + 20.5f + 1) - buttomLength;
|
||||||
var dataWid = dataWidTotal / fieldCount;
|
var dataWid = dataWidTotal / fieldCount;
|
||||||
var xWid = dataWid - 0;
|
var xWid = dataWid - 0;
|
||||||
for (int i = 0; i < dimension; i++)
|
for (int i = 0; i < dimension; i++)
|
||||||
@@ -226,6 +232,9 @@ namespace XCharts.Editor
|
|||||||
drawRect.width = dataWid + 40 + dimension * namegap - 2.5f;
|
drawRect.width = dataWid + 40 + dimension * namegap - 2.5f;
|
||||||
EditorGUI.PropertyField(drawRect, sereName, GUIContent.none);
|
EditorGUI.PropertyField(drawRect, sereName, GUIContent.none);
|
||||||
}
|
}
|
||||||
|
drawRect.x = lastX;
|
||||||
|
drawRect.width = lastWid;
|
||||||
|
ChartEditorHelper.UpDownAddDeleteButton(drawRect, context.listProp, index);
|
||||||
EditorGUIUtility.fieldWidth = lastFieldWid;
|
EditorGUIUtility.fieldWidth = lastFieldWid;
|
||||||
EditorGUIUtility.labelWidth = lastLabelWid;
|
EditorGUIUtility.labelWidth = lastLabelWid;
|
||||||
}
|
}
|
||||||
@@ -242,12 +251,14 @@ namespace XCharts.Editor
|
|||||||
var fieldCount = dimension + (showName ? 1 : 0);
|
var fieldCount = dimension + (showName ? 1 : 0);
|
||||||
var serieData = m_Datas.GetArrayElementAtIndex(index);
|
var serieData = m_Datas.GetArrayElementAtIndex(index);
|
||||||
var dataIndex = serieData.FindPropertyRelative("m_Index").intValue;
|
var dataIndex = serieData.FindPropertyRelative("m_Index").intValue;
|
||||||
var callbackContext = new HeaderCallbackContext(){
|
var callbackContext = new HeaderCallbackContext()
|
||||||
|
{
|
||||||
serieData = serieData,
|
serieData = serieData,
|
||||||
fieldCount = fieldCount,
|
fieldCount = fieldCount,
|
||||||
showName = showName,
|
showName = showName,
|
||||||
index = index,
|
index = index,
|
||||||
dimension = dimension
|
dimension = dimension,
|
||||||
|
listProp = m_Datas
|
||||||
};
|
};
|
||||||
m_DataElementFoldout[index] = ChartEditorHelper.DrawSerieDataHeader("SerieData " + dataIndex, flag, false, null, callbackContext, DrawSerieDataHeader);
|
m_DataElementFoldout[index] = ChartEditorHelper.DrawSerieDataHeader("SerieData " + dataIndex, flag, false, null, callbackContext, DrawSerieDataHeader);
|
||||||
if (m_DataElementFoldout[index])
|
if (m_DataElementFoldout[index])
|
||||||
@@ -327,7 +338,10 @@ namespace XCharts.Editor
|
|||||||
var sourceIndex = dataLink.FindPropertyRelative("m_Source");
|
var sourceIndex = dataLink.FindPropertyRelative("m_Source");
|
||||||
var targetIndex = dataLink.FindPropertyRelative("m_Target");
|
var targetIndex = dataLink.FindPropertyRelative("m_Target");
|
||||||
var value = dataLink.FindPropertyRelative("m_Value");
|
var value = dataLink.FindPropertyRelative("m_Value");
|
||||||
ChartEditorHelper.MakeThreeField(ref drawRect, drawRect.width, sourceIndex, targetIndex, value, "");
|
var hig = ChartEditorHelper.MakeThreeField(ref drawRect, drawRect.width, sourceIndex, targetIndex, value, "");
|
||||||
|
var btnRect = drawRect;
|
||||||
|
btnRect.y -= hig;
|
||||||
|
ChartEditorHelper.UpDownAddDeleteButton(btnRect, m_Datas, index);
|
||||||
});
|
});
|
||||||
if (m_LinksElementFoldout[index])
|
if (m_LinksElementFoldout[index])
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ namespace XCharts.Editor
|
|||||||
public bool showName;
|
public bool showName;
|
||||||
public int index;
|
public int index;
|
||||||
public int dimension;
|
public int dimension;
|
||||||
|
public SerializedProperty listProp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class HeaderMenuInfo
|
public class HeaderMenuInfo
|
||||||
@@ -52,6 +53,8 @@ namespace XCharts.Editor
|
|||||||
public const float GAP_WIDTH = 0;
|
public const float GAP_WIDTH = 0;
|
||||||
public const float DIFF_WIDTH = 1;
|
public const float DIFF_WIDTH = 1;
|
||||||
#endif
|
#endif
|
||||||
|
public const float ICON_WIDHT = 10;
|
||||||
|
public const float ICON_GAP = 0;
|
||||||
static Dictionary<string, GUIContent> s_GUIContentCache;
|
static Dictionary<string, GUIContent> s_GUIContentCache;
|
||||||
|
|
||||||
static ChartEditorHelper()
|
static ChartEditorHelper()
|
||||||
@@ -115,21 +118,23 @@ namespace XCharts.Editor
|
|||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void MakeThreeField(ref Rect drawRect, float rectWidth, SerializedProperty prop1,
|
public static float MakeThreeField(ref Rect drawRect, float rectWidth, SerializedProperty prop1,
|
||||||
SerializedProperty prop2, SerializedProperty prop3, string name)
|
SerializedProperty prop2, SerializedProperty prop3, string name, bool btnSpacing = true)
|
||||||
{
|
{
|
||||||
EditorGUI.LabelField(drawRect, name);
|
EditorGUI.LabelField(drawRect, name);
|
||||||
var startX = drawRect.x + EditorGUIUtility.labelWidth - EditorGUI.indentLevel * INDENT_WIDTH + GAP_WIDTH;
|
var startX = drawRect.x + EditorGUIUtility.labelWidth - EditorGUI.indentLevel * INDENT_WIDTH + GAP_WIDTH;
|
||||||
var diff = 13 + EditorGUI.indentLevel * 14;
|
var diff = 13f + EditorGUI.indentLevel * 14;
|
||||||
var offset = diff - INDENT_WIDTH;
|
var offset = diff - INDENT_WIDTH;
|
||||||
var tempWidth = (rectWidth - startX + diff) / 3;
|
var tempWidth = (rectWidth - startX + diff - (btnSpacing ? (ICON_WIDHT + ICON_GAP) * 4 : 0)) / 3 + 8.5f;
|
||||||
var centerXRect = new Rect(startX, drawRect.y, tempWidth, drawRect.height - 1);
|
var centerXRect = new Rect(startX, drawRect.y, tempWidth, drawRect.height - 1);
|
||||||
var centerYRect = new Rect(centerXRect.x + tempWidth - offset, drawRect.y, tempWidth - 1, drawRect.height - 1);
|
var centerYRect = new Rect(centerXRect.x + tempWidth - offset, drawRect.y, tempWidth - 1, drawRect.height - 1);
|
||||||
var centerZRect = new Rect(centerYRect.x + tempWidth - offset, drawRect.y, tempWidth - 1, drawRect.height - 1);
|
var centerZRect = new Rect(centerYRect.x + tempWidth - offset, drawRect.y, tempWidth - 1, drawRect.height - 1);
|
||||||
EditorGUI.PropertyField(centerXRect, prop1, GUIContent.none);
|
EditorGUI.PropertyField(centerXRect, prop1, GUIContent.none);
|
||||||
EditorGUI.PropertyField(centerYRect, prop2, GUIContent.none);
|
EditorGUI.PropertyField(centerYRect, prop2, GUIContent.none);
|
||||||
EditorGUI.PropertyField(centerZRect, prop3, GUIContent.none);
|
EditorGUI.PropertyField(centerZRect, prop3, GUIContent.none);
|
||||||
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
var hig = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||||
|
drawRect.y += hig;
|
||||||
|
return hig;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void MakeVector2(ref Rect drawRect, float rectWidth, SerializedProperty prop, string name)
|
public static void MakeVector2(ref Rect drawRect, float rectWidth, SerializedProperty prop, string name)
|
||||||
@@ -344,15 +349,12 @@ namespace XCharts.Editor
|
|||||||
{
|
{
|
||||||
EditorGUI.indentLevel++;
|
EditorGUI.indentLevel++;
|
||||||
var listSize = listProp.arraySize;
|
var listSize = listProp.arraySize;
|
||||||
var iconWidth = 10;
|
|
||||||
var iconGap = 0f;
|
|
||||||
|
|
||||||
if (showSize)
|
if (showSize)
|
||||||
{
|
{
|
||||||
var headerHeight = DrawSplitterAndBackground(drawRect);
|
var headerHeight = DrawSplitterAndBackground(drawRect);
|
||||||
if (showOrder)
|
if (showOrder)
|
||||||
{
|
{
|
||||||
var elementRect = new Rect(drawRect.x, drawRect.y, drawRect.width - iconWidth + 2, drawRect.height);
|
var elementRect = new Rect(drawRect.x, drawRect.y, drawRect.width - ICON_WIDHT + 2, drawRect.height);
|
||||||
var oldColor = GUI.contentColor;
|
var oldColor = GUI.contentColor;
|
||||||
GUI.contentColor = Color.black;
|
GUI.contentColor = Color.black;
|
||||||
GUI.contentColor = oldColor;
|
GUI.contentColor = oldColor;
|
||||||
@@ -405,40 +407,14 @@ namespace XCharts.Editor
|
|||||||
DrawSplitterAndBackground(drawRect);
|
DrawSplitterAndBackground(drawRect);
|
||||||
if (showOrder)
|
if (showOrder)
|
||||||
{
|
{
|
||||||
var temp = INDENT_WIDTH + GAP_WIDTH + iconGap;
|
|
||||||
var isSerie = "Serie".Equals(element.type);
|
var isSerie = "Serie".Equals(element.type);
|
||||||
var elementRect = isSerie ?
|
var elementRect = isSerie ?
|
||||||
new Rect(drawRect.x, drawRect.y, drawRect.width + INDENT_WIDTH - 2 * iconGap, drawRect.height) :
|
new Rect(drawRect.x, drawRect.y, drawRect.width + INDENT_WIDTH - 2 * ICON_GAP, drawRect.height) :
|
||||||
new Rect(drawRect.x, drawRect.y, drawRect.width - 4 * iconWidth, drawRect.height);
|
new Rect(drawRect.x, drawRect.y, drawRect.width - 4 * ICON_WIDHT, drawRect.height);
|
||||||
EditorGUI.PropertyField(elementRect, element, new GUIContent("Element " + i));
|
EditorGUI.PropertyField(elementRect, element, new GUIContent("Element " + i));
|
||||||
var iconRect = new Rect(drawRect.width - 4 * iconWidth + temp, drawRect.y, iconWidth, drawRect.height);
|
UpDownAddDeleteButton(drawRect, listProp, i);
|
||||||
var oldColor = GUI.contentColor;
|
drawRect.y += EditorGUI.GetPropertyHeight(element);
|
||||||
GUI.contentColor = Color.black;
|
height += EditorGUI.GetPropertyHeight(element);
|
||||||
if (GUI.Button(iconRect, EditorCustomStyles.iconUp, EditorCustomStyles.invisibleButton))
|
|
||||||
{
|
|
||||||
if (i > 0) listProp.MoveArrayElement(i, i - 1);
|
|
||||||
}
|
|
||||||
iconRect = new Rect(drawRect.width - 3 * iconWidth + temp, drawRect.y, iconWidth, drawRect.height);
|
|
||||||
if (GUI.Button(iconRect, EditorCustomStyles.iconDown, EditorCustomStyles.invisibleButton))
|
|
||||||
{
|
|
||||||
if (i < listProp.arraySize - 1) listProp.MoveArrayElement(i, i + 1);
|
|
||||||
}
|
|
||||||
iconRect = new Rect(drawRect.width - 2 * iconWidth + temp, drawRect.y, iconWidth, drawRect.height);
|
|
||||||
if (GUI.Button(iconRect, EditorCustomStyles.iconAdd, EditorCustomStyles.invisibleButton))
|
|
||||||
{
|
|
||||||
if (i < listProp.arraySize && i >= 0) listProp.InsertArrayElementAtIndex(i);
|
|
||||||
}
|
|
||||||
iconRect = new Rect(drawRect.width - iconWidth + temp, drawRect.y, iconWidth, drawRect.height);
|
|
||||||
if (GUI.Button(iconRect, EditorCustomStyles.iconRemove, EditorCustomStyles.invisibleButton))
|
|
||||||
{
|
|
||||||
if (i < listProp.arraySize && i >= 0) listProp.DeleteArrayElementAtIndex(i);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
drawRect.y += EditorGUI.GetPropertyHeight(element);
|
|
||||||
height += EditorGUI.GetPropertyHeight(element);
|
|
||||||
}
|
|
||||||
GUI.contentColor = oldColor;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -451,6 +427,34 @@ namespace XCharts.Editor
|
|||||||
EditorGUI.indentLevel--;
|
EditorGUI.indentLevel--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void UpDownAddDeleteButton(Rect drawRect, SerializedProperty listProp, int i)
|
||||||
|
{
|
||||||
|
var temp = INDENT_WIDTH + GAP_WIDTH + ICON_GAP;
|
||||||
|
var iconRect = new Rect(drawRect.width - 4 * ICON_WIDHT + temp, drawRect.y, ICON_WIDHT, drawRect.height);
|
||||||
|
var oldColor = GUI.contentColor;
|
||||||
|
GUI.contentColor = Color.black;
|
||||||
|
if (GUI.Button(iconRect, EditorCustomStyles.iconUp, EditorCustomStyles.invisibleButton))
|
||||||
|
{
|
||||||
|
if (i > 0) listProp.MoveArrayElement(i, i - 1);
|
||||||
|
}
|
||||||
|
iconRect = new Rect(drawRect.width - 3 * ICON_WIDHT + temp, drawRect.y, ICON_WIDHT, drawRect.height);
|
||||||
|
if (GUI.Button(iconRect, EditorCustomStyles.iconDown, EditorCustomStyles.invisibleButton))
|
||||||
|
{
|
||||||
|
if (i < listProp.arraySize - 1) listProp.MoveArrayElement(i, i + 1);
|
||||||
|
}
|
||||||
|
iconRect = new Rect(drawRect.width - 2 * ICON_WIDHT + temp, drawRect.y, ICON_WIDHT, drawRect.height);
|
||||||
|
if (GUI.Button(iconRect, EditorCustomStyles.iconAdd, EditorCustomStyles.invisibleButton))
|
||||||
|
{
|
||||||
|
if (i < listProp.arraySize && i >= 0) listProp.InsertArrayElementAtIndex(i);
|
||||||
|
}
|
||||||
|
iconRect = new Rect(drawRect.width - ICON_WIDHT + temp, drawRect.y, ICON_WIDHT, drawRect.height);
|
||||||
|
if (GUI.Button(iconRect, EditorCustomStyles.iconRemove, EditorCustomStyles.invisibleButton))
|
||||||
|
{
|
||||||
|
if (i < listProp.arraySize && i >= 0) listProp.DeleteArrayElementAtIndex(i);
|
||||||
|
}
|
||||||
|
GUI.contentColor = oldColor;
|
||||||
|
}
|
||||||
|
|
||||||
public static bool PropertyField(ref Rect drawRect, Dictionary<string, float> heights, string key,
|
public static bool PropertyField(ref Rect drawRect, Dictionary<string, float> heights, string key,
|
||||||
SerializedProperty prop)
|
SerializedProperty prop)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user