mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-14 20:00:09 +00:00
增加GridLayout网格布局组件
This commit is contained in:
@@ -12,7 +12,8 @@ namespace XCharts.Runtime
|
||||
return false;
|
||||
}
|
||||
|
||||
public void UpdateRuntimeData(float chartX, float chartY, float chartWidth, float chartHeight)
|
||||
{ }
|
||||
public void UpdateRuntimeData(BaseChart chart)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ namespace XCharts.Runtime
|
||||
public class GridCoord : CoordSystem, IUpdateRuntimeData, ISerieContainer
|
||||
{
|
||||
[SerializeField] private bool m_Show = true;
|
||||
[SerializeField][Since("v3.8.0")] private int m_LayoutIndex = -1;
|
||||
[SerializeField] private float m_Left = 0.1f;
|
||||
[SerializeField] private float m_Right = 0.08f;
|
||||
[SerializeField] private float m_Top = 0.22f;
|
||||
@@ -36,6 +37,11 @@ namespace XCharts.Runtime
|
||||
get { return m_Show; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
|
||||
}
|
||||
public int layoutIndex
|
||||
{
|
||||
get { return m_LayoutIndex; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_LayoutIndex, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Distance between grid component and the left side of the container.
|
||||
/// |grid 组件离容器左侧的距离。
|
||||
@@ -114,8 +120,22 @@ namespace XCharts.Runtime
|
||||
return context.isPointerEnter;
|
||||
}
|
||||
|
||||
public void UpdateRuntimeData(float chartX, float chartY, float chartWidth, float chartHeight)
|
||||
public void UpdateRuntimeData(BaseChart chart)
|
||||
{
|
||||
if (layoutIndex >= 0)
|
||||
{
|
||||
var layout = chart.GetChartComponent<GridLayout>(layoutIndex);
|
||||
if (layout != null)
|
||||
{
|
||||
layout.UpdateRuntimeData(chart);
|
||||
layout.UpdateGridContext(index, ref context);
|
||||
return;
|
||||
}
|
||||
}
|
||||
var chartX = chart.chartX;
|
||||
var chartY = chart.chartY;
|
||||
var chartWidth = chart.chartWidth;
|
||||
var chartHeight = chart.chartHeight;
|
||||
context.left = left <= 1 ? left * chartWidth : left;
|
||||
context.bottom = bottom <= 1 ? bottom * chartHeight : bottom;
|
||||
context.top = top <= 1 ? top * chartHeight : top;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
@@ -15,7 +14,7 @@ namespace XCharts.Runtime
|
||||
grid.painter = chart.painter;
|
||||
grid.refreshComponent = delegate()
|
||||
{
|
||||
grid.UpdateRuntimeData(chart.chartX, chart.chartY, chart.chartWidth, chart.chartHeight);
|
||||
grid.UpdateRuntimeData(chart);
|
||||
chart.OnCoordinateChanged();
|
||||
};
|
||||
grid.refreshComponent();
|
||||
|
||||
130
Runtime/Coord/Grid/GridLayout.cs
Normal file
130
Runtime/Coord/Grid/GridLayout.cs
Normal file
@@ -0,0 +1,130 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
/// <summary>
|
||||
/// Grid layout component. Used to manage the layout of multiple `GridCoord`, and the number of rows and columns of the grid can be controlled by `row` and `column`.
|
||||
/// |网格布局组件。用于管理多个`GridCoord`的布局,可以通过`row`和`column`来控制网格的行列数。
|
||||
/// </summary>
|
||||
[Since("v3.8.0")]
|
||||
[Serializable]
|
||||
[ComponentHandler(typeof(GridLayoutHandler), true)]
|
||||
public class GridLayout : MainComponent, IUpdateRuntimeData
|
||||
{
|
||||
[SerializeField] private bool m_Show = true;
|
||||
[SerializeField] private float m_Left = 0.1f;
|
||||
[SerializeField] private float m_Right = 0.08f;
|
||||
[SerializeField] private float m_Top = 0.22f;
|
||||
[SerializeField] private float m_Bottom = 0.12f;
|
||||
[SerializeField] private int m_Row = 2;
|
||||
[SerializeField] private int m_Column = 2;
|
||||
[SerializeField] private Vector2 m_Spacing = Vector2.zero;
|
||||
|
||||
public GridLayoutContext context = new GridLayoutContext();
|
||||
|
||||
/// <summary>
|
||||
/// Whether to show the grid in rectangular coordinate.
|
||||
/// |是否显示直角坐标系网格。
|
||||
/// </summary>
|
||||
public bool show
|
||||
{
|
||||
get { return m_Show; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Show, value)) SetVerticesDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Distance between grid component and the left side of the container.
|
||||
/// |grid 组件离容器左侧的距离。
|
||||
/// </summary>
|
||||
public float left
|
||||
{
|
||||
get { return m_Left; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Left, value)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Distance between grid component and the right side of the container.
|
||||
/// |grid 组件离容器右侧的距离。
|
||||
/// </summary>
|
||||
public float right
|
||||
{
|
||||
get { return m_Right; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Right, value)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Distance between grid component and the top side of the container.
|
||||
/// |grid 组件离容器上侧的距离。
|
||||
/// </summary>
|
||||
public float top
|
||||
{
|
||||
get { return m_Top; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Top, value)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// Distance between grid component and the bottom side of the container.
|
||||
/// |grid 组件离容器下侧的距离。
|
||||
/// </summary>
|
||||
public float bottom
|
||||
{
|
||||
get { return m_Bottom; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Bottom, value)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// the row count of grid layout.
|
||||
/// |网格布局的行数。
|
||||
/// </summary>
|
||||
public int row
|
||||
{
|
||||
get { return m_Row; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Row, value)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// the column count of grid layout.
|
||||
/// |网格布局的列数。
|
||||
/// </summary>
|
||||
public int column
|
||||
{
|
||||
get { return m_Column; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Column, value)) SetAllDirty(); }
|
||||
}
|
||||
/// <summary>
|
||||
/// the spacing of grid layout.
|
||||
/// |网格布局的间距。
|
||||
/// </summary>
|
||||
public Vector2 spacing
|
||||
{
|
||||
get { return m_Spacing; }
|
||||
set { if (PropertyUtil.SetStruct(ref m_Spacing, value)) SetAllDirty(); }
|
||||
}
|
||||
|
||||
public void UpdateRuntimeData(BaseChart chart)
|
||||
{
|
||||
var chartX = chart.chartX;
|
||||
var chartY = chart.chartY;
|
||||
var chartWidth = chart.chartWidth;
|
||||
var chartHeight = chart.chartHeight;
|
||||
context.left = left <= 1 ? left * chartWidth : left;
|
||||
context.bottom = bottom <= 1 ? bottom * chartHeight : bottom;
|
||||
context.top = top <= 1 ? top * chartHeight : top;
|
||||
context.right = right <= 1 ? right * chartWidth : right;
|
||||
context.x = chartX + context.left;
|
||||
context.y = chartY + context.bottom;
|
||||
context.width = chartWidth - context.left - context.right;
|
||||
context.height = chartHeight - context.top - context.bottom;
|
||||
context.eachWidth = (context.width - spacing.x * (column - 1)) / column;
|
||||
context.eachHeight = (context.height - spacing.y * (row - 1)) / row;
|
||||
}
|
||||
|
||||
internal void UpdateGridContext(int index, ref GridCoordContext gridContext)
|
||||
{
|
||||
var row = index / m_Column;
|
||||
var column = index % m_Column;
|
||||
|
||||
gridContext.x = context.x + column * (context.eachWidth + spacing.x);
|
||||
gridContext.y = context.y + row * (context.eachHeight + spacing.y);
|
||||
gridContext.width = context.eachWidth;
|
||||
gridContext.height = context.eachHeight;
|
||||
gridContext.position = new Vector3(gridContext.x, gridContext.y);
|
||||
gridContext.center = new Vector3(gridContext.x + gridContext.width / 2, gridContext.y + gridContext.height / 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Runtime/Coord/Grid/GridLayout.cs.meta
Normal file
11
Runtime/Coord/Grid/GridLayout.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9abc8e277fa0f41c1a0b13133bb736c4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
16
Runtime/Coord/Grid/GridLayoutContext.cs
Normal file
16
Runtime/Coord/Grid/GridLayoutContext.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
public class GridLayoutContext : MainComponentContext
|
||||
{
|
||||
public float x;
|
||||
public float y;
|
||||
public float width;
|
||||
public float height;
|
||||
public float left;
|
||||
public float right;
|
||||
public float bottom;
|
||||
public float top;
|
||||
public float eachWidth;
|
||||
public float eachHeight;
|
||||
}
|
||||
}
|
||||
11
Runtime/Coord/Grid/GridLayoutContext.cs.meta
Normal file
11
Runtime/Coord/Grid/GridLayoutContext.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7265c042ebd33458eb12c112d46d9a60
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
7
Runtime/Coord/Grid/GridLayoutHandler.cs
Normal file
7
Runtime/Coord/Grid/GridLayoutHandler.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
[UnityEngine.Scripting.Preserve]
|
||||
internal sealed class GridLayoutHandler : MainComponentHandler<GridLayout>
|
||||
{
|
||||
}
|
||||
}
|
||||
11
Runtime/Coord/Grid/GridLayoutHandler.cs.meta
Normal file
11
Runtime/Coord/Grid/GridLayoutHandler.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3b1c1f0fa475b484286b0b2c688dc3c1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -92,8 +92,12 @@ namespace XCharts.Runtime
|
||||
return context.runtimeIsPointerEnter;
|
||||
}
|
||||
|
||||
public void UpdateRuntimeData(float chartX, float chartY, float chartWidth, float chartHeight)
|
||||
public void UpdateRuntimeData(BaseChart chart)
|
||||
{
|
||||
var chartX = chart.chartX;
|
||||
var chartY = chart.chartY;
|
||||
var chartWidth = chart.chartWidth;
|
||||
var chartHeight = chart.chartHeight;
|
||||
context.left = left <= 1 ? left * chartWidth : left;
|
||||
context.bottom = bottom <= 1 ? bottom * chartHeight : bottom;
|
||||
context.top = top <= 1 ? top * chartHeight : top;
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace XCharts.Runtime
|
||||
grid.painter = chart.painter;
|
||||
grid.refreshComponent = delegate()
|
||||
{
|
||||
grid.UpdateRuntimeData(chart.chartX, chart.chartY, chart.chartWidth, chart.chartHeight);
|
||||
grid.UpdateRuntimeData(chart);
|
||||
chart.OnCoordinateChanged();
|
||||
};
|
||||
grid.refreshComponent();
|
||||
|
||||
Reference in New Issue
Block a user