fix(UI): 边界框不再内缩 + 文本获得几何身份 + 补全漏项 + 描边提速 32%

## 1. 取消内缩(这是"边框不清晰"的主因)

第九轮为"父子矩形共边不叠粗"给 depth > 0 的 box 加了 1px 内缩。结果 GX 徽标
(30x17 逻辑像素的胶囊,圆角 = 高的一半,外接矩形正好等于 LaneBadgeRect)内缩 1px 后
框比形状小一圈 ⇒ 左右尖端与上下圆弧全部落在框外。

现行规则:**框 = 可见形状的外接矩形,绝不内缩**。父子共边时让"后画的覆盖"即可,
这本来就是正确的图层语义。层级 > 0 只影响配色,不再影响几何。

## 2. 文本第一次有了几何身份(唯一出口回报,不逐处登记)

文本是本项目唯一"没有几何身份"的元素:65 处绘制点各自现算 gd::RectF、画完即弃。
逐处补登记必漏,因此在唯一出口回报一次:

  PaintUtil 新增
    class UiTextRectSink { virtual void OnTextRect(const gd::RectF&) = 0; };
    void UiSetTextRectSink(UiTextRectSink*);       // 开关关闭时为 nullptr
    void UiSetTextRectOffset(float dx, float dy);  // 离屏位图渲染的坐标换算
    UiTextRectSink* UiGetTextRectSink();

DrawUiText() / UiTextAtClipped() 画完后按对齐方式 + 实测宽高把布局矩形**收窄成墨迹矩形**
再回报。UiDebugBoxList 直接继承该接口,宿主只需 UiSetTextRectSink(&m_debugBoxes) 一句。
开关关闭时只是一次空指针判断,正常绘制零影响。

## 3. 缓存命中的行也要有文本框

面板的行是"先画进位图再贴回",命中缓存的帧**根本不调用 UiText** ⇒ 文本框第二帧起消失。
做法:行渲染时用本地 RowTextCollector 收集(位图坐标)→ 连同位图存进
RowBitmapCache::textRects → 贴图时按 (originX, originY) 回放。
⚠️ **必须无条件收集**:只在"外层有收集器"时收集会导致"关调试时滚过列表 → 打开调试 →
命中缓存 → 永远没有文本框"。

## 4. 补齐 PlotView 漏项(全部读现成成员)

m_timeAxisRect / m_scrollBarRect / BackToTopRect() / m_cursorSpanRect /
m_cursorLabelRects / EditFieldRect()

## 5. 描边提速:图元 12 → 8

微基准结论:图元数量是唯一瓶颈(每次 FillRectangle ≈1µs)。
旧实现把每条边拆成"中段 1px + 两端各一段加粗"= 12 次;新实现 = 4 条 1px 边 + 4 个自适应角块。
实测 paintBoxes 5.892ms → 4.028ms(-32%),观感几乎一致(角仍是两条粗边的交点)。
⚠️ 不要改写成 GraphicsPath/FillPath(单次约 20µs,比 12 段还慢);
GDI PolyPolygon 一次画 5688 个矩形要 114ms,更不能用。

## 6. 关闭开关时清空容器(释放内存,避免误读)

## 7. 验证

- make release / make debug 零 error 零 warning;TargetCheck.exe 909,824 B(888.5 KiB < 900 KiB)。
- 新增探针 .preflight/lbcovr 7/7:box-time-axis / box-plot-scrollbar / box-back-to-top /
  box-gx-badge-matches-pill(容差 0.5px)/ text-boxes-collected(89 个)/
  row-text-boxes-from-cached-rows / boxes-cleared-when-off。
- 回归:lbcheck 21/21、lbresid 5/5、lbzorder 4/4、uicheck 69/69。
- rendercheck:8 个场景的整帧与区域哈希与上一轮**逐一相同** + FUNC 7/7
  (证明调试功能对正常绘制零影响)。
- 帧耗时分解(MF4 / 283 网格):base 9.06ms、仅强制整帧 6.66ms、完整调试 11.35ms;
  collect 0.082ms、paintBoxes 4.028ms(上一轮 5.892ms)。

## 8. 文档

Documents/UI_Refactor_Plan.md / UI_Refactor_Progress.md / UI_Refactor_Report.md 追加第九阶段;
Documents/agent_mem.md 同步变更日志与「2026-10-28 第十一轮」硬约束与踩坑。
This commit is contained in:
DeepSeek V4.1 Flash committed 2026-10-28 17:38:55 +08:00
1 parent 57e12cfb27
commit aa4925a2b7
14 files changed
+635 -107

No files matched your search

+14 -2
View File
@@ -18,6 +18,7 @@
#include "Theme.hpp"
#include "Toolbar.hpp"
#include "UiComponent.hpp"
#include "UiDebugBounds.hpp"
#include "UiSurface.hpp"
namespace jdi
@@ -398,8 +399,11 @@ namespace jdi
/**
* @brief 绘制全部 UI 控件的布局边界(调试开关开启时在 Render 的最后一步调用)。
*
* 遍历组件表(底 → 顶)并让每个组件上报自己的内部结构;随后补上不属于
* 任何组件的两块区域(面板分隔条、客户区外框)。
* 内容分两路:
* * **组件结构**:遍历组件表(底 → 顶)让每个组件上报内部结构,再补上不属于任何
* 组件的区域(客户区外框、面板分隔条、菜单 / 拾色器);
* * **文本**:绘制期间由 `UiSetTextRectSink(&m_debugBoxes)` 自动收集(见 `PaintUtil`),
* 因为文本是本项目唯一"没有几何身份"的元素,它在 60+ 个调用点现算矩形、画完即弃。
*
* @param [IN,OUT] g 绘图上下文。
* @param [IN] width 客户区宽度。
@@ -478,6 +482,14 @@ namespace jdi
*/
bool m_showLayoutBounds = false;
/**
* @brief 调试 box 容器(只在 `m_showLayoutBounds` 为真时使用)。
*
* 作为成员而不是局部变量:避免开关打开时每帧重新分配,
* 也让它能直接充当 `PaintUtil` 的文本收集器(`UiTextRectSink`)。
*/
UiDebugBoxList m_debugBoxes;
/** @brief 填充组件表(`Initialize` 里 `Setup` 之后调用一次)。 */
void BuildComponentTable();
@@ -522,6 +522,21 @@ namespace jdi
g.SetSmoothingMode(gd::SmoothingModeAntiAlias);
g.SetPixelOffsetMode(gd::PixelOffsetModeHalf);
g.SetTextRenderingHint(gd::TextRenderingHintClearTypeGridFit);
// ⚠️ 调试:文本是本项目唯一"没有几何身份"的绘制元素(60+ 个调用点现算矩形、
// 画完即弃),因此在这里安装收集器,让 `PaintUtil` 在绘制时把**实际墨迹矩形**
// 回报给 `m_debugBoxes`。开关关闭时完全不安装(空指针,一次判空即返回)。
if (m_showLayoutBounds)
{
m_debugBoxes.Clear();
m_debugBoxes.SetLayer(2); // 基础内容层(工具栏/面板/绘图区)
UiSetTextRectSink(&m_debugBoxes);
}
else if (!m_debugBoxes.Empty())
{
// 关闭后释放容器(否则上一次的几何会一直占着内存,也容易被误读成"仍在收集")。
m_debugBoxes.Clear();
}
// 信号列表 / 样式区「目标」行的悬停 → 绘图区联动高亮(网格变色 + 该信号曲线高亮)。
// 用户 2026-10-15 要求;鼠标在网格里移动**不再**触发网格变色高亮。
// ⚠️ 每帧同步(而不是只在 WM_MOUSEMOVE 里同步)才能覆盖全部改变悬停的路径:
@@ -553,7 +568,17 @@ namespace jdi
m_plot.Paint(g);
// 弹出菜单与浮动拾色器始终绘制在最上层,保证与主界面风格一致。
// ⚠️ 调试:它们是不透明浮层,文本要记入更高的绘制层,
// 否则会被自己登记到遮挡矩形里的"挖洞"逻辑裁掉。
if (m_showLayoutBounds)
{
m_debugBoxes.SetLayer(5);
}
m_menu.Paint(g);
if (m_showLayoutBounds)
{
m_debugBoxes.SetLayer(6);
}
m_colorPicker.Paint(g);
// 加载遮罩层在一切内容之上(包括菜单与拾色器),形成模态观感。
@@ -563,6 +588,7 @@ namespace jdi
// 位图缓存 —— 否则关掉开关后线条会残留在缓存里。
if (m_showLayoutBounds)
{
UiSetTextRectSink(nullptr);
PaintLayoutBounds(g, width, height);
}
}
@@ -1156,40 +1156,42 @@ namespace jdi
void Application::PaintLayoutBounds(gd::Graphics& g, int width, int height)
{
UiDebugBoxList boxes;
// ⚠️ 复用成员容器(不是局部变量):文本几何已经在**绘制期间**由 `PaintUtil`
// 通过 `UiSetTextRectSink(&m_debugBoxes)` 收进来了,这里只负责补组件结构。
m_debugBoxes.SetLayer(0);
// 客户区外框:便于确认"窗口边缘 == 最外层边界"。
boxes.Add(gd::RectF(0.0f, 0.0f, static_cast<float>(width), static_cast<float>(height)), 0);
m_debugBoxes.Add(gd::RectF(0.0f, 0.0f, static_cast<float>(width),
static_cast<float>(height)), 0);
// 组件区域(底 → 顶;组件自己负责补齐内部结构)。
// ⚠️ 两点都很重要:
// 1. `SetClip(组件区域)`:组件内部的元素可能落在自己地盘之外(典型:滚出可视区的
// 网格 `lane.rect` 的 Y 为负数),不裁剪会把边框画到工具栏/标签栏上
// —— 这正是"工具栏上出现绘制残留"的直接原因。
// 网格 `lane.rect` 的 Y 为负数),不裁剪会把边框画到工具栏/标签栏上。
// 2. 每收集完一个组件就 `PushLayer()`:浮层压在本体之上(右键二级菜单压在行上面),
// 只有按收集顺序分层,后收集的内容才画在上面。
for (const ComponentEntry& entry : m_components)
{
if (entry.component != nullptr)
{
boxes.SetClip(entry.component->Area());
entry.component->CollectDebugBoxes(boxes);
m_debugBoxes.SetClip(entry.component->Area());
entry.component->CollectDebugBoxes(m_debugBoxes);
}
boxes.PushLayer();
m_debugBoxes.PushLayer();
}
// 不属于任何组件的两块:面板分隔条(由宿主直接填充色块)、菜单 / 拾色器(浮层)。
// ⚠️ 浮层**不设裁剪矩形**:菜单的二级子菜单会展开到菜单本体之外,设裁剪会把它裁掉;
// 它们自己会把本体登记为"遮挡矩形"(见 `PopupMenu::CollectDebugBoxes`),
// 由绘制阶段把更低层的 box 从浮层区域里挖掉。
boxes.SetClip(gd::RectF());
boxes.Add(m_splitterRect, 0);
boxes.PushLayer();
m_menu.CollectDebugBoxes(boxes);
boxes.PushLayer();
m_colorPicker.CollectDebugBoxes(boxes);
m_debugBoxes.SetClip(gd::RectF());
m_debugBoxes.Add(m_splitterRect, 0);
m_debugBoxes.PushLayer();
m_menu.CollectDebugBoxes(m_debugBoxes);
m_debugBoxes.PushLayer();
m_colorPicker.CollectDebugBoxes(m_debugBoxes);
UiDebugPaintBoxList(g, boxes);
UiDebugPaintBoxList(g, m_debugBoxes);
}
void Application::DispatchMenuResult(const MenuResult& result)