表格:背景/边框/冻结容器的 rect 每次更新都按尺寸钉回左上角

认领回来的旧生成物(_TableBackground / _TableBorders / 冻结容器)可能还带着上一版的
中心锚点,而 UpdateBackground 只改 sizeDelta、边框的认领路径干脆不改 rect——于是渲染器
以自己的局部原点(pivot 0.5)为左上角画出去,画面就是"以父组件中心为左上角"的错位。

新增 PinTopLeftRect:锚点/pivot 钉 (0,1)、锚位按参数、尺寸按总宽高,只在值不同时写。
背景每次 UpdateBackground、边框认领与刷新、冻结容器每次同步都走它。
This commit is contained in:
2026-11-17 14:59:52 +08:00
parent e4a70d0188
commit 22ef2174da
4 changed files with 39 additions and 5 deletions
@@ -191,6 +191,31 @@ namespace XericUI.XTable.Rendering.Component
return bar;
}
/// <summary>
/// 把生成物的 rect 钉成"锚点左上 + 指定锚位",只在值不同的时候写。
///
/// <para>生成物可能是域重载后认领回来的旧对象(<c>_TableBackground</c> / <c>_TableBorders</c>),
/// 它们的锚点/锚位还是上一版留下的——只改 sizeDelta 就会画出"以父组件中心为左上角"的错位。</para>
/// </summary>
private static void PinTopLeftRect(RectTransform rt, Vector2 position)
{
if (rt == null) return;
Vector2 topLeft = new Vector2(0f, 1f);
if (rt.anchorMin != topLeft) rt.anchorMin = topLeft;
if (rt.anchorMax != topLeft) rt.anchorMax = topLeft;
if (rt.pivot != topLeft) rt.pivot = topLeft;
if (rt.anchoredPosition != position) rt.anchoredPosition = position;
}
/// <summary>同上,顺带把尺寸一起钉死。</summary>
private static void PinTopLeftRect(RectTransform rt, Vector2 position, float width, float height)
{
if (rt == null) return;
PinTopLeftRect(rt, position);
var size = new Vector2(width, height);
if (rt.sizeDelta != size) rt.sizeDelta = size;
}
/// <summary>把生成物及其子物体统一标记为不保存、不进编辑。</summary>
private static void MarkGenerated(GameObject go)
{