feat(ui): 工具栏"选区"改名、菜单对勾右置与边距修正、选区自适应勾选、悬停/选区拖拽性能

1) 工具栏文案:"时间轴缩放"/"Y 轴缩放" -> "时间轴选区"/"Y 轴选区"
- Toolbar.cpp 按钮标签、Toolbar.hpp 枚举注释、Application 状态提示语同步更新

2) 网格右键菜单:对勾从左侧移到右侧,并修正菜单内各元素边距
- 文本列统一为 kPadH + kItemPad(5 + 8),三类条目(HEADER/NORMAL/EDIT)共用;
  原先左侧预留 22px 标记列,导致"网格 N"、"Y 轴最大值"、"选区 Y 轴自适应"等
  所有文本的左边距被整体推右(用户报告的"文本左边距过大")
- 对勾改画在条目右侧的 kMarkerColumn(18) 列内,文本宽度相应预留,不会与文字重叠
- EDIT 行输入框改为右对齐到条目内容区右边界,宽度由 NaturalEditFieldWidth() 统一计算,
  空间不足时为左侧说明文字保留自然宽度(避免被菜单宽度上限挤成省略号)
- 分隔线、色块行同样改用 kItemPad 内缩;kRightPad 已删除

3) "选区 Y 轴自适应"增加与"Y 轴自适应"一致的勾选标记
- Lane 新增 viewAutoRange / viewAutoMin / viewAutoMax,记录应用该操作时的视图时间区间
- 新增 PlotView::LaneRangeIsAutoToView():只有未被任何手动幅值改动且时间选区未变化时才为 true
- 所有手动改动路径(ApplyValueSelection/ScaleLaneRange/ShiftLaneRange/ApplyLaneValueText/
  EndEdit/ResetLaneRange/MoveSignalToLane)都会清除该状态;
  时间选区变化后 viewAutoMin/Max 与当前视图不符,勾选自动消失
- RefreshPlotMenuValues() 同步刷新该项状态

4) 修复大文件(VERY_BIG_DATA 1.77GB / 5 信号)下悬停与选区缩放的严重卡顿
- 根因:任何悬停态变化(左侧信号列表、网格内命中曲线提示)或选区拖拽都会触发整幅重绘,
  其中波形绘制约 80ms/帧,因此交互帧率只有 ~10fps
- 静态场景缓存从"仅拖拽信号/光标"推广为"只要场景键一致就复用",缓存区域由整个客户区
  收敛为仅绘图区:工具栏/标签栏/面板各自带悬停态必须每帧绘制(约 10.5ms),
  而真正昂贵的波形改为直接贴图(约 1ms)
- 场景键新增 contentHash(FNV-1a 折叠网格几何/幅值、每条信号的引用/可见性/
  颜色/透明度/线宽/样式/显示名与所属文件名):改样式、重命名、增删信号都会自动失效
- 随鼠标变化的内容全部移出缓存:新增 PaintHoverHighlight() 在贴图之后绘制
  悬停网格底色(半透明叠加)与悬停信号光晕(PaintSignalHalo());
  PaintLane 内只绘制拖拽中的信号光晕(key 中记录 haloFile/haloSignal)
- EnsureSceneCache 改为要求位图尺寸与当前区域严格相等(原 >= 复用会在窗口缩小后
  把旧像素画到绘图区之外)
- Application::Render 移除 reuseScene 分支,统一每帧绘制界面框架

实测(VERY_BIG_DATA 5 信号,Release):
- 整幅重绘 ~80ms -> 命中缓存贴图 ~1ms
- 悬停左侧信号列表:~95ms -> ~14ms/帧
- 悬停网格内信号(含光晕高亮):~95ms -> ~28~32ms/帧
- 时间轴 / Y 轴选区拖拽:~95~105ms -> ~19~22ms/帧
- 非拖拽静止帧 ~118ms 维持不变;空闲 CPU 0.00%

构建: make clean; make all 无警告无错误
This commit is contained in:
DeepSeek V4.1 Flash committed 2026-10-07 11:26:43 +08:00
1 parent a3e638fa58
commit dd48cdd2e1
9 files changed
+414 -194

No files matched your search

+3
View File
@@ -330,6 +330,9 @@ namespace jdi
bool autoRange = true; /**< 是否依据信号取值范围自动计算 Y 轴。 */
double yMin = -1.0; /**< 手动 Y 轴下限。 */
double yMax = 1.0; /**< 手动 Y 轴上限。 */
bool viewAutoRange = false; /**< 是否由「选区 Y 轴自适应」产生且时间选区未再变化。 */
double viewAutoMin = 0.0; /**< 应用「选区 Y 轴自适应」时的视图时间下限。 */
double viewAutoMax = 0.0; /**< 应用「选区 Y 轴自适应」时的视图时间上限。 */
};
/**
+7
View File
@@ -287,6 +287,13 @@ namespace jdi
*/
gd::RectF EditFieldRect(int index) const;
/**
* @brief 计算 EDIT 项输入框的“自然宽度”(排版与绘制共用同一公式)。
* @param [IN] item 菜单项。
* @return 宽度(像素)。
*/
float NaturalEditFieldWidth(const MenuItem& item) const;
/**
* @brief 进入指定项的内联编辑状态。
* @param [IN] index 项目下标。
+2
View File
@@ -1048,6 +1048,8 @@ namespace jdi
for (Lane& lane : m_lanes)
{
// 网格的信号组成发生变化,“选区 Y 轴自适应”的结果不再对应当前视野。
lane.viewAutoRange = false;
std::vector<SignalRef>& refs = lane.signals;
refs.erase(std::remove(refs.begin(), refs.end(), ref), refs.end());
}
+49 -35
View File
@@ -13,9 +13,10 @@ namespace jdi
const float kSeparatorHeight = 9.0f; /**< 分隔线高度。 */
const float kSwatchRowHeight = 32.0f; /**< 色块行高度。 */
const float kPadV = 5.0f; /**< 菜单上下内边距。 */
const float kPadH = 6.0f; /**< 菜单左右内边距。 */
const float kMarkerColumn = 22.0f; /**< 选中标记列宽度。 */
const float kRightPad = 14.0f; /**< 文本右侧留白。 */
const float kPadH = 5.0f; /**< 菜单左右内边距。 */
const float kItemPad = 8.0f; /**< 条目内文本的左右内缩(所有条目统一)。 */
const float kMarkerColumn = 18.0f; /**< 条目**右侧**的选中标记列宽度(对勾画在这里)。 */
const float kMarkerGap = 4.0f; /**< 文本与右侧标记列之间的间隔。 */
const float kMinWidth = 148.0f; /**< 菜单最小宽度。 */
const float kMaxWidth = 340.0f; /**< 菜单最大宽度。 */
const float kCorner = 6.0f; /**< 菜单圆角半径。 */
@@ -80,31 +81,32 @@ namespace jdi
if (item.kind == MenuItemKind::SWATCHES)
{
const int count = std::max(0, std::min(item.swatchCount, 16));
const float width = kPadH * 2.0f * m_scale + static_cast<float>(count) * kSwatchSize * m_scale +
const float width = (kPadH + kItemPad) * 2.0f * m_scale +
static_cast<float>(count) * kSwatchSize * m_scale +
static_cast<float>(std::max(0, count - 1)) * kSwatchGap * m_scale;
contentWidth = std::max(contentWidth, width);
}
else if (item.kind == MenuItemKind::HEADER)
{
const float width = (kPadH + kMarkerColumn) * m_scale +
UiMeasureTextWidth(m_fonts->uiSmallBold, item.label) + kRightPad * m_scale;
// 标题与普通项共用同一文字列与右侧标记列,保证整个菜单的左右边距一致。
const float width = (kPadH + kItemPad) * 2.0f * m_scale + kMarkerColumn * m_scale +
kMarkerGap * m_scale +
UiMeasureTextWidth(m_fonts->uiSmallBold, item.label);
contentWidth = std::max(contentWidth, width);
}
else if (item.kind == MenuItemKind::NORMAL)
{
const float width = (kPadH + kMarkerColumn) * m_scale +
UiMeasureTextWidth(m_fonts->uiSmall, item.label) + kRightPad * m_scale;
const float width = (kPadH + kItemPad) * 2.0f * m_scale + kMarkerColumn * m_scale +
kMarkerGap * m_scale + UiMeasureTextWidth(m_fonts->uiSmall, item.label);
contentWidth = std::max(contentWidth, width);
}
else if (item.kind == MenuItemKind::EDIT)
{
// 说明文字 + 输入框 + 右侧留白;输入框宽度按数值文本自适应(取一个上限)。
const float fieldWidth =
std::max(kEditFieldWidth * m_scale,
UiMeasureTextWidth(m_fonts->uiSmall, item.value) + 20.0f * m_scale);
const float width = (kPadH + kMarkerColumn) * m_scale +
// 说明文字 + 输入框;输入框宽度按数值文本自适应(与 EditFieldRect 保持一致)。
const float fieldWidth = NaturalEditFieldWidth(item);
const float width = (kPadH + kItemPad) * 2.0f * m_scale +
UiMeasureTextWidth(m_fonts->uiSmall, item.label) + kEditFieldGap * m_scale +
fieldWidth + kRightPad * m_scale;
fieldWidth;
contentWidth = std::max(contentWidth, width);
}
}
@@ -144,7 +146,7 @@ namespace jdi
std::vector<gd::RectF>& rects = m_swatchRects[index];
rects.reserve(static_cast<std::size_t>(count));
const float swatchY = cursorY + (itemHeight - kSwatchSize * m_scale) * 0.5f;
const float startX = left + (kPadH + 4.0f) * m_scale;
const float startX = left + (kPadH + kItemPad) * m_scale;
for (int swatch = 0; swatch < count; ++swatch)
{
const float swatchX =
@@ -157,27 +159,35 @@ namespace jdi
}
}
float PopupMenu::NaturalEditFieldWidth(const MenuItem& item) const
{
return std::max(kEditFieldWidth * m_scale,
UiMeasureTextWidth(m_fonts->uiSmall, item.value) + 20.0f * m_scale);
}
gd::RectF PopupMenu::EditFieldRect(int index) const
{
if (index < 0 || index >= static_cast<int>(m_items.size()))
{
return gd::RectF();
}
if (m_items[static_cast<std::size_t>(index)].kind != MenuItemKind::EDIT)
const MenuItem& item = m_items[static_cast<std::size_t>(index)];
if (item.kind != MenuItemKind::EDIT)
{
return gd::RectF();
}
// 输入框靠右对齐:宽度取固定下限与当前文本宽度中的较大者,但不得超过菜单可用宽度的一半。
// 输入框靠右对齐到条目内容区右边界;宽度取自然宽度,但必须给说明文字留出自然宽度,
// 避免菜单被最大宽度夹取后输入框把左侧标签挤成省略号。
const gd::RectF& rect = m_itemRects[static_cast<std::size_t>(index)];
const float maxWidth = std::max(40.0f * m_scale, rect.Width * 0.5f);
float width = std::max(kEditFieldWidth * m_scale,
UiMeasureTextWidth(m_fonts->uiSmall, m_items[static_cast<std::size_t>(index)].value) +
20.0f * m_scale);
width = std::min(width, maxWidth);
const float contentWidth = std::max(40.0f * m_scale, rect.Width - 2.0f * kItemPad * m_scale);
const float labelWidth = UiMeasureTextWidth(m_fonts->uiSmall, item.label) + kEditFieldGap * m_scale;
float width = NaturalEditFieldWidth(item);
width = std::min(width, std::max(40.0f * m_scale, contentWidth - labelWidth));
width = std::min(width, contentWidth * 0.75f);
const float height = rect.Height - kEditFieldPadV * 2.0f * m_scale;
return gd::RectF(rect.X + rect.Width - width - 4.0f * m_scale,
return gd::RectF(rect.X + rect.Width - kItemPad * m_scale - width,
rect.Y + (rect.Height - height) * 0.5f, width, height);
}
@@ -745,15 +755,16 @@ namespace jdi
if (item.kind == MenuItemKind::SEPARATOR)
{
const float lineY = rect.Y + rect.Height * 0.5f;
UiDrawLine(g, rect.X + 4.0f * m_scale, lineY, rect.X + rect.Width - 4.0f * m_scale, lineY,
m_theme->border, 1.0f);
UiDrawLine(g, rect.X + kItemPad * m_scale, lineY,
rect.X + rect.Width - kItemPad * m_scale, lineY, m_theme->border, 1.0f);
continue;
}
if (item.kind == MenuItemKind::HEADER)
{
// 标题与普通项共用同一文字列,保证菜单内所有文本严格左对齐。
UiText(g, item.label, m_fonts->uiSmallBold,
gd::RectF(rect.X + kMarkerColumn * m_scale, rect.Y, rect.Width, rect.Height),
gd::RectF(rect.X + kItemPad * m_scale, rect.Y, rect.Width, rect.Height),
m_theme->textMuted, TextAlign::LEFT);
continue;
}
@@ -771,8 +782,8 @@ namespace jdi
}
const std::uint32_t labelColor = item.enabled ? m_theme->text : m_theme->textMuted;
// 说明文字与普通项使用同一文字列(kMarkerColumn),保证菜单内所有文本左对齐。
const float labelLeft = rect.X + kMarkerColumn * m_scale;
// 说明文字与普通项使用同一文字列(kItemPad),保证菜单内所有文本左对齐。
const float labelLeft = rect.X + kItemPad * m_scale;
const gd::RectF fieldRect = EditFieldRect(static_cast<int>(index));
const float labelWidth = std::max(8.0f, fieldRect.X - labelLeft - kEditFieldGap * m_scale);
UiText(g, UiEllipsize(g, item.label, m_fonts->uiSmall, labelWidth), m_fonts->uiSmall,
@@ -841,18 +852,21 @@ namespace jdi
if (item.checked)
{
// 单选标记:对勾。
const float cx = rect.X + kMarkerColumn * m_scale * 0.5f + 2.0f * m_scale;
// 单选标记:对勾固定画在条目**右侧**的标记列内,左侧只留统一的小边距,
// 这样菜单文本左边距不会因为“可能存在的对勾”而被整体推右。
const float markerRight = rect.X + rect.Width - kItemPad * m_scale;
const float cx = markerRight - kMarkerColumn * m_scale * 0.5f;
const float cy = rect.Y + rect.Height * 0.5f;
const std::uint32_t markerColor = hovered ? m_theme->textOnAccent : m_theme->accent;
UiDrawLine(g, cx - 4.0f * m_scale, cy, cx - 1.0f * m_scale, cy + 3.0f * m_scale,
hovered ? m_theme->textOnAccent : m_theme->accent, 1.8f * m_scale);
markerColor, 1.8f * m_scale);
UiDrawLine(g, cx - 1.0f * m_scale, cy + 3.0f * m_scale, cx + 4.5f * m_scale,
cy - 4.0f * m_scale, hovered ? m_theme->textOnAccent : m_theme->accent,
1.8f * m_scale);
cy - 4.0f * m_scale, markerColor, 1.8f * m_scale);
}
const float textLeft = rect.X + kMarkerColumn * m_scale;
const float textWidth = rect.Width - kMarkerColumn * m_scale - 4.0f * m_scale;
const float textLeft = rect.X + kItemPad * m_scale;
const float textWidth =
rect.Width - 2.0f * kItemPad * m_scale - kMarkerColumn * m_scale - kMarkerGap * m_scale;
UiText(g, UiEllipsize(g, item.label, m_fonts->uiSmall, textWidth), m_fonts->uiSmall,
gd::RectF(textLeft, rect.Y, std::max(8.0f, textWidth), rect.Height), textColor,
TextAlign::LEFT);