diff --git a/Runtime/Resources.meta b/Runtime/Resources.meta
new file mode 100644
index 0000000..3de318b
--- /dev/null
+++ b/Runtime/Resources.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: f6a0a99a3d243d2429a9ca17b9b35149
+folderAsset: yes
+DefaultImporter:
+ externalObjects: {}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Runtime/XTable/Style.meta b/Runtime/Resources/Style.meta
similarity index 77%
rename from Runtime/XTable/Style.meta
rename to Runtime/Resources/Style.meta
index a2485a1..9345f8a 100644
--- a/Runtime/XTable/Style.meta
+++ b/Runtime/Resources/Style.meta
@@ -1,5 +1,5 @@
fileFormatVersion: 2
-guid: 64d88208839a5034db31c330796453aa
+guid: 6da8337ecebc7074b9f37bc69feab5c1
folderAsset: yes
DefaultImporter:
externalObjects: {}
diff --git a/Runtime/XTable/Style/DefaultTableStyles.xsss b/Runtime/Resources/Style/DefaultTableStyles.xsss
similarity index 100%
rename from Runtime/XTable/Style/DefaultTableStyles.xsss
rename to Runtime/Resources/Style/DefaultTableStyles.xsss
diff --git a/Runtime/XTable/Style/DefaultTableStyles.xsss.meta b/Runtime/Resources/Style/DefaultTableStyles.xsss.meta
similarity index 100%
rename from Runtime/XTable/Style/DefaultTableStyles.xsss.meta
rename to Runtime/Resources/Style/DefaultTableStyles.xsss.meta
diff --git a/Runtime/Core/StyleSheetUI/DefaultXericStyleSheet.xsss b/Runtime/Resources/Style/DefaultXericStyleSheet.xsss
similarity index 100%
rename from Runtime/Core/StyleSheetUI/DefaultXericStyleSheet.xsss
rename to Runtime/Resources/Style/DefaultXericStyleSheet.xsss
diff --git a/Runtime/Core/StyleSheetUI/DefaultXericStyleSheet.xsss.meta b/Runtime/Resources/Style/DefaultXericStyleSheet.xsss.meta
similarity index 100%
rename from Runtime/Core/StyleSheetUI/DefaultXericStyleSheet.xsss.meta
rename to Runtime/Resources/Style/DefaultXericStyleSheet.xsss.meta
diff --git a/Runtime/XTable/Core/XTableConfig.cs b/Runtime/XTable/Core/XTableConfig.cs
new file mode 100644
index 0000000..ff7efcb
--- /dev/null
+++ b/Runtime/XTable/Core/XTableConfig.cs
@@ -0,0 +1,124 @@
+using UnityEngine;
+
+namespace XericUI.XTable.Core
+{
+ ///
+ /// 表格系统全局配置资源——统一管理布局、样式回退值、运行时颜色等参数。
+ /// 表格组件在 Awake 时自动加载 Resources 中的 "XTableDefaultConfig",
+ /// 或由外部脚本在初始化阶段显式赋值。
+ ///
+ [CreateAssetMenu(fileName = "XTableConfig", menuName = "Xeric UI/Table/Table Config", order = 100)]
+ public class XTableConfig : ScriptableObject
+ {
+ #region 布局
+
+ [Header("布局")]
+ [Tooltip("新增行时的默认行高(像素)")]
+ public float DefaultRowHeight = 40f;
+
+ [Tooltip("新增列时的默认列宽(像素)")]
+ public float DefaultColumnWidth = 100f;
+
+ [Tooltip("单元格内容水平内边距(左右各此值)")]
+ public float CellHorizontalPadding = 4f;
+
+ #endregion
+
+ #region 四叉树
+
+ [Header("四叉树")]
+ [Tooltip("单节点最大单元格数,超过此值强制空间分裂以提升可见性裁剪效率")]
+ public int QuadtreeMaxCellsPerNode = 64;
+
+ #endregion
+
+ #region 对象池
+
+ [Header("对象池")]
+ [Tooltip("通用对象池初始容量")]
+ public int PoolInitialCapacity = 64;
+
+ #endregion
+
+ #region 样式回退值
+
+ [Header("样式回退值(当 StyleManager 中查不到时使用)")]
+ [Tooltip("默认样式命名空间")]
+ public string DefaultStyleNamespace = "xeric_table_default";
+
+ [Tooltip("单元格背景色")]
+ public Color BgColor = new Color(0.18f, 0.18f, 0.18f, 1f);
+
+ [Tooltip("单元格前景色(文字颜色)")]
+ public Color FgColor = new Color(0.05f, 0.05f, 0.05f);
+
+ [Tooltip("编辑器选中色")]
+ public Color SelectionColor = new Color(0.2f, 0.5f, 1f, 0.3f);
+
+ [Tooltip("边框颜色")]
+ public Color BorderColor = new Color(0.35f, 0.35f, 0.35f, 0.5f);
+
+ [Tooltip("边框宽度")]
+ public float BorderWidth = 1f;
+
+ [Tooltip("字体大小")]
+ public int FontSize = 14;
+
+ #endregion
+
+ #region 运行时颜色
+
+ [Header("运行时选中/边框颜色")]
+ [Tooltip("运行时单选高亮")]
+ public Color RuntimeSelectionColor = new Color(0.18f, 0.42f, 0.82f, 0.25f);
+
+ [Tooltip("运行时多选高亮")]
+ public Color RuntimeMultiSelectColor = new Color(0.18f, 0.42f, 0.82f, 0.12f);
+
+ [Tooltip("运行时焦点高亮(当前选中格)")]
+ public Color RuntimeFocusColor = new Color(0.22f, 0.55f, 0.95f, 0.35f);
+
+ [Tooltip("运行时边框色")]
+ public Color RuntimeBorderColor = new Color(0.35f, 0.35f, 0.35f, 0.5f);
+
+ [Tooltip("运行时边框宽度")]
+ public float RuntimeBorderWidth = 1f;
+
+ #endregion
+
+ #region 编辑器多选颜色因子
+
+ [Header("编辑器多选/焦点颜色因子(基于 SelectionColor 计算)")]
+ [Tooltip("多选透明因子")]
+ [Range(0, 1)] public float MultiSelectAlphaFactor = 0.4f;
+
+ [Tooltip("焦点色 R 增量")]
+ [Range(0, 0.5f)] public float FocusRAdd = 0.04f;
+
+ [Tooltip("焦点色 G 增量")]
+ [Range(0, 0.5f)] public float FocusGAdd = 0.13f;
+
+ [Tooltip("焦点色 B 增量")]
+ [Range(0, 0.5f)] public float FocusBAdd = 0.13f;
+
+ [Tooltip("焦点色 Alpha 倍数")]
+ [Range(0.1f, 3f)] public float FocusAlphaMul = 1.4f;
+
+ #endregion
+
+ #region 资源路径
+
+ /// Resources 目录下的默认配置文件名(不含扩展名)
+ public const string DEFAULT_RESOURCE_PATH = "XTableDefaultConfig";
+
+ /// 从 Resources 加载默认配置,若失败则返回 ScriptableObject.CreateInstance 的默认值
+ public static XTableConfig LoadOrDefault()
+ {
+ var cfg = Resources.Load(DEFAULT_RESOURCE_PATH);
+ if (cfg != null) return cfg;
+ return CreateInstance();
+ }
+
+ #endregion
+ }
+}
diff --git a/Runtime/XTable/Core/XTableConfig.cs.meta b/Runtime/XTable/Core/XTableConfig.cs.meta
new file mode 100644
index 0000000..57f4c9b
--- /dev/null
+++ b/Runtime/XTable/Core/XTableConfig.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 94d64cced79c6ef41af29f7473ff5105
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Runtime/XTable/Core/XTableQuadtree.cs b/Runtime/XTable/Core/XTableQuadtree.cs
index 1ec3b63..997f757 100644
--- a/Runtime/XTable/Core/XTableQuadtree.cs
+++ b/Runtime/XTable/Core/XTableQuadtree.cs
@@ -65,12 +65,17 @@ namespace XericUI.XTable.Core
private Node m_Root;
private float[] m_RowHeights;
private float[] m_ColWidths;
+ private int m_MaxCellsPerNode;
/// 四叉树是否已构建完成
public bool IsBuilt { get; private set; }
#endregion
+ #region 常量
+
+ #endregion
+
#region 构建
///
@@ -83,7 +88,7 @@ namespace XericUI.XTable.Core
/// 所有有数据的单元格元数据列表
public void Build(float totalWidth, float totalHeight,
float[] rowHeights, float[] colWidths,
- List cells)
+ List cells, int maxCellsPerNode = 64)
{
if (rowHeights == null || colWidths == null || cells == null)
{
@@ -93,6 +98,7 @@ namespace XericUI.XTable.Core
m_RowHeights = rowHeights;
m_ColWidths = colWidths;
+ m_MaxCellsPerNode = maxCellsPerNode;
m_Root = new Node { Region = new Rect(0, 0, totalWidth, totalHeight) };
int maxRow = rowHeights.Length - 1;
@@ -109,10 +115,10 @@ namespace XericUI.XTable.Core
/// 强制重建(外部入口,通常由表格组件在数据/布局变更后调用)
public void ForceRebuild(float totalWidth, float totalHeight,
float[] rowHeights, float[] colWidths,
- List cells)
+ List cells, int maxCellsPerNode = 64)
{
Clear();
- Build(totalWidth, totalHeight, rowHeights, colWidths, cells);
+ Build(totalWidth, totalHeight, rowHeights, colWidths, cells, maxCellsPerNode);
}
private void BuildNode(Node node, List allCells,
@@ -149,11 +155,20 @@ namespace XericUI.XTable.Core
if (allSame)
{
- node.UniformNamespace = firstNs;
- node.Cells = new List<(int, int)>(cellsInRange.Count);
- for (int i = 0; i < cellsInRange.Count; i++)
- node.Cells.Add((cellsInRange[i].Row, cellsInRange[i].Col));
- return;
+ // 命名空间统一,但若空间跨度过大则继续分裂以便按块跳过不可见区域
+ if (cellsInRange.Count > m_MaxCellsPerNode &&
+ (minRow < maxRow || minCol < maxCol))
+ {
+ // 继续执行分裂逻辑(不要 return)
+ }
+ else
+ {
+ node.UniformNamespace = firstNs;
+ node.Cells = new List<(int, int)>(cellsInRange.Count);
+ for (int i = 0; i < cellsInRange.Count; i++)
+ node.Cells.Add((cellsInRange[i].Row, cellsInRange[i].Col));
+ return;
+ }
}
// 无法继续分裂(单行单列),强制标记为均匀
diff --git a/Runtime/XTable/Rendering/Component/TableRenderer.cs b/Runtime/XTable/Rendering/Component/TableRenderer.cs
index 6f7760d..691d2e6 100644
--- a/Runtime/XTable/Rendering/Component/TableRenderer.cs
+++ b/Runtime/XTable/Rendering/Component/TableRenderer.cs
@@ -29,6 +29,13 @@ namespace XericUI.XTable.Rendering.Component
/// Texture2D → Sprite 缓存,避免每帧分配
private Dictionary m_SpriteCache;
+ /// 单元格内容水平内边距(单侧),由 XericUIActionTable 设置
+ public float CellPadding;
+ private float CellPadding2 => CellPadding * 2f;
+
+ /// 表格全局配置资源,由 XericUIActionTable 设置
+ public XTableConfig Config;
+
#endregion
#region 公开属性
@@ -194,8 +201,8 @@ namespace XericUI.XTable.Rendering.Component
float borderWidth = GetStyleFloat(defaultNs, XericUIActionTable.STYLE_CELL_BORDER_BOTTOM_WIDTH,
XericUIActionTable.BORDER_WIDTH_FALLBACK);
- Color multiSelectColor = new Color(selectionColor.r, selectionColor.g, selectionColor.b, selectionColor.a * 0.4f);
- Color focusColor = new Color(selectionColor.r + 0.04f, selectionColor.g + 0.13f, selectionColor.b + 0.13f, selectionColor.a * 1.4f);
+ Color multiSelectColor = new Color(selectionColor.r, selectionColor.g, selectionColor.b, selectionColor.a * Config.MultiSelectAlphaFactor);
+ Color focusColor = new Color(selectionColor.r + Config.FocusRAdd, selectionColor.g + Config.FocusGAdd, selectionColor.b + Config.FocusBAdd, selectionColor.a * Config.FocusAlphaMul);
int selRow = GetSelectedRow();
int selCol = GetSelectedCol();
@@ -258,8 +265,8 @@ namespace XericUI.XTable.Rendering.Component
if (!string.IsNullOrEmpty(data.Text))
{
var txt = m_Assembler.GetText("cell_text", cellNS);
- txt.Rect.anchoredPosition = new Vector2(cellX + 4, cellY);
- txt.Rect.sizeDelta = new Vector2(cellW - 8, cellH);
+ txt.Rect.anchoredPosition = new Vector2(cellX + CellPadding, cellY);
+ txt.Rect.sizeDelta = new Vector2(cellW - CellPadding2, cellH);
txt.Text.text = data.Text;
txt.Text.color = GetStyleColor(cellNS, XericUIActionTable.STYLE_CELL_FG_COLOR,
XericUIActionTable.FG_COLOR_FALLBACK);
@@ -275,8 +282,8 @@ namespace XericUI.XTable.Rendering.Component
{
Sprite sprite = GetOrCreateSprite(data.Image);
var img = m_Assembler.GetImage("cell_image", cellNS);
- img.Rect.anchoredPosition = new Vector2(cellX + 4, cellY);
- img.Rect.sizeDelta = new Vector2(cellW - 8, cellH);
+ img.Rect.anchoredPosition = new Vector2(cellX + CellPadding, cellY);
+ img.Rect.sizeDelta = new Vector2(cellW - CellPadding2, cellH);
img.Image.sprite = sprite;
}
break;
@@ -300,9 +307,9 @@ namespace XericUI.XTable.Rendering.Component
private void RenderCellsRuntime(int sr, int er, int sc, int ec,
float[] rowHeights, float[] colWidths, XTableData tableData, string defaultNs)
{
- Color rtSelectionColor = XericUIActionTable.RT_SELECTION_COLOR;
- Color rtMultiSelectColor = XericUIActionTable.RT_MULTI_SELECT_COLOR;
- Color rtFocusColor = XericUIActionTable.RT_FOCUS_COLOR;
+ Color rtSelectionColor = Config.RuntimeSelectionColor;
+ Color rtMultiSelectColor = Config.RuntimeMultiSelectColor;
+ Color rtFocusColor = Config.RuntimeFocusColor;
int selRow = GetSelectedRow();
int selCol = GetSelectedCol();
@@ -347,13 +354,13 @@ namespace XericUI.XTable.Rendering.Component
var hLine = m_Assembler.GetImage("cell_hline");
hLine.Rect.anchoredPosition = new Vector2(cellX, cellY - cellH);
- hLine.Rect.sizeDelta = new Vector2(cellW, XericUIActionTable.RT_BORDER_WIDTH);
- hLine.Image.color = XericUIActionTable.RT_BORDER_COLOR;
+ hLine.Rect.sizeDelta = new Vector2(cellW, Config.RuntimeBorderWidth);
+ hLine.Image.color = Config.RuntimeBorderColor;
var vLine = m_Assembler.GetImage("cell_vline");
- vLine.Rect.anchoredPosition = new Vector2(cellX + cellW - XericUIActionTable.RT_BORDER_WIDTH, cellY);
- vLine.Rect.sizeDelta = new Vector2(XericUIActionTable.RT_BORDER_WIDTH, cellH);
- vLine.Image.color = XericUIActionTable.RT_BORDER_COLOR;
+ vLine.Rect.anchoredPosition = new Vector2(cellX + cellW - Config.RuntimeBorderWidth, cellY);
+ vLine.Rect.sizeDelta = new Vector2(Config.RuntimeBorderWidth, cellH);
+ vLine.Image.color = Config.RuntimeBorderColor;
if (data == null) continue;
@@ -363,8 +370,8 @@ namespace XericUI.XTable.Rendering.Component
if (!string.IsNullOrEmpty(data.Text))
{
var txt = m_Assembler.GetText("cell_text", cellNS);
- txt.Rect.anchoredPosition = new Vector2(cellX + 4, cellY);
- txt.Rect.sizeDelta = new Vector2(cellW - 8, cellH);
+ txt.Rect.anchoredPosition = new Vector2(cellX + CellPadding, cellY);
+ txt.Rect.sizeDelta = new Vector2(cellW - CellPadding2, cellH);
txt.Text.text = data.Text;
}
break;
@@ -373,8 +380,8 @@ namespace XericUI.XTable.Rendering.Component
{
Sprite sprite = GetOrCreateSprite(data.Image);
var img = m_Assembler.GetImage("cell_image", cellNS);
- img.Rect.anchoredPosition = new Vector2(cellX + 4, cellY);
- img.Rect.sizeDelta = new Vector2(cellW - 8, cellH);
+ img.Rect.anchoredPosition = new Vector2(cellX + CellPadding, cellY);
+ img.Rect.sizeDelta = new Vector2(cellW - CellPadding2, cellH);
img.Image.sprite = sprite;
}
break;
diff --git a/Runtime/XTable/Rendering/Component/XericUIActionTable.cs b/Runtime/XTable/Rendering/Component/XericUIActionTable.cs
index cfc3f97..c1f0894 100644
--- a/Runtime/XTable/Rendering/Component/XericUIActionTable.cs
+++ b/Runtime/XTable/Rendering/Component/XericUIActionTable.cs
@@ -10,7 +10,6 @@ using XericUI.XTable.Mapping;
using XericUI.XTable.Rendering.Elements;
using XericLibrary.Runtime.SuperStyleSheet;
using XericLibrary.Runtime.UIGraph;
-using XericUI.XTable.Core;
#if UNITY_EDITOR
using UnityEditor;
#endif
@@ -26,12 +25,6 @@ namespace XericUI.XTable.Rendering.Component
[AddComponentMenu("Xeric UI Vessel/Table/Xeric UI Action Table", 60)]
public partial class XericUIActionTable : XericUIBehaciour, IPointerClickHandler
{
- #region 常量
-
- private const string DEFAULT_STYLE_NS = "xeric_table_default";
-
- #endregion
-
#region 序列化字段
[SerializeField] private XTableData m_TableData;
@@ -40,7 +33,11 @@ namespace XericUI.XTable.Rendering.Component
[SerializeField] private float[] m_ColWidths = new float[] { 100f, 80f, 120f };
- [SerializeField] private string m_DefaultStyleNamespace = DEFAULT_STYLE_NS;
+ [SerializeField] private string m_DefaultStyleNamespace = "";
+
+ [SerializeField]
+ [Tooltip("表格全局配置资源")]
+ private XTableConfig m_Config;
[SerializeField] private ScrollRect m_ScrollRect;
@@ -186,6 +183,23 @@ namespace XericUI.XTable.Rendering.Component
}
}
+ /// 表格全局配置资源
+ public XTableConfig Config
+ {
+ get
+ {
+ if (m_Config == null)
+ m_Config = XTableConfig.LoadOrDefault();
+ return m_Config;
+ }
+ set => m_Config = value;
+ }
+
+ /// 单元格内容水平内边距(单侧)
+ private float CellPadding => Config.CellHorizontalPadding;
+ /// 单元格内容宽度扣除量
+ private float CellPadding2 => Config.CellHorizontalPadding * 2f;
+
///
/// 基于四叉树查询结果渲染可见象限内的单元格内容(文本/预制体/选择高亮)。
/// 边框由 统一绘制。
@@ -198,8 +212,8 @@ namespace XericUI.XTable.Rendering.Component
if (!Application.isPlaying)
{
Color selectionColor = GetCellSelectionBgColor(ns);
- Color multiSelectColor = new Color(selectionColor.r, selectionColor.g, selectionColor.b, selectionColor.a * 0.4f);
- Color focusColor = new Color(selectionColor.r + 0.04f, selectionColor.g + 0.13f, selectionColor.b + 0.13f, selectionColor.a * 1.4f);
+ Color multiSelectColor = new Color(selectionColor.r, selectionColor.g, selectionColor.b, selectionColor.a * Config.MultiSelectAlphaFactor);
+ Color focusColor = new Color(selectionColor.r + Config.FocusRAdd, selectionColor.g + Config.FocusGAdd, selectionColor.b + Config.FocusBAdd, selectionColor.a * Config.FocusAlphaMul);
foreach (var q in quadrants)
{
@@ -261,8 +275,8 @@ namespace XericUI.XTable.Rendering.Component
if (!string.IsNullOrEmpty(data.Text))
{
var txt = m_Assembler.GetText("cell_text", cellNS);
- txt.Rect.anchoredPosition = new Vector2(cellX + 4, cellY);
- txt.Rect.sizeDelta = new Vector2(cellW - 8, cellH);
+ txt.Rect.anchoredPosition = new Vector2(cellX + CellPadding, cellY);
+ txt.Rect.sizeDelta = new Vector2(cellW - CellPadding2, cellH);
txt.Text.text = data.Text;
txt.Text.color = GetCellFgColor(cellNS);
txt.Text.fontSize = GetCellFontSize(cellNS);
@@ -275,8 +289,8 @@ namespace XericUI.XTable.Rendering.Component
{
Sprite sprite = GetOrCreateSprite(data.Image);
var img = m_Assembler.GetImage("cell_image", cellNS);
- img.Rect.anchoredPosition = new Vector2(cellX + 4, cellY);
- img.Rect.sizeDelta = new Vector2(cellW - 8, cellH);
+ img.Rect.anchoredPosition = new Vector2(cellX + CellPadding, cellY);
+ img.Rect.sizeDelta = new Vector2(cellW - CellPadding2, cellH);
img.Image.sprite = sprite;
}
break;
@@ -300,9 +314,9 @@ namespace XericUI.XTable.Rendering.Component
#endif
// 运行时模式
- Color rtSelectionColor = RT_SELECTION_COLOR;
- Color rtMultiSelectColor = RT_MULTI_SELECT_COLOR;
- Color rtFocusColor = RT_FOCUS_COLOR;
+ Color rtSelectionColor = Config.RuntimeSelectionColor;
+ Color rtMultiSelectColor = Config.RuntimeMultiSelectColor;
+ Color rtFocusColor = Config.RuntimeFocusColor;
foreach (var q in quadrants)
{
@@ -362,8 +376,8 @@ namespace XericUI.XTable.Rendering.Component
if (!string.IsNullOrEmpty(data.Text))
{
var txt = m_Assembler.GetText("cell_text", cellNS);
- txt.Rect.anchoredPosition = new Vector2(cellX + 4, cellY);
- txt.Rect.sizeDelta = new Vector2(cellW - 8, cellH);
+ txt.Rect.anchoredPosition = new Vector2(cellX + CellPadding, cellY);
+ txt.Rect.sizeDelta = new Vector2(cellW - CellPadding2, cellH);
txt.Text.text = data.Text;
}
break;
@@ -372,8 +386,8 @@ namespace XericUI.XTable.Rendering.Component
{
Sprite sprite = GetOrCreateSprite(data.Image);
var img = m_Assembler.GetImage("cell_image", cellNS);
- img.Rect.anchoredPosition = new Vector2(cellX + 4, cellY);
- img.Rect.sizeDelta = new Vector2(cellW - 8, cellH);
+ img.Rect.anchoredPosition = new Vector2(cellX + CellPadding, cellY);
+ img.Rect.sizeDelta = new Vector2(cellW - CellPadding2, cellH);
img.Image.sprite = sprite;
}
break;
@@ -405,6 +419,12 @@ namespace XericUI.XTable.Rendering.Component
// 域重载后旧子对象可能残留在场景中(DontSave 不自动销毁),先清空再重建
ClearAllChildren();
+ if (m_Config == null)
+ m_Config = XTableConfig.LoadOrDefault();
+
+ if (string.IsNullOrEmpty(m_DefaultStyleNamespace))
+ m_DefaultStyleNamespace = Config.DefaultStyleNamespace;
+
if (m_TableData == null)
m_TableData = new XTableData();
@@ -675,9 +695,10 @@ namespace XericUI.XTable.Rendering.Component
public bool IsMergeSource(int row, int col, out int rowSpan, out int colSpan)
=> TableData.IsMergeSource(row, col, out rowSpan, out colSpan);
- /// 在末尾追加一行,默认行高 40
- public void AddRow(float height = 40f)
+ /// 在末尾追加一行,默认行高来自 Config
+ public void AddRow(float height = -1f)
{
+ if (height <= 0) height = Config.DefaultRowHeight;
#if UNITY_EDITOR
UnityEditor.Undo.RecordObject(this, "Add Table Row");
#endif
@@ -692,9 +713,10 @@ namespace XericUI.XTable.Rendering.Component
#endif
}
- /// 在末尾追加一列,默认列宽 100
- public void AddColumn(float width = 100f)
+ /// 在末尾追加一列,默认列宽来自 Config
+ public void AddColumn(float width = -1f)
{
+ if (width <= 0) width = Config.DefaultColumnWidth;
#if UNITY_EDITOR
UnityEditor.Undo.RecordObject(this, "Add Table Column");
#endif
@@ -1243,8 +1265,8 @@ namespace XericUI.XTable.Rendering.Component
Color borderColor = GetCellBorderColor(ns);
float borderWidth = GetCellBorderWidth(ns);
- Color multiSelectColor = new Color(selectionColor.r, selectionColor.g, selectionColor.b, selectionColor.a * 0.4f);
- Color focusColor = new Color(selectionColor.r + 0.04f, selectionColor.g + 0.13f, selectionColor.b + 0.13f, selectionColor.a * 1.4f);
+ Color multiSelectColor = new Color(selectionColor.r, selectionColor.g, selectionColor.b, selectionColor.a * Config.MultiSelectAlphaFactor);
+ Color focusColor = new Color(selectionColor.r + Config.FocusRAdd, selectionColor.g + Config.FocusGAdd, selectionColor.b + Config.FocusBAdd, selectionColor.a * Config.FocusAlphaMul);
for (int r = sr; r < er && r < m_RowHeights.Length; r++)
{
@@ -1308,8 +1330,8 @@ namespace XericUI.XTable.Rendering.Component
if (!string.IsNullOrEmpty(data.Text))
{
var txt = m_Assembler.GetText("cell_text", cellNS);
- txt.Rect.anchoredPosition = new Vector2(cellX + 4, cellY);
- txt.Rect.sizeDelta = new Vector2(cellW - 8, cellH);
+ txt.Rect.anchoredPosition = new Vector2(cellX + CellPadding, cellY);
+ txt.Rect.sizeDelta = new Vector2(cellW - CellPadding2, cellH);
txt.Text.text = data.Text;
txt.Text.color = GetCellFgColor(cellNS);
txt.Text.fontSize = GetCellFontSize(cellNS);
@@ -1322,8 +1344,8 @@ namespace XericUI.XTable.Rendering.Component
{
Sprite sprite = GetOrCreateSprite(data.Image);
var img = m_Assembler.GetImage("cell_image", cellNS);
- img.Rect.anchoredPosition = new Vector2(cellX + 4, cellY);
- img.Rect.sizeDelta = new Vector2(cellW - 8, cellH);
+ img.Rect.anchoredPosition = new Vector2(cellX + CellPadding, cellY);
+ img.Rect.sizeDelta = new Vector2(cellW - CellPadding2, cellH);
img.Image.sprite = sprite;
}
break;
@@ -1346,9 +1368,9 @@ namespace XericUI.XTable.Rendering.Component
#endif
// 运行时模式
- Color rtSelectionColor = RT_SELECTION_COLOR;
- Color rtMultiSelectColor = RT_MULTI_SELECT_COLOR;
- Color rtFocusColor = RT_FOCUS_COLOR;
+ Color rtSelectionColor = Config.RuntimeSelectionColor;
+ Color rtMultiSelectColor = Config.RuntimeMultiSelectColor;
+ Color rtFocusColor = Config.RuntimeFocusColor;
for (int r = sr; r < er && r < m_RowHeights.Length; r++)
{
@@ -1393,13 +1415,13 @@ namespace XericUI.XTable.Rendering.Component
var hLine = m_Assembler.GetImage("cell_hline");
hLine.Rect.anchoredPosition = new Vector2(cellX, cellY - cellH);
- hLine.Rect.sizeDelta = new Vector2(cellW, RT_BORDER_WIDTH);
- hLine.Image.color = RT_BORDER_COLOR;
+ hLine.Rect.sizeDelta = new Vector2(cellW, Config.RuntimeBorderWidth);
+ hLine.Image.color = Config.RuntimeBorderColor;
var vLine = m_Assembler.GetImage("cell_vline");
- vLine.Rect.anchoredPosition = new Vector2(cellX + cellW - RT_BORDER_WIDTH, cellY);
- vLine.Rect.sizeDelta = new Vector2(RT_BORDER_WIDTH, cellH);
- vLine.Image.color = RT_BORDER_COLOR;
+ vLine.Rect.anchoredPosition = new Vector2(cellX + cellW - Config.RuntimeBorderWidth, cellY);
+ vLine.Rect.sizeDelta = new Vector2(Config.RuntimeBorderWidth, cellH);
+ vLine.Image.color = Config.RuntimeBorderColor;
if (data == null) continue;
@@ -1409,8 +1431,8 @@ namespace XericUI.XTable.Rendering.Component
if (!string.IsNullOrEmpty(data.Text))
{
var txt = m_Assembler.GetText("cell_text", cellNS);
- txt.Rect.anchoredPosition = new Vector2(cellX + 4, cellY);
- txt.Rect.sizeDelta = new Vector2(cellW - 8, cellH);
+ txt.Rect.anchoredPosition = new Vector2(cellX + CellPadding, cellY);
+ txt.Rect.sizeDelta = new Vector2(cellW - CellPadding2, cellH);
txt.Text.text = data.Text;
// 运行时样式由 StyleBoundElement 被动更新,此处仅设置文本内容
}
@@ -1420,8 +1442,8 @@ namespace XericUI.XTable.Rendering.Component
{
Sprite sprite = GetOrCreateSprite(data.Image);
var img = m_Assembler.GetImage("cell_image", cellNS);
- img.Rect.anchoredPosition = new Vector2(cellX + 4, cellY);
- img.Rect.sizeDelta = new Vector2(cellW - 8, cellH);
+ img.Rect.anchoredPosition = new Vector2(cellX + CellPadding, cellY);
+ img.Rect.sizeDelta = new Vector2(cellW - CellPadding2, cellH);
img.Image.sprite = sprite;
}
break;
@@ -1676,7 +1698,7 @@ namespace XericUI.XTable.Rendering.Component
}
}
- m_Quadtree.Build(m_TotalWidth, m_TotalHeight, m_RowHeights, m_ColWidths, cells);
+ m_Quadtree.Build(m_TotalWidth, m_TotalHeight, m_RowHeights, m_ColWidths, cells, Config.QuadtreeMaxCellsPerNode);
}
#endregion
@@ -1756,12 +1778,12 @@ namespace XericUI.XTable.Rendering.Component
}
else
{
- borderColor = RT_BORDER_COLOR;
- borderWidth = RT_BORDER_WIDTH;
+ borderColor = Config.RuntimeBorderColor;
+ borderWidth = Config.RuntimeBorderWidth;
}
#else
- Color borderColor = RT_BORDER_COLOR;
- float borderWidth = RT_BORDER_WIDTH;
+ Color borderColor = Config.RuntimeBorderColor;
+ float borderWidth = Config.RuntimeBorderWidth;
#endif
int rows = m_RowHeights.Length;
@@ -1850,6 +1872,8 @@ namespace XericUI.XTable.Rendering.Component
// 共享预制体对象池
m_ViewportRenderer.PrefabPool = m_PrefabPool;
m_ViewportRenderer.ActivePrefabMap = m_ActivePrefabMap;
+ m_ViewportRenderer.CellPadding = Config.CellHorizontalPadding;
+ m_ViewportRenderer.Config = Config;
}
/// 渲染 Viewport 层冻结单元格,随滚动偏移调整位置