feat(UI): 显示布局边界(Android 风格)+ 工具栏设置菜单(齿轮)+ 三处可见收益优化
## 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 第八轮」硬约束与验证坑。
This commit is contained in:
1 parent
0ec8055e95
commit
ab19a6e72e
26 files changed
+997
-55
No files matched your search
@@ -1,9 +1,11 @@
|
||||
// Application 实现分片 —— 本文件只包含 Application 的**成员函数定义**(纯代码搬移,行为与拆分前完全一致)。
|
||||
// Application 实现分片 —— 本文件包含:标签页管理、工具栏动作、设置菜单、键盘、菜单结果派发。
|
||||
//
|
||||
// 共用的常量与自由函数在 ApplicationInternal.hpp(命名空间 `appdetail`,全部 inline)。
|
||||
// 分片按“职责”划分:核心(状态/布局/几何)、渲染、交互与编辑,见各文件名。
|
||||
// 共用的常量与工具函数在 ApplicationInternal.hpp(命名空间 `appdetail`,全部 inline)。
|
||||
// 分片按"职责"划分:核心(状态/布局)、渲染、命令与菜单、加载。
|
||||
#include "ApplicationInternal.hpp"
|
||||
|
||||
#include "UiDebugBounds.hpp"
|
||||
|
||||
namespace jdi
|
||||
{
|
||||
|
||||
@@ -305,6 +307,15 @@ namespace jdi
|
||||
{
|
||||
switch (action)
|
||||
{
|
||||
case ToolbarAction::SETTINGS:
|
||||
// 齿轮按钮只负责**展开菜单**:不改变任何业务状态,因此不必走后面的"整帧失效",
|
||||
// 只需要把浮层画出来(菜单打开后 `Render` 会因 `overlaysVisible` 自动整帧重绘)。
|
||||
OpenSettingsMenu();
|
||||
if (m_hwnd != nullptr)
|
||||
{
|
||||
InvalidateRect(m_hwnd, nullptr, TRUE);
|
||||
}
|
||||
return;
|
||||
case ToolbarAction::OPEN_FILE:
|
||||
OpenFileDialog();
|
||||
break;
|
||||
@@ -1106,6 +1117,70 @@ namespace jdi
|
||||
m_plot.AllLanesAutoFitToSelection(), true);
|
||||
}
|
||||
|
||||
void Application::OpenSettingsMenu()
|
||||
{
|
||||
// 锚点取齿轮按钮的**实际矩形**:按钮宽度由控件实测,宿主不应自己推算几何。
|
||||
gd::RectF anchor;
|
||||
if (!m_toolbar.ButtonRect(ToolbarAction::SETTINGS, anchor))
|
||||
{
|
||||
// 尚未布局(极端情形):退化为从菜单快捷键位置展开,而不是什么都不发生。
|
||||
anchor = m_toolbarRect;
|
||||
}
|
||||
|
||||
std::vector<MenuItem> items;
|
||||
|
||||
// ── 调试 ──────────────────────────────────────────────
|
||||
MenuItem debugHeader;
|
||||
debugHeader.kind = MenuItemKind::HEADER;
|
||||
debugHeader.label = L"调试";
|
||||
items.push_back(debugHeader);
|
||||
|
||||
MenuItem boundsItem;
|
||||
boundsItem.label = L"显示布局边界";
|
||||
boundsItem.id = kAppCmdShowLayoutBounds;
|
||||
boundsItem.checked = m_showLayoutBounds;
|
||||
// 切换项:点击后菜单保持打开,勾选态由宿主回写(与既有「镜像」等切换项一致)。
|
||||
boundsItem.keepOpen = true;
|
||||
items.push_back(boundsItem);
|
||||
|
||||
RECT client = {};
|
||||
GetClientRect(m_hwnd, &client);
|
||||
const gd::RectF bounds(0.0f, 0.0f, static_cast<float>(client.right - client.left),
|
||||
static_cast<float>(client.bottom - client.top));
|
||||
|
||||
// 右下展开,锚在按钮**下沿**(留 4 逻辑像素,视觉上不贴着按钮边框)。
|
||||
const int x = static_cast<int>(anchor.X);
|
||||
const int y = static_cast<int>(anchor.Y + anchor.Height + 4.0f * m_scale);
|
||||
m_menu.Open(MenuScope::APP_SETTINGS, bounds, x, y, items);
|
||||
}
|
||||
|
||||
void Application::PaintLayoutBounds(gd::Graphics& g, int width, int height)
|
||||
{
|
||||
// 客户区外框:便于确认"窗口边缘 == 最外层边界"。
|
||||
UiDebugPaintBounds(g, gd::RectF(0.0f, 0.0f, static_cast<float>(width),
|
||||
static_cast<float>(height)), 0, m_scale);
|
||||
|
||||
// 组件区域(底 → 顶;组件自己负责再上报内部结构)。
|
||||
for (const ComponentEntry& entry : m_components)
|
||||
{
|
||||
if (entry.component != nullptr)
|
||||
{
|
||||
entry.component->PaintDebugBounds(g, m_scale);
|
||||
}
|
||||
}
|
||||
|
||||
// 不属于任何组件的两块:面板分隔条(由宿主直接填充色块)、菜单/拾色器(浮层)。
|
||||
UiDebugPaintBounds(g, m_splitterRect, 0, m_scale);
|
||||
if (m_menu.IsOpen())
|
||||
{
|
||||
UiDebugPaintBounds(g, m_menu.Rect(), 0, m_scale);
|
||||
}
|
||||
if (m_colorPicker.IsOpen())
|
||||
{
|
||||
UiDebugPaintBounds(g, m_colorPicker.Rect(), 0, m_scale);
|
||||
}
|
||||
}
|
||||
|
||||
void Application::DispatchMenuResult(const MenuResult& result)
|
||||
{
|
||||
if (!result.valid)
|
||||
@@ -1115,6 +1190,20 @@ namespace jdi
|
||||
|
||||
switch (result.scope)
|
||||
{
|
||||
case MenuScope::APP_SETTINGS:
|
||||
{
|
||||
// 应用设置菜单:全部条目都是**带勾选态的切换项**,菜单保持打开,
|
||||
// 勾选变化通过 `UpdateItemLabel` 立即回写(连续切换多项时不用反复打开菜单)。
|
||||
if (result.id == kAppCmdShowLayoutBounds)
|
||||
{
|
||||
m_showLayoutBounds = !m_showLayoutBounds;
|
||||
m_menu.UpdateItemLabel(kAppCmdShowLayoutBounds, L"显示布局边界", m_showLayoutBounds);
|
||||
// 边界比组件矩形外扩 1px 且跨越所有装饰区 ⇒ 必须整帧重绘。
|
||||
m_chromeDirty = true;
|
||||
}
|
||||
InvalidateRect(m_hwnd, nullptr, TRUE);
|
||||
break;
|
||||
}
|
||||
case MenuScope::SIGNAL_PANEL:
|
||||
{
|
||||
const bool needRelayout = m_panel.OnMenuCommand(result);
|
||||
|
||||
Reference in new issue
Block a user