修复图例判断超范围异常的问题

This commit is contained in:
monitor1394
2020-06-07 18:22:57 +08:00
parent 53e988e8d2
commit f93355e6c4
2 changed files with 79 additions and 70 deletions

View File

@@ -25,69 +25,78 @@ namespace XCharts
EditorGUI.PropertyField(drawRect, align, new GUIContent("Location")); EditorGUI.PropertyField(drawRect, align, new GUIContent("Location"));
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
++EditorGUI.indentLevel; ++EditorGUI.indentLevel;
switch ((Location.Align)align.enumValueIndex)
{
case Location.Align.TopCenter:
EditorGUI.PropertyField(drawRect, top); EditorGUI.PropertyField(drawRect, top);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
break;
case Location.Align.TopLeft:
EditorGUI.PropertyField(drawRect, top);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, left);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
break;
case Location.Align.TopRight:
EditorGUI.PropertyField(drawRect, top);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, right);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
break;
case Location.Align.BottomCenter:
EditorGUI.PropertyField(drawRect, bottom);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
break;
case Location.Align.BottomLeft:
EditorGUI.PropertyField(drawRect, bottom); EditorGUI.PropertyField(drawRect, bottom);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, left); EditorGUI.PropertyField(drawRect, left);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
break;
case Location.Align.BottomRight:
EditorGUI.PropertyField(drawRect, bottom);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(drawRect, right); EditorGUI.PropertyField(drawRect, right);
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
break; // switch ((Location.Align)align.enumValueIndex)
case Location.Align.Center: // {
break; // case Location.Align.TopCenter:
case Location.Align.CenterLeft: // EditorGUI.PropertyField(drawRect, top);
EditorGUI.PropertyField(drawRect, left); // drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; // break;
break; // case Location.Align.TopLeft:
case Location.Align.CenterRight: // EditorGUI.PropertyField(drawRect, top);
EditorGUI.PropertyField(drawRect, right); // drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; // EditorGUI.PropertyField(drawRect, left);
break; // drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
} // break;
// case Location.Align.TopRight:
// EditorGUI.PropertyField(drawRect, top);
// drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
// EditorGUI.PropertyField(drawRect, right);
// drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
// break;
// case Location.Align.BottomCenter:
// EditorGUI.PropertyField(drawRect, bottom);
// drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
// break;
// case Location.Align.BottomLeft:
// EditorGUI.PropertyField(drawRect, bottom);
// drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
// EditorGUI.PropertyField(drawRect, left);
// drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
// break;
// case Location.Align.BottomRight:
// EditorGUI.PropertyField(drawRect, bottom);
// drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
// EditorGUI.PropertyField(drawRect, right);
// drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
// break;
// case Location.Align.Center:
// break;
// case Location.Align.CenterLeft:
// EditorGUI.PropertyField(drawRect, left);
// drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
// break;
// case Location.Align.CenterRight:
// EditorGUI.PropertyField(drawRect, right);
// drawRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
// break;
// }
--EditorGUI.indentLevel; --EditorGUI.indentLevel;
} }
public override float GetPropertyHeight(SerializedProperty prop, GUIContent label) public override float GetPropertyHeight(SerializedProperty prop, GUIContent label)
{ {
SerializedProperty align = prop.FindPropertyRelative("m_Align"); return 5 * EditorGUIUtility.singleLineHeight + 4 * EditorGUIUtility.standardVerticalSpacing;
switch ((Location.Align)align.enumValueIndex) // SerializedProperty align = prop.FindPropertyRelative("m_Align");
{ // switch ((Location.Align)align.enumValueIndex)
case Location.Align.Center: // {
return 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing; // case Location.Align.Center:
case Location.Align.TopCenter: // return 1 * EditorGUIUtility.singleLineHeight + 1 * EditorGUIUtility.standardVerticalSpacing;
case Location.Align.BottomCenter: // case Location.Align.TopCenter:
case Location.Align.CenterLeft: // case Location.Align.BottomCenter:
case Location.Align.CenterRight: // case Location.Align.CenterLeft:
return 2 * EditorGUIUtility.singleLineHeight + 2 * EditorGUIUtility.standardVerticalSpacing; // case Location.Align.CenterRight:
default: // return 2 * EditorGUIUtility.singleLineHeight + 2 * EditorGUIUtility.standardVerticalSpacing;
return 3 * EditorGUIUtility.singleLineHeight + 3 * EditorGUIUtility.standardVerticalSpacing; // default:
} // return 3 * EditorGUIUtility.singleLineHeight + 3 * EditorGUIUtility.standardVerticalSpacing;
// }
} }
} }
} }

View File

@@ -92,7 +92,7 @@ namespace XCharts
foreach (var kv in legend.buttonList) foreach (var kv in legend.buttonList)
{ {
var item = kv.Value; var item = kv.Value;
if (currHeight + item.height + legend.itemGap > legendHeight) if (currHeight + item.height > legendHeight)
{ {
currHeight = 0; currHeight = 0;
offsetX += legendRuntimeWidth + legend.itemGap; offsetX += legendRuntimeWidth + legend.itemGap;
@@ -105,7 +105,7 @@ namespace XCharts
foreach (var kv in legend.buttonList) foreach (var kv in legend.buttonList)
{ {
var item = kv.Value; var item = kv.Value;
if (currHeight + item.height + legend.itemGap > legendHeight) if (currHeight + item.height > legendHeight)
{ {
currHeight = 0; currHeight = 0;
offsetX += legendRuntimeWidth + legend.itemGap; offsetX += legendRuntimeWidth + legend.itemGap;
@@ -118,7 +118,7 @@ namespace XCharts
foreach (var kv in legend.buttonList) foreach (var kv in legend.buttonList)
{ {
var item = kv.Value; var item = kv.Value;
if (currHeight + item.height + legend.itemGap > legendHeight) if (currHeight + item.height > legendHeight)
{ {
currHeight = 0; currHeight = 0;
offsetX -= legendRuntimeWidth + legend.itemGap; offsetX -= legendRuntimeWidth + legend.itemGap;
@@ -134,7 +134,7 @@ namespace XCharts
foreach (var kv in legend.buttonList) foreach (var kv in legend.buttonList)
{ {
var item = kv.Value; var item = kv.Value;
if (currHeight + item.height + legend.itemGap > legendHeight) if (currHeight + item.height > legendHeight)
{ {
currHeight = 0; currHeight = 0;
offsetX += legendRuntimeWidth + legend.itemGap; offsetX += legendRuntimeWidth + legend.itemGap;
@@ -148,7 +148,7 @@ namespace XCharts
foreach (var kv in legend.buttonList) foreach (var kv in legend.buttonList)
{ {
var item = kv.Value; var item = kv.Value;
if (currHeight + item.height + legend.itemGap > legendHeight) if (currHeight + item.height > legendHeight)
{ {
currHeight = 0; currHeight = 0;
offsetX += legendRuntimeWidth + legend.itemGap; offsetX += legendRuntimeWidth + legend.itemGap;
@@ -163,7 +163,7 @@ namespace XCharts
foreach (var kv in legend.buttonList) foreach (var kv in legend.buttonList)
{ {
var item = kv.Value; var item = kv.Value;
if (currHeight + item.height + legend.itemGap > legendHeight) if (currHeight + item.height > legendHeight)
{ {
currHeight = 0; currHeight = 0;
offsetX -= legendRuntimeWidth + legend.itemGap; offsetX -= legendRuntimeWidth + legend.itemGap;
@@ -178,7 +178,7 @@ namespace XCharts
foreach (var kv in legend.buttonList) foreach (var kv in legend.buttonList)
{ {
var item = kv.Value; var item = kv.Value;
if (currHeight + item.height + legend.itemGap > legendHeight) if (currHeight + item.height > legendHeight)
{ {
currHeight = 0; currHeight = 0;
offsetX += legendRuntimeWidth + legend.itemGap; offsetX += legendRuntimeWidth + legend.itemGap;
@@ -193,7 +193,7 @@ namespace XCharts
foreach (var kv in legend.buttonList) foreach (var kv in legend.buttonList)
{ {
var item = kv.Value; var item = kv.Value;
if (currHeight + item.height + legend.itemGap > legendHeight) if (currHeight + item.height > legendHeight)
{ {
currHeight = 0; currHeight = 0;
offsetX += legendRuntimeWidth + legend.itemGap; offsetX += legendRuntimeWidth + legend.itemGap;
@@ -208,7 +208,7 @@ namespace XCharts
foreach (var kv in legend.buttonList) foreach (var kv in legend.buttonList)
{ {
var item = kv.Value; var item = kv.Value;
if (currHeight + item.height + legend.itemGap > legendHeight) if (currHeight + item.height > legendHeight)
{ {
currHeight = 0; currHeight = 0;
offsetX -= legendRuntimeWidth + legend.itemGap; offsetX -= legendRuntimeWidth + legend.itemGap;
@@ -229,7 +229,7 @@ namespace XCharts
foreach (var kv in legend.buttonList) foreach (var kv in legend.buttonList)
{ {
var item = kv.Value; var item = kv.Value;
if (currWidth + item.width + legend.itemGap >= legendWidth) if (currWidth + item.width > legendWidth)
{ {
currWidth = 0f; currWidth = 0f;
if (isBottom) currHeight += legend.itemGap + item.height; if (isBottom) currHeight += legend.itemGap + item.height;
@@ -247,7 +247,7 @@ namespace XCharts
foreach (var kv in legend.buttonList) foreach (var kv in legend.buttonList)
{ {
var item = kv.Value; var item = kv.Value;
if (currWidth + item.width + legend.itemGap >= legendWidth) if (currWidth + item.width > legendWidth)
{ {
currWidth = 0f; currWidth = 0f;
if (isBottom) currHeight += legend.itemGap + item.height; if (isBottom) currHeight += legend.itemGap + item.height;
@@ -265,7 +265,7 @@ namespace XCharts
foreach (var kv in legend.buttonList) foreach (var kv in legend.buttonList)
{ {
var item = kv.Value; var item = kv.Value;
if (currWidth + item.width + legend.itemGap >= legendWidth) if (currWidth + item.width > legendWidth)
{ {
currWidth = 0f; currWidth = 0f;
if (isBottom) currHeight += legend.itemGap + item.height; if (isBottom) currHeight += legend.itemGap + item.height;