refactor(plotview): 面板状态/滚动量收敛为唯一派发点,消除 20+ 处手写分支
问题:`Lane` 里 7 种实验性功能各自持有一份 `LanePanelState` 与滚动偏移(共 14 个字段)。 旧实现在每个需要“按种类取用”的地方各写一遍多层嵌套三元式或 switch: - EdgePanelLayoutFor 的 enabled / open / collapsed / storedX / storedY 共 5 条 7 层嵌套三元式(历史上多次因多/少一个右括号编译失败); - 标题栏拖拽、✕ 关闭、滚轮翻页、滚动条拖动、错开序数统计各自再写一遍。 新增一种面板要改 20+ 处,漏一处就是「面板拖不动 / 关不掉 / 滚轮滚不到底」 (MARK、RESAMPLE、CLIP 三种面板都真实踩过)。 改法(PlotViewInternal.hpp 新增唯一派发点): - LanePanelEnabled(lane, kind) - LanePanelStateOf(lane, kind) 可写/只读 - LanePanelScrollOf(lane, kind) 可写/只读 这些 switch **穷举全部 7 种且不写 default**,因此 -Wswitch(属 -Wall)会在新增 EdgePanelKind 而漏登记时直接报警 —— 已用最小程序验证 -Wswitch 确实会报。 调用点改造: - EdgePanelLayoutFor:5 条嵌套三元式 -> 3 行访问器调用;局部 kOrder[] -> kEdgePanelKinds。 - 标题栏拖拽:整个 7 分支 switch -> 一次访问器写入。 - 滚轮翻页:current 的三元式链 -> LanePanelScrollOf;switch 补全 MEAN/MARK 并去掉 default。 - 滚动条拖动:switch 补全 MEAN/MARK 并去掉 default。 - ✕ 关闭:去掉 `case COUNT: default:` 的兜底,改为穷举。 - SetLanePanelCollapsed / LanePanelCollapsed:两个 switch -> 一次访问器。 - 滚轮“是否可滚面板”的 kind 列举改为 `hoveredKind != MARK`。 验证:release / debug 全量编译零 warning;产物大小不变(793,088 B,逻辑等价)。
This commit is contained in:
1 parent
94fc1c45da
commit
7a3fefb9c2
5 files changed
+173
-181
No files matched your search
@@ -1081,6 +1081,103 @@ namespace jdi
|
||||
/** 实验性功能浮动面板的种类数(遍历与命中测试统一用它,避免新增功能时漏改)。 */
|
||||
inline const int kEdgePanelKindCount = static_cast<int>(sizeof(kEdgePanelKinds) / sizeof(kEdgePanelKinds[0]));
|
||||
|
||||
// ---- 面板状态 / 滚动量的**唯一派发点** --------------------------------------
|
||||
//
|
||||
// ⚠️⚠️ 为什么必须有这一组函数:`Lane` 里每种实验性功能各有一份
|
||||
// `LanePanelState` 与滚动偏移(7 种 × 2 = 14 个字段)。旧实现在**每个**需要
|
||||
// 按种类取用这些字段的地方各写一遍多层三元式或 `switch`:
|
||||
// * `EdgePanelLayoutFor` 的 `enabled / open / collapsed` 各一条 7 层嵌套三元式
|
||||
// (历史多次因为“多/少一个右括号”编译失败);
|
||||
// * 标题栏拖拽、✕ 关闭、滚轮滚动、折叠切换、缓存键……各自再写一遍。
|
||||
// 新增一种面板要改 20+ 处,漏一处就是“面板拖不动 / 关不掉 / 滚轮滚不到底”
|
||||
//(`MARK`、`RESAMPLE`、`CLIP` 都真实踩过)。
|
||||
//
|
||||
// 现在这些字段只在这一组函数里按种类分派;**调用方一律用它**。
|
||||
// ⚠️ 这些 `switch` **不得写 `default:`** —— 让 `-Wswitch` 在新增
|
||||
// `EdgePanelKind` 而漏登记时直接报警(编译期保护,0 运行时代价)。
|
||||
|
||||
/** @brief 取某种面板的 UI 状态(展开/折起/位置)——可写版本。 */
|
||||
inline LanePanelState& LanePanelStateOf(Lane& lane, EdgePanelKind kind)
|
||||
{
|
||||
switch (kind)
|
||||
{
|
||||
case EdgePanelKind::COUNT:
|
||||
return lane.edgePanel;
|
||||
case EdgePanelKind::CENTER:
|
||||
return lane.edgeCenterPanel;
|
||||
case EdgePanelKind::MEAN:
|
||||
return lane.meanFilterPanel;
|
||||
case EdgePanelKind::PEAK:
|
||||
return lane.weakPeakPanel;
|
||||
case EdgePanelKind::MARK:
|
||||
return lane.freeMarkerPanel;
|
||||
case EdgePanelKind::RESAMPLE:
|
||||
return lane.resamplePanel;
|
||||
case EdgePanelKind::CLIP:
|
||||
return lane.clipPanel;
|
||||
}
|
||||
// 枚举值越界(只可能来自非法强制转换):返回一个安全的占位对象。
|
||||
return lane.edgePanel;
|
||||
}
|
||||
|
||||
/** @brief 取某种面板的 UI 状态——只读版本。 */
|
||||
inline const LanePanelState& LanePanelStateOf(const Lane& lane, EdgePanelKind kind)
|
||||
{
|
||||
return LanePanelStateOf(const_cast<Lane&>(lane), kind);
|
||||
}
|
||||
|
||||
/** @brief 取某种面板的**内容滚动偏移**(客户区像素)——可写版本。 */
|
||||
inline float& LanePanelScrollOf(Lane& lane, EdgePanelKind kind)
|
||||
{
|
||||
switch (kind)
|
||||
{
|
||||
case EdgePanelKind::COUNT:
|
||||
return lane.edgeCountScroll;
|
||||
case EdgePanelKind::CENTER:
|
||||
return lane.edgeCenterScroll;
|
||||
case EdgePanelKind::MEAN:
|
||||
return lane.meanFilterScroll;
|
||||
case EdgePanelKind::PEAK:
|
||||
return lane.weakPeakScroll;
|
||||
case EdgePanelKind::MARK:
|
||||
return lane.freeMarkerScroll;
|
||||
case EdgePanelKind::RESAMPLE:
|
||||
return lane.resampleScroll;
|
||||
case EdgePanelKind::CLIP:
|
||||
return lane.clipScroll;
|
||||
}
|
||||
return lane.meanFilterScroll;
|
||||
}
|
||||
|
||||
/** @brief 取某种面板的**内容滚动偏移**——只读版本。 */
|
||||
inline const float& LanePanelScrollOf(const Lane& lane, EdgePanelKind kind)
|
||||
{
|
||||
return LanePanelScrollOf(const_cast<Lane&>(lane), kind);
|
||||
}
|
||||
|
||||
/** @brief 该面板对应的功能是否已启用(右键菜单里的开关)。 */
|
||||
inline bool LanePanelEnabled(const Lane& lane, EdgePanelKind kind)
|
||||
{
|
||||
switch (kind)
|
||||
{
|
||||
case EdgePanelKind::COUNT:
|
||||
return lane.edgeCount;
|
||||
case EdgePanelKind::CENTER:
|
||||
return lane.edgeCenter;
|
||||
case EdgePanelKind::MEAN:
|
||||
return lane.meanFilter;
|
||||
case EdgePanelKind::PEAK:
|
||||
return lane.weakPeak;
|
||||
case EdgePanelKind::MARK:
|
||||
return lane.freeMarker;
|
||||
case EdgePanelKind::RESAMPLE:
|
||||
return lane.resample;
|
||||
case EdgePanelKind::CLIP:
|
||||
return lane.clip;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 计算一条派生曲线在给定采样窗口内的取值(同步路径与后台线程共用)。
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user