## 1. 新功能:齿轮按钮 -> 应用设置菜单 -> 显示布局边界 - ToolbarAction::SETTINGS 位于「导入文件」左侧;工具栏布局改为 「左侧固定簇(kLeftClusterCount = 2:齿轮 + 导入文件)+ 右侧按钮组」。 - 齿轮是矢量化绘制(8 齿 + 外环 + 轴孔,全部按 half 的比例推导), 不用字体字符「⚙」——该字符在不同回退字体里大小与基线不一致,会忽大忽小、垂直不居中。 UiButtonWidget 新增 UiButtonIcon(NONE / GEAR)与 SetIcon。 - MenuScope::APP_SETTINGS(新增)+ 设置菜单:HEADER「调试」+ 勾选切换项「显示布局边界」 (keepOpen:点击后菜单保持打开,勾选态由 UpdateItemLabel 回写)。 锚点取 Toolbar::ButtonRect(SETTINGS) 的控件实测矩形,宿主不再自己推算按钮几何。 ## 2. 布局边界:基类给协议,组件自己上报 - UiComponent 新增 virtual PaintDebugBounds(g, scale),默认只画 Area()。 - Toolbar / TabBar 覆盖:跳过与区域重合的根控件,遍历 m_root->Children()(层级 1); TabBar 另上报每个 ✕(层级 2)。 - SignalPanel 覆盖:表头 / 筛选框 / 列表 / 样式区(1)+ 滚动条、样式行、当前可见列表行(2)。 - PlotView 覆盖:每个 LaneVisual::rect(1);不上报随数据变化的瞬态几何(曲线/胶囊/提示)。 - UiWidget 新增 PaintDebugBounds(g, scale, depth) 递归整棵控件树 —— 已上树的控件零成本获得边界。 - 宿主 PaintLayoutBounds 补客户区外框、分隔条、打开的菜单/拾色器。 视觉与实现约束(Android「Show layout bounds」风): - 只描边、不填充(几十个嵌套矩形叠加填充会把内容糊住); - 层级配色 青蓝(2px) / 品红 / 琥珀 / 绿(1px); - 线宽按设备像素固定(不乘 scale),临时 PixelOffsetModeNone + 关抗锯齿 + 整像素对齐, 保证 1px 就是 1px; - ⚠️ 只在 Render 最后一步叠加,绝不进入任何位图缓存(PlotView 4 层缓存 / SignalPanel 行位图缓存), 否则关掉开关后线条会残留; - ⚠️ fullFrame 并入 m_showLayoutBounds:开启时必须整帧回送,否则「只回送绘图区」的快路径 会让装饰区边界停在旧帧上。 ## 3. 可见收益优化(行为不变) - Toolbar::Layout:控件树改为按需重建(m_treeDirty),只在规格/字体/主题/缩放/动态文本 变化时重建。拖动面板分隔条时 Relayout 每帧调用一次 -> 不再每帧 10 次堆分配 + 8 次测量缓存失效。 - Toolbar::SetActionLabel:只写 m_labelOverrides(唯一权威)+ 置树脏,消除「覆盖表与控件文本 双写」可能不同步的问题。 - UiWidget::DispatchRedraw(event):新增;收敛 Toolbar / TabBar 里重复的 Dispatch(); return UiRectHasArea(TakeDirty());(TakeDirty 会清零,漏一次就把下一次真实变化 误判成「无变化」)。 ## 4. 验证 - make release / make debug:零 error 零 warning;TargetCheck.exe 897,024 B(< 900 KB)。 - 新增离屏探针 .preflight/lbcheck:21 / 21 PASS (齿轮在导入文件左侧/同高/更窄;开启后青蓝 24,930 px、品红 19,734 px;关闭后逐像素还原; 菜单 scope、锚定贴合按钮、宽度未被撑大、条目初始未勾选、点击翻转开关、菜单保持打开)。 - Tools/rendercheck:8 个场景的「工具栏带以下区域」哈希与改造前**逐一相同** (证明改动像素被完全限制在工具栏带内);整帧哈希因新增按钮整体变化,属预期。 FUNC 断言 7 / 7 PASS。 - Tools/uicheck:69 passed / 0 failed。 ## 5. 文档 Documents/UI_Refactor_Plan.md / UI_Refactor_Progress.md / UI_Refactor_Report.md 追加第六阶段; Documents/agent_mem.md 同步变更日志与「2026-10-28 第八轮」硬约束与验证坑。
97 lines
3.2 KiB
C++
97 lines
3.2 KiB
C++
#include "UiDebugBounds.hpp"
|
|
|
|
#include <cmath>
|
|
|
|
namespace jdi
|
|
{
|
|
|
|
namespace
|
|
{
|
|
/** @brief 顶层组件区域的描边宽度(设备像素)。 */
|
|
const int kAreaStroke = 2;
|
|
/** @brief 内部控件 / 子块的描边宽度(设备像素)。 */
|
|
const int kNodeStroke = 1;
|
|
|
|
/**
|
|
* @brief 用整数像素矩形填充(要求调用方已把像素偏移模式设为 `None`)。
|
|
*
|
|
* 走 GDI+ 而不是 `UiFillRect`:这里需要**精确的 1px 覆盖**,而 `UiFillRect` 的快
|
|
* 路径按 `floor/ceil` 取整并可能转交 GDI,混进调试层会带来额外的状态切换开销。
|
|
*/
|
|
void FillPixels(gd::Graphics& g, int x, int y, int width, int height, std::uint32_t argb)
|
|
{
|
|
if (width <= 0 || height <= 0)
|
|
{
|
|
return;
|
|
}
|
|
gd::SolidBrush brush{gd::Color(argb)};
|
|
g.FillRectangle(&brush, x, y, width, height);
|
|
}
|
|
} // namespace
|
|
|
|
std::uint32_t UiDebugBoundsColor(int depth)
|
|
{
|
|
// 与主题无关的固定配色:调试层必须"永远显眼",不能跟随用户主题变成接近底色。
|
|
switch (depth)
|
|
{
|
|
case 0:
|
|
return 0xFF29B6F6u; // 青蓝:顶层组件区域
|
|
case 1:
|
|
return 0xFFE040FBu; // 品红:控件节点
|
|
case 2:
|
|
return 0xFFFFB300u; // 琥珀:内部子块
|
|
default:
|
|
return 0xFF66BB6Au; // 绿:更深的子块
|
|
}
|
|
}
|
|
|
|
void UiDebugPaintBounds(gd::Graphics& g, const gd::RectF& rect, int depth, float scale)
|
|
{
|
|
(void)scale; // 线宽刻意不随 DPI 变化(见头文件说明),此参数保留以便将来做对齐细分。
|
|
|
|
if (!(rect.Width > 0.0f) || !(rect.Height > 0.0f))
|
|
{
|
|
return;
|
|
}
|
|
|
|
// 对齐到整像素:把矩形四边四舍五入,保证 1px 描边正好压住一格像素。
|
|
const int left = static_cast<int>(std::lround(rect.X));
|
|
const int top = static_cast<int>(std::lround(rect.Y));
|
|
int right = static_cast<int>(std::lround(rect.X + rect.Width)) - 1;
|
|
int bottom = static_cast<int>(std::lround(rect.Y + rect.Height)) - 1;
|
|
if (right < left)
|
|
{
|
|
right = left;
|
|
}
|
|
if (bottom < top)
|
|
{
|
|
bottom = top;
|
|
}
|
|
|
|
const int width = right - left + 1;
|
|
const int height = bottom - top + 1;
|
|
const int level = (depth < 0) ? 0 : depth;
|
|
const std::uint32_t color = UiDebugBoundsColor(level);
|
|
const int stroke = (level == 0) ? kAreaStroke : kNodeStroke;
|
|
|
|
const gd::GraphicsState state = g.Save();
|
|
// 描边必须锐利:关抗锯齿 + 关半像素偏移,矩形已对齐整像素 ⇒ 1px 就是 1px。
|
|
g.SetSmoothingMode(gd::SmoothingModeNone);
|
|
g.SetPixelOffsetMode(gd::PixelOffsetModeNone);
|
|
|
|
// ⚠️ **只描边、不填充**(与 Android「Show layout bounds」一致):
|
|
// 填充会在几十个嵌套矩形上层层叠加,把内容糊成一片,反而看不出真实边界。
|
|
|
|
// 四条边(用实心矩形而不是 `DrawRectangle`:后者会因笔宽奇偶而偏移半像素)。
|
|
const int thick = (stroke * 2 <= width) ? stroke : 1;
|
|
const int thickY = (stroke * 2 <= height) ? stroke : 1;
|
|
FillPixels(g, left, top, width, thickY, color); // 上
|
|
FillPixels(g, left, bottom - thickY + 1, width, thickY, color); // 下
|
|
FillPixels(g, left, top, thick, height, color); // 左
|
|
FillPixels(g, right - thick + 1, top, thick, height, color); // 右
|
|
|
|
g.Restore(state);
|
|
}
|
|
|
|
} // namespace jdi
|