feat: 支持多视图标签页、按文件分组的多文件信号管理与网格随勾选自动收敛
数据层与视图配置解耦:新增 DataSet(多文件只读数据层)与 TabConfig(每标签页独立配置),
以 SignalRef{fileIndex,signalIndex} 标识全局信号,替换原有单文件 SignalSet。
- 标签页:新增 TabBar 组件,支持新建/切换/关闭标签页;每页独立保存信号勾选、
颜色/线宽/显示方式、网格划分、视图范围与时间光标,互不影响。
- 网格收敛:可见性变更统一经 TabConfig 的 Set*Visible 接口并同步重算网格,
取消勾选后对应的空网格立即回收(修复此前留下空轨道的问题)。
- 多文件分组:左侧面板改为「文件分组 + 信号」树形列表,分组可折叠、可整组勾选,
分组复选框支持全选/部分/未选三态;新加载文件的信号默认未勾选,由用户自行选择。
- 来源标识:信号行、样式编辑区标题、波形图例与光标读数在跨文件时标注来源文件名。
- 交互补充:面板滚动条支持点击跳转与拖拽,切换标签页自动滚动到已选信号。
- 工具栏精简为「打开 CSV/适应视图/放大/缩小/合并网格/每信号一格/全选信号/清空勾选」,
按钮宽度改为按实际文本像素测量;打开对话框支持多选文件,拖放支持批量载入。
- 新增 TestData/[2].CSV 作为跨文件对比测试数据。
This commit is contained in:
1 parent
132b305544
commit
9c6c374cce
21 files changed
+4086
-1461
No files matched your search
@@ -0,0 +1,179 @@
|
||||
#ifndef __TAB_BAR_HPP__
|
||||
#define __TAB_BAR_HPP__
|
||||
|
||||
#include <windows.h>
|
||||
#include <objidl.h>
|
||||
#include <gdiplus.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "PaintUtil.hpp"
|
||||
#include "Theme.hpp"
|
||||
|
||||
namespace jdi
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief 标签栏交互结果。
|
||||
*/
|
||||
struct TabBarResult
|
||||
{
|
||||
/**
|
||||
* @brief 交互动作类型。
|
||||
*/
|
||||
enum class Type : int
|
||||
{
|
||||
NONE = 0, /**< 未触发任何动作。 */
|
||||
SELECT, /**< 切换到指定标签页。 */
|
||||
CLOSE, /**< 关闭指定标签页。 */
|
||||
ADD, /**< 新建标签页。 */
|
||||
CONTEXT /**< 请求弹出标签页上下文菜单。 */
|
||||
};
|
||||
|
||||
Type type = Type::NONE; /**< 动作类型。 */
|
||||
int index = -1; /**< 标签页下标(ADD 时无意义)。 */
|
||||
int screenX = 0; /**< 上下文菜单请求的屏幕横坐标。 */
|
||||
int screenY = 0; /**< 上下文菜单请求的屏幕纵坐标。 */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 顶部标签栏:支持多视图切换、新建与关闭。
|
||||
*/
|
||||
class TabBar
|
||||
{
|
||||
public:
|
||||
TabBar();
|
||||
|
||||
/**
|
||||
* @brief 绑定字体与主题资源。
|
||||
* @param [IN] fonts 字体集合,需在标签栏生命周期内保持有效。
|
||||
* @param [IN] theme 主题配色,需在标签栏生命周期内保持有效。
|
||||
*/
|
||||
void Setup(const UiFonts* fonts, const Theme* theme);
|
||||
|
||||
/**
|
||||
* @brief 设置 DPI 缩放比例。
|
||||
* @param [IN] scale 缩放比例(1.0 对应 96 DPI)。
|
||||
*/
|
||||
void SetScale(float scale);
|
||||
|
||||
/**
|
||||
* @brief 更新标签页名称集合。
|
||||
* @param [IN] names 标签页名称列表。
|
||||
*/
|
||||
void SetTabs(const std::vector<std::wstring>& names);
|
||||
|
||||
/**
|
||||
* @brief 设置当前激活的标签页下标。
|
||||
* @param [IN] index 标签页下标,-1 表示无激活页。
|
||||
*/
|
||||
void SetActiveIndex(int index);
|
||||
|
||||
/**
|
||||
* @brief 计算标签栏期望高度。
|
||||
* @return 期望高度(像素)。
|
||||
*/
|
||||
float DesiredHeight() const;
|
||||
|
||||
/**
|
||||
* @brief 按给定区域重新排布标签与按钮。
|
||||
* @param [IN] area 标签栏可用区域。
|
||||
*/
|
||||
void Layout(const gd::RectF& area);
|
||||
|
||||
/**
|
||||
* @brief 绘制标签栏。
|
||||
* @param [IN,OUT] g 绘图上下文。
|
||||
*/
|
||||
void Paint(gd::Graphics& g);
|
||||
|
||||
/**
|
||||
* @brief 处理鼠标移动。
|
||||
* @param [IN] x 客户区横坐标。
|
||||
* @param [IN] y 客户区纵坐标。
|
||||
* @return 悬停状态发生变化返回 true。
|
||||
*/
|
||||
bool OnMouseMove(int x, int y);
|
||||
|
||||
/**
|
||||
* @brief 处理鼠标左键按下。
|
||||
* @param [IN] x 客户区横坐标。
|
||||
* @param [IN] y 客户区纵坐标。
|
||||
* @return 命中可点击元素返回 true。
|
||||
*/
|
||||
bool OnLButtonDown(int x, int y);
|
||||
|
||||
/**
|
||||
* @brief 处理鼠标左键抬起并给出交互结果。
|
||||
* @param [IN] x 客户区横坐标。
|
||||
* @param [IN] y 客户区纵坐标。
|
||||
* @param [OUT] result 交互结果。
|
||||
* @return 视觉状态发生变化返回 true。
|
||||
*/
|
||||
bool OnLButtonUp(int x, int y, TabBarResult& result);
|
||||
|
||||
/**
|
||||
* @brief 处理鼠标右键按下(请求标签页上下文菜单)。
|
||||
* @param [IN] x 客户区横坐标。
|
||||
* @param [IN] y 客户区纵坐标。
|
||||
* @param [IN] screenX 屏幕横坐标。
|
||||
* @param [IN] screenY 屏幕纵坐标。
|
||||
* @param [OUT] result 交互结果。
|
||||
* @return 命中标签页返回 true。
|
||||
*/
|
||||
bool OnRButtonDown(int x, int y, int screenX, int screenY, TabBarResult& result);
|
||||
|
||||
/**
|
||||
* @brief 处理鼠标离开标签栏。
|
||||
* @return 视觉状态发生变化返回 true。
|
||||
*/
|
||||
bool OnMouseLeave();
|
||||
|
||||
/**
|
||||
* @brief 判断坐标是否落在标签栏区域内。
|
||||
* @param [IN] x 客户区横坐标。
|
||||
* @param [IN] y 客户区纵坐标。
|
||||
* @return 落在区域内返回 true。
|
||||
*/
|
||||
bool HitTest(int x, int y) const;
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief 单个标签页的布局信息。
|
||||
*/
|
||||
struct TabItem
|
||||
{
|
||||
std::wstring name; /**< 标签页名称。 */
|
||||
gd::RectF rect; /**< 标签整体矩形。 */
|
||||
gd::RectF closeRect; /**< 关闭按钮矩形。 */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 判断坐标命中的标签页下标。
|
||||
* @param [IN] x 客户区横坐标。
|
||||
* @param [IN] y 客户区纵坐标。
|
||||
* @return 标签页下标,未命中返回 -1。
|
||||
*/
|
||||
int TabAtPoint(int x, int y) const;
|
||||
|
||||
const UiFonts* m_fonts = nullptr; /**< 字体资源。 */
|
||||
const Theme* m_theme = nullptr; /**< 主题资源。 */
|
||||
float m_scale = 1.0f; /**< DPI 缩放比例。 */
|
||||
|
||||
std::vector<TabItem> m_tabs; /**< 标签页布局集合。 */
|
||||
gd::RectF m_addRect; /**< 新建按钮矩形。 */
|
||||
gd::RectF m_area; /**< 标签栏整体区域。 */
|
||||
|
||||
int m_activeIndex = -1; /**< 当前激活标签页下标。 */
|
||||
int m_hoverIndex = -1; /**< 当前悬停标签页下标。 */
|
||||
bool m_hoverClose = false; /**< 是否悬停在关闭按钮上。 */
|
||||
bool m_hoverAdd = false; /**< 是否悬停在新建按钮上。 */
|
||||
int m_pressedIndex = -1; /**< 当前按下的标签页下标。 */
|
||||
bool m_pressedClose = false; /**< 是否按在关闭按钮上。 */
|
||||
bool m_pressedAdd = false; /**< 是否按在新建按钮上。 */
|
||||
};
|
||||
|
||||
} // namespace jdi
|
||||
|
||||
#endif // __TAB_BAR_HPP__
|
||||
@@ -0,0 +1,307 @@
|
||||
#include "TabBar.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
namespace jdi
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
const float kTabHeight = 32.0f; /**< 标签高度(逻辑像素)。 */
|
||||
const float kTopMargin = 4.0f; /**< 标签顶部留白。 */
|
||||
const float kLeftPadding = 8.0f; /**< 左侧留白。 */
|
||||
const float kTabPadding = 14.0f; /**< 标签文本左右内边距。 */
|
||||
const float kCloseSize = 16.0f; /**< 关闭按钮尺寸。 */
|
||||
const float kCloseGap = 6.0f; /**< 文本与关闭按钮间距。 */
|
||||
const float kAddSize = 24.0f; /**< 新建按钮尺寸。 */
|
||||
const float kAddGap = 6.0f; /**< 新建按钮与末个标签的间距。 */
|
||||
const float kCorner = 5.0f; /**< 标签圆角半径。 */
|
||||
const float kMaxTabWidth = 200.0f; /**< 单个标签最大宽度(逻辑像素)。 */
|
||||
}
|
||||
|
||||
TabBar::TabBar() = default;
|
||||
|
||||
void TabBar::Setup(const UiFonts* fonts, const Theme* theme)
|
||||
{
|
||||
m_fonts = fonts;
|
||||
m_theme = theme;
|
||||
}
|
||||
|
||||
void TabBar::SetScale(float scale)
|
||||
{
|
||||
m_scale = (scale > 0.1f) ? scale : 1.0f;
|
||||
}
|
||||
|
||||
void TabBar::SetTabs(const std::vector<std::wstring>& names)
|
||||
{
|
||||
m_tabs.clear();
|
||||
m_tabs.resize(names.size());
|
||||
for (std::size_t index = 0; index < names.size(); ++index)
|
||||
{
|
||||
m_tabs[index].name = names[index];
|
||||
}
|
||||
if (m_activeIndex >= static_cast<int>(m_tabs.size()))
|
||||
{
|
||||
m_activeIndex = m_tabs.empty() ? -1 : static_cast<int>(m_tabs.size()) - 1;
|
||||
}
|
||||
m_hoverIndex = -1;
|
||||
m_hoverClose = false;
|
||||
}
|
||||
|
||||
void TabBar::SetActiveIndex(int index)
|
||||
{
|
||||
m_activeIndex = index;
|
||||
}
|
||||
|
||||
float TabBar::DesiredHeight() const
|
||||
{
|
||||
return (kTabHeight + kTopMargin) * m_scale;
|
||||
}
|
||||
|
||||
void TabBar::Layout(const gd::RectF& area)
|
||||
{
|
||||
m_area = area;
|
||||
if (m_fonts == nullptr || m_fonts->ui == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const float tabHeight = kTabHeight * m_scale;
|
||||
const float top = area.Y + kTopMargin * m_scale;
|
||||
const float closeSize = kCloseSize * m_scale;
|
||||
const float maxWidth = kMaxTabWidth * m_scale;
|
||||
const float minWidth = 70.0f * m_scale;
|
||||
|
||||
float cursorX = area.X + kLeftPadding * m_scale;
|
||||
|
||||
for (TabItem& tab : m_tabs)
|
||||
{
|
||||
const float textWidth = UiMeasureTextWidth(m_fonts->ui, tab.name);
|
||||
float width = kTabPadding * 2.0f * m_scale + textWidth + kCloseGap * m_scale + closeSize;
|
||||
width = std::max(minWidth, std::min(width, maxWidth));
|
||||
|
||||
tab.rect = gd::RectF(cursorX, top, width, tabHeight);
|
||||
tab.closeRect = gd::RectF(cursorX + width - kTabPadding * m_scale - closeSize,
|
||||
top + (tabHeight - closeSize) * 0.5f, closeSize, closeSize);
|
||||
|
||||
cursorX += width + kAddGap * m_scale;
|
||||
}
|
||||
|
||||
const float addSize = kAddSize * m_scale;
|
||||
m_addRect = gd::RectF(cursorX, top + (tabHeight - addSize) * 0.5f, addSize, addSize);
|
||||
}
|
||||
|
||||
void TabBar::Paint(gd::Graphics& g)
|
||||
{
|
||||
if (m_theme == nullptr || m_fonts == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
UiFillRect(g, m_area, m_theme->panelBg);
|
||||
|
||||
const float closeIconSize = 8.0f * m_scale;
|
||||
|
||||
for (std::size_t index = 0; index < m_tabs.size(); ++index)
|
||||
{
|
||||
const TabItem& tab = m_tabs[index];
|
||||
const bool active = (static_cast<int>(index) == m_activeIndex);
|
||||
const bool hovered = (static_cast<int>(index) == m_hoverIndex);
|
||||
|
||||
std::uint32_t background = m_theme->panelBg;
|
||||
if (active)
|
||||
{
|
||||
background = m_theme->cardBg;
|
||||
}
|
||||
else if (hovered)
|
||||
{
|
||||
background = m_theme->hover;
|
||||
}
|
||||
UiFillRoundRect(g, tab.rect, kCorner * m_scale, background);
|
||||
|
||||
if (!active)
|
||||
{
|
||||
UiDrawRoundRect(g, tab.rect, kCorner * m_scale, m_theme->border, 1.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 激活页使用顶部强调条指示。
|
||||
UiFillRoundRect(g, gd::RectF(tab.rect.X + kCorner * m_scale, tab.rect.Y,
|
||||
tab.rect.Width - kCorner * 2.0f * m_scale, 2.5f * m_scale),
|
||||
1.0f * m_scale, m_theme->accent);
|
||||
}
|
||||
|
||||
const float textLeft = tab.rect.X + kTabPadding * m_scale;
|
||||
const float textWidth = tab.closeRect.X - kCloseGap * m_scale - textLeft;
|
||||
const std::wstring label = UiEllipsize(g, tab.name, m_fonts->ui, std::max(8.0f, textWidth));
|
||||
UiText(g, label, active ? m_fonts->uiBold : m_fonts->ui,
|
||||
gd::RectF(textLeft, tab.rect.Y, std::max(8.0f, textWidth), tab.rect.Height),
|
||||
active ? m_theme->textStrong : m_theme->text, TextAlign::LEFT);
|
||||
|
||||
// 关闭按钮:悬停时显示底色,图标始终可见。
|
||||
const bool closeHot = hovered && m_hoverClose;
|
||||
if (closeHot)
|
||||
{
|
||||
UiFillRoundRect(g, tab.closeRect, 3.0f * m_scale, m_theme->pressed);
|
||||
}
|
||||
const float cx = tab.closeRect.X + tab.closeRect.Width * 0.5f;
|
||||
const float cy = tab.closeRect.Y + tab.closeRect.Height * 0.5f;
|
||||
const std::uint32_t iconColor =
|
||||
closeHot ? m_theme->danger : (active ? m_theme->text : m_theme->textMuted);
|
||||
UiDrawLine(g, cx - closeIconSize * 0.5f, cy - closeIconSize * 0.5f, cx + closeIconSize * 0.5f,
|
||||
cy + closeIconSize * 0.5f, iconColor, 1.4f * m_scale);
|
||||
UiDrawLine(g, cx + closeIconSize * 0.5f, cy - closeIconSize * 0.5f, cx - closeIconSize * 0.5f,
|
||||
cy + closeIconSize * 0.5f, iconColor, 1.4f * m_scale);
|
||||
}
|
||||
|
||||
// 新建按钮。
|
||||
const std::uint32_t addBg = m_hoverAdd ? m_theme->hover : m_theme->panelBg;
|
||||
UiFillRoundRect(g, m_addRect, kCorner * m_scale, addBg);
|
||||
UiDrawRoundRect(g, m_addRect, kCorner * m_scale, m_theme->border, 1.0f);
|
||||
|
||||
const float ax = m_addRect.X + m_addRect.Width * 0.5f;
|
||||
const float ay = m_addRect.Y + m_addRect.Height * 0.5f;
|
||||
const float armLength = 4.5f * m_scale;
|
||||
const std::uint32_t addColor = m_hoverAdd ? m_theme->accent : m_theme->text;
|
||||
UiDrawLine(g, ax - armLength, ay, ax + armLength, ay, addColor, 1.6f * m_scale);
|
||||
UiDrawLine(g, ax, ay - armLength, ax, ay + armLength, addColor, 1.6f * m_scale);
|
||||
|
||||
// 底部分隔线。
|
||||
UiDrawLine(g, m_area.X, m_area.Y + m_area.Height - 1.0f, m_area.X + m_area.Width,
|
||||
m_area.Y + m_area.Height - 1.0f, m_theme->border, 1.0f);
|
||||
}
|
||||
|
||||
bool TabBar::HitTest(int x, int y) const
|
||||
{
|
||||
return UiPointInRect(m_area, static_cast<float>(x), static_cast<float>(y));
|
||||
}
|
||||
|
||||
int TabBar::TabAtPoint(int x, int y) const
|
||||
{
|
||||
const float fx = static_cast<float>(x);
|
||||
const float fy = static_cast<float>(y);
|
||||
for (std::size_t index = 0; index < m_tabs.size(); ++index)
|
||||
{
|
||||
if (UiPointInRect(m_tabs[index].rect, fx, fy))
|
||||
{
|
||||
return static_cast<int>(index);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool TabBar::OnMouseMove(int x, int y)
|
||||
{
|
||||
const int index = TabAtPoint(x, y);
|
||||
const bool overClose =
|
||||
(index >= 0 && UiPointInRect(m_tabs[static_cast<std::size_t>(index)].closeRect,
|
||||
static_cast<float>(x), static_cast<float>(y)));
|
||||
const bool overAdd = UiPointInRect(m_addRect, static_cast<float>(x), static_cast<float>(y));
|
||||
|
||||
if (index == m_hoverIndex && overClose == m_hoverClose && overAdd == m_hoverAdd)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
m_hoverIndex = index;
|
||||
m_hoverClose = overClose;
|
||||
m_hoverAdd = overAdd;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TabBar::OnLButtonDown(int x, int y)
|
||||
{
|
||||
m_pressedIndex = -1;
|
||||
m_pressedClose = false;
|
||||
m_pressedAdd = false;
|
||||
|
||||
if (UiPointInRect(m_addRect, static_cast<float>(x), static_cast<float>(y)))
|
||||
{
|
||||
m_pressedAdd = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
const int index = TabAtPoint(x, y);
|
||||
if (index < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_pressedIndex = index;
|
||||
m_pressedClose = UiPointInRect(m_tabs[static_cast<std::size_t>(index)].closeRect,
|
||||
static_cast<float>(x), static_cast<float>(y));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TabBar::OnLButtonUp(int x, int y, TabBarResult& result)
|
||||
{
|
||||
result = TabBarResult();
|
||||
|
||||
if (m_pressedAdd)
|
||||
{
|
||||
m_pressedAdd = false;
|
||||
if (UiPointInRect(m_addRect, static_cast<float>(x), static_cast<float>(y)))
|
||||
{
|
||||
result.type = TabBarResult::Type::ADD;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (m_pressedIndex < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const int index = m_pressedIndex;
|
||||
const bool wasClose = m_pressedClose;
|
||||
m_pressedIndex = -1;
|
||||
m_pressedClose = false;
|
||||
|
||||
if (TabAtPoint(x, y) != index)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (wasClose)
|
||||
{
|
||||
result.type = TabBarResult::Type::CLOSE;
|
||||
result.index = index;
|
||||
}
|
||||
else
|
||||
{
|
||||
result.type = TabBarResult::Type::SELECT;
|
||||
result.index = index;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TabBar::OnRButtonDown(int x, int y, int screenX, int screenY, TabBarResult& result)
|
||||
{
|
||||
result = TabBarResult();
|
||||
|
||||
const int index = TabAtPoint(x, y);
|
||||
if (index < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
result.type = TabBarResult::Type::CONTEXT;
|
||||
result.index = index;
|
||||
result.screenX = screenX;
|
||||
result.screenY = screenY;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TabBar::OnMouseLeave()
|
||||
{
|
||||
if (m_hoverIndex < 0 && !m_hoverClose && !m_hoverAdd)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
m_hoverIndex = -1;
|
||||
m_hoverClose = false;
|
||||
m_hoverAdd = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace jdi
|
||||
Reference in new issue
Block a user