重构(UI): 统一组件协议 + 去手写链路 + 大文件按职责拆分 + 代码审查 + 剥离 Tools
## 1. 新增 UiComponent 顶层组件协议(不是负优化)
Components/Shared/Inc/UiComponent.hpp:纯接口、无状态,8 个方法
SetScale / Layout / Area / Paint / HitTest / OnMouseLeave / IsEditing / QueryCursor。
Toolbar / TabBar / SignalPanel / PlotView 本来就各自拥有完全同名同签名的成员,
因此改造 = 加 override + 补 Area()(PlotView 另加一个非 const 的 QueryCursor 转发,
因为它自己的查询会惰性建立行缓存),实现代码零改动、静态派发、体积无增长。
刻意不把 UiWidget 当作它的基类:UiWidget 是"树节点"(父给尺寸、父下探脏区、
命中沿树链派发),而 PlotView(4 层位图缓存)/ SignalPanel(行位图缓存)是
"地盘宿主"。强行上树会推翻"父脏则子全脏"的前提,历史上正是这类耦合导致过
"后台渲染覆盖平移结果""命中矩形错位"的事故。头文件里已写明这条理由。
Toolbar/TabBar 是两者的交集:对外实现 UiComponent,对内持有一棵 UiWidget 树。
## 2. 宿主侧:四条手写链 -> 组件表
Application 新增 ComponentEntry{ component, target, chrome } 与 m_components
(底->顶:plot -> panel -> toolbar -> tabBar),BuildComponentTable() 装配一次。
- ApplyDpi 6 行逐个 SetScale -> 1 个循环
- Relayout 手算三列 x 坐标 -> UiStackRects(内容区, HORIZONTAL, {panelW, splitW, AUTO})
- WM_MOUSELEAVE 逐个 OnMouseLeave -> 循环累积 chromeChanged / plotChanged
- WM_SETCURSOR if/else if 链 -> 从表尾向前找首个命中者,取其 QueryCursor
顺带兑现历史缺口:UiLayout::UiStackRects 自引入以来第一次有了生产调用点。
有意保留显式的三条链(WM_LBUTTONDOWN / WM_LBUTTONUP / WM_MOUSEMOVE):它们各自带
组件专属后置动作(提交重命名、构建派生信号、面板联动滚动、更新拖拽光标、
plotOnlyMove 决定局部失效还是整帧失效)。塞进表里只能靠 lambda 字段,
可读性反而下降 —— 属于用户明确禁止的"过度抽象",因此不做。
## 3. 大文件按职责拆分(纯整函数搬移,逐像素 0 差异)
SignalPanelInteraction.cpp 2329 -> 831 行,拆出:
SignalPanelEdit.cpp 616 内联编辑(筛选框、组名/信号名、数值、颜色与透明度)
SignalPanelScroll.cpp 205 动画与滚动(折起、联动滚动、滚动到目标信号)
SignalPanelMenu.cpp 527 弹出菜单(系数/偏移、镜像、右键菜单与命令回执)
Shared/PopupMenu.cpp 1901 -> 706 行,拆出:
PopupMenuLayout.cpp 753 尺寸测量、项矩形排版、滚动可见性
PopupMenuPaint.cpp 397 背景/阴影/项绘制
Inc/PopupMenuInternal.hpp 103 pmdetail 常量 + inline 辅助(跨 TU 安全)
拆分判据是"职责"而非行数;共享常量一律收敛到 *Internal.hpp。
## 4. 代码审查(修 5 处)
- SignalPanelInteraction.cpp 头注释仍写"4 片",实际 6 片 -> 改为完整清单
- PopupMenuLayout.cpp 机械搬移时把构造函数一起搬走 -> 重复定义,只保留在交互分片
- PopupMenu.cpp 的 #include "PopupMenuInternal.hpp" 落进 namespace jdi 内 -> 移到文件头
- PopupMenuPaint.cpp 缺 UiControls.hpp(UiDrawEditFieldContent 未声明)-> 补 include
- 全仓复查历史删除符号残留引用(m_paintPlot / ClampCursorsAfterPan /
PaintFreeMarkerTooltip / CaptureDecorCache / FitSinglePointSignal / CsvTable /
DataFile / .preflight / structcheck)-> 零命中
## 5. Tools/ 剥离
git rm -r --cached Tools + .gitignore 新增 Tools/(本地文件保留,可随时复跑)。
ui_refactor 分支为全本地分支,另做 filter-branch 清除历史中的该目录。
## 6. 验证
- make release / make debug:零 error 零 warning
- rendercheck:A-H 八个场景哈希与改造前逐一相同
(A 2166933039626F66 B C444ECFEB18FD73D C 7984446D8E7A4418 D BF855879CA12F289
E 1C663E4118616016 F 0535292D8E07AE18 G 7A58172C46577729 H 23F390DD76141113)
FUNC 7/7 PASS
- uicheck:69 passed, 0 failed
- TargetCheck.exe 891,392 B(< 900 KB 阈值)
## 7. 文档
Documents/UI_Refactor_Plan.md / UI_Refactor_Progress.md / UI_Refactor_Report.md
新增第五阶段章节;Documents/agent_mem.md 同步变更日志与「第七轮」硬约束。
This commit is contained in:
1 parent
675c2a5f54
commit
0ec8055e95
20 files changed
+3287
-2678
No files matched your search
@@ -137,6 +137,10 @@ namespace jdi
|
||||
m_plot.SetHostWindow(m_hwnd);
|
||||
m_menu.SetHostWindow(m_hwnd);
|
||||
|
||||
// 组件表在这里一次装配好:之后所有"设置缩放 / 摆放 / 悬停离开 / 光标 / 装饰区绘制"
|
||||
// 都由 `m_components` 驱动,宿主不再逐个点名组件。
|
||||
BuildComponentTable();
|
||||
|
||||
// 标题栏小图标与任务栏/Alt+Tab 缩略图大图标分开设置(同一个多尺寸 ICO 资源的不同尺寸)。
|
||||
HICON bigIcon = LoadAppIcon(GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON));
|
||||
HICON smallIcon = LoadAppIcon(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON));
|
||||
@@ -193,6 +197,18 @@ namespace jdi
|
||||
}
|
||||
}
|
||||
|
||||
void Application::BuildComponentTable()
|
||||
{
|
||||
// 底 → 顶:绘图区在最底,面板/工具栏/标签栏依次在上面。
|
||||
// 四个组件的区域互不重叠,因此命中顺序在这里不影响结果(保留顶优先只是为了与
|
||||
// 旧实现的方向一致,且将来若出现重叠会有确定的语义)。
|
||||
m_components.clear();
|
||||
m_components.push_back(ComponentEntry{ &m_plot, Target::PLOT, false });
|
||||
m_components.push_back(ComponentEntry{ &m_panel, Target::PANEL, true });
|
||||
m_components.push_back(ComponentEntry{ &m_toolbar, Target::TOOLBAR, true });
|
||||
m_components.push_back(ComponentEntry{ &m_tabBar, Target::TAB_BAR, true });
|
||||
}
|
||||
|
||||
void Application::ApplyDpi(UINT dpi)
|
||||
{
|
||||
if (dpi == 0)
|
||||
@@ -204,12 +220,12 @@ namespace jdi
|
||||
m_scale = static_cast<float>(dpi) / 96.0f;
|
||||
|
||||
m_fonts.Create(dpi);
|
||||
m_tabBar.SetScale(m_scale);
|
||||
m_toolbar.SetScale(m_scale);
|
||||
m_menu.SetScale(m_scale);
|
||||
m_colorPicker.SetScale(m_scale);
|
||||
m_panel.SetScale(m_scale);
|
||||
m_plot.SetScale(m_scale);
|
||||
for (const ComponentEntry& entry : m_components)
|
||||
{
|
||||
entry.component->SetScale(m_scale);
|
||||
}
|
||||
ReleaseBackBuffer();
|
||||
Relayout();
|
||||
}
|
||||
@@ -284,16 +300,38 @@ namespace jdi
|
||||
panelWidth = std::max(ScaleOf(kMinPanelWidth, m_scale), std::min(panelWidth, maximum));
|
||||
m_panelWidth = panelWidth / m_scale;
|
||||
|
||||
m_panelRect = gd::RectF(0.0f, contentTop, panelWidth, contentHeight);
|
||||
m_splitterRect = gd::RectF(panelWidth, contentTop, splitterWidth, contentHeight);
|
||||
m_plotRect = gd::RectF(panelWidth + splitterWidth, contentTop,
|
||||
std::max(0.0f, width - panelWidth - splitterWidth), contentHeight);
|
||||
// 内容区:左面板 + 分隔条 + 绘图区。用 `UiStackRects` 表达"固定 + 占满剩余"的切分,
|
||||
// 避免再次手算三组坐标(这也是 `UiLayout` 第一个真实生产调用点)。
|
||||
const std::vector<float> contentSizes{ panelWidth, splitterWidth, kUiSizeAuto };
|
||||
std::vector<gd::RectF> contentRects;
|
||||
UiStackRects(gd::RectF(0.0f, contentTop, width, contentHeight), UiAxis::HORIZONTAL,
|
||||
contentSizes, 0.0f, contentRects);
|
||||
m_panelRect = contentRects[0];
|
||||
m_splitterRect = contentRects[1];
|
||||
m_plotRect = contentRects[2];
|
||||
|
||||
m_tabBar.Layout(m_tabBarRect);
|
||||
m_toolbar.Layout(m_toolbarRect);
|
||||
m_panel.SetClientBounds(gd::RectF(0.0f, 0.0f, width, height));
|
||||
m_panel.Layout(m_panelRect);
|
||||
m_plot.Layout(m_plotRect);
|
||||
// 四个组件的区域一次摆完(顺序无关:各区域互不重叠)。
|
||||
m_panel.SetClientBounds(gd::RectF(0.0f, 0.0f, width, height));
|
||||
for (const ComponentEntry& entry : m_components)
|
||||
{
|
||||
switch (entry.target)
|
||||
{
|
||||
case Target::TAB_BAR:
|
||||
entry.component->Layout(m_tabBarRect);
|
||||
break;
|
||||
case Target::TOOLBAR:
|
||||
entry.component->Layout(m_toolbarRect);
|
||||
break;
|
||||
case Target::PANEL:
|
||||
entry.component->Layout(m_panelRect);
|
||||
break;
|
||||
case Target::PLOT:
|
||||
entry.component->Layout(m_plotRect);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 所有控件的目标矩形都变了,装饰区域必须整体重绘一次。
|
||||
m_chromeDirty = true;
|
||||
@@ -973,10 +1011,23 @@ namespace jdi
|
||||
// 只有标签栏 / 工具栏 / 面板的悬停态变化才需要重绘装饰区域;
|
||||
// 绘图区自身的悬停态变化(提示浮层、信号光晕)只需重绘绘图区,
|
||||
// 这样拖拽光标时鼠标短暂移出窗口也不会退化成整帧重绘。
|
||||
bool chromeChanged = m_tabBar.OnMouseLeave();
|
||||
chromeChanged = m_toolbar.OnMouseLeave() || chromeChanged;
|
||||
chromeChanged = m_panel.OnMouseLeave() || chromeChanged;
|
||||
const bool plotChanged = m_plot.OnMouseLeave();
|
||||
bool chromeChanged = false;
|
||||
bool plotChanged = false;
|
||||
for (const ComponentEntry& entry : m_components)
|
||||
{
|
||||
if (!entry.component->OnMouseLeave())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (entry.chrome)
|
||||
{
|
||||
chromeChanged = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
plotChanged = true;
|
||||
}
|
||||
}
|
||||
m_mouseOverPlot = false;
|
||||
|
||||
if (chromeChanged)
|
||||
@@ -1462,13 +1513,19 @@ namespace jdi
|
||||
{
|
||||
cursor = LoadCursorW(nullptr, IDC_SIZEWE);
|
||||
}
|
||||
else if (m_plot.HitTest(point.x, point.y))
|
||||
else
|
||||
{
|
||||
cursor = m_plot.QueryCursor(point.x, point.y);
|
||||
}
|
||||
else if (UiPointInRect(m_panelRect, static_cast<float>(point.x), static_cast<float>(point.y)))
|
||||
{
|
||||
cursor = m_panel.QueryCursor(point.x, point.y);
|
||||
// 光标仲裁:从组件表**顶部往下**找第一个命中的组件;它返回 nullptr 即视为
|
||||
// "该区域用箭头"(与旧实现里 `if (绘图区命中) 取它的光标,否则看面板` 一致)。
|
||||
for (auto iterator = m_components.rbegin(); iterator != m_components.rend(); ++iterator)
|
||||
{
|
||||
if (!iterator->component->HitTest(point.x, point.y))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
cursor = iterator->component->QueryCursor(point.x, point.y);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (cursor == nullptr)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user