fix: 修复图例改名不同步、细化网格标尺并支持标签页重排与曲线实色跟随拖拽
- 图例跟随重命名:绘图区图例文本改用信号当前显示名(Title), 左侧列表改名后网格图例立即同步。 - 标签页重排与改名:新增拖拽排序(按住标签左右拖动并显示插入指示条, 重排后保持原激活页)与双击内联改名,新增 MoveTab 正确处理激活下标。 修复改名后未重新布局导致标签页整条消失的问题(SetTabs 会重置标签矩形)。 双击判定改为自行按双击时间识别,不再依赖系统 WM_LBUTTONDBLCLK。 - 信号拖拽:虚影改用原信号颜色与线宽(不再画成虚线),保持原有线段/散点样式; 横向与纵向均自由跟随鼠标位移;拖拽首帧位移为零,虚影始终贴合在鼠标下方。 - 网格与标尺细化:时间轴与幅值轴期望刻度数提高,并在相邻主刻度之间 补绘 5 等分细线,便于目视估读。 - 图例定位与交互:图例移到各网格左上角,与标尺数字冲突时优先显示图例 (标尺数值主动避让);图例条目支持单击选中信号(与左侧列表联动、 样式区随之切换目标)与双击重命名信号。 - 网格划分:合并网格后新勾选的信号不再被并入那个唯一的合并网格, 而是自动切换为自定义划分并独占一个新网格。 - 工具栏:「每信号一格」改名为「拆分信号网格」。 - 清理:移除已无引用的 UiDrawArrowIcon 与 m_styleContentRect。
This commit is contained in:
1 parent
261b8ac07d
commit
4e295a2a7d
12 files changed
+800
-109
No files matched your search
@@ -28,11 +28,15 @@ namespace jdi
|
||||
SELECT, /**< 切换到指定标签页。 */
|
||||
CLOSE, /**< 关闭指定标签页。 */
|
||||
ADD, /**< 新建标签页。 */
|
||||
CONTEXT /**< 请求弹出标签页上下文菜单。 */
|
||||
CONTEXT, /**< 请求弹出标签页上下文菜单。 */
|
||||
REORDER, /**< 拖拽调整标签页顺序。 */
|
||||
RENAME /**< 提交标签页重命名。 */
|
||||
};
|
||||
|
||||
Type type = Type::NONE; /**< 动作类型。 */
|
||||
int index = -1; /**< 标签页下标(ADD 时无意义)。 */
|
||||
int targetIndex = -1; /**< REORDER 的目标位置。 */
|
||||
std::wstring text; /**< RENAME 的新名称。 */
|
||||
int screenX = 0; /**< 上下文菜单请求的屏幕横坐标。 */
|
||||
int screenY = 0; /**< 上下文菜单请求的屏幕纵坐标。 */
|
||||
};
|
||||
@@ -124,6 +128,48 @@ namespace jdi
|
||||
*/
|
||||
bool OnRButtonDown(int x, int y, int screenX, int screenY, TabBarResult& result);
|
||||
|
||||
/**
|
||||
* @brief 处理鼠标左键双击(进入标签页重命名)。
|
||||
* @param [IN] x 客户区横坐标。
|
||||
* @param [IN] y 客户区纵坐标。
|
||||
* @return 进入编辑态返回 true。
|
||||
*/
|
||||
bool OnDoubleClick(int x, int y);
|
||||
|
||||
/**
|
||||
* @brief 判断标签栏是否处于重命名编辑态。
|
||||
* @return 处于编辑态返回 true。
|
||||
*/
|
||||
bool IsEditing() const { return m_editIndex >= 0; }
|
||||
|
||||
/**
|
||||
* @brief 处理编辑态下的字符输入。
|
||||
* @param [IN] character 输入字符。
|
||||
* @return 界面状态发生变化返回 true。
|
||||
*/
|
||||
bool OnEditChar(wchar_t character);
|
||||
|
||||
/**
|
||||
* @brief 处理编辑态下的按键。
|
||||
* @param [IN] key 虚拟键码。
|
||||
* @param [OUT] result 提交重命名时返回结果。
|
||||
* @return 事件已被消费返回 true。
|
||||
*/
|
||||
bool OnEditKey(WPARAM key, TabBarResult& result);
|
||||
|
||||
/**
|
||||
* @brief 查询拖拽排序时应当插入的位置。
|
||||
* @param [IN] x 客户区横坐标。
|
||||
* @return 插入下标(0..标签数量)。
|
||||
*/
|
||||
int DropIndexAt(int x) const;
|
||||
|
||||
/**
|
||||
* @brief 判断是否正在拖动标签页。
|
||||
* @return 正在拖动返回 true。
|
||||
*/
|
||||
bool IsDragging() const { return m_dragIndex >= 0; }
|
||||
|
||||
/**
|
||||
* @brief 处理鼠标离开标签栏。
|
||||
* @return 视觉状态发生变化返回 true。
|
||||
@@ -172,6 +218,18 @@ namespace jdi
|
||||
int m_pressedIndex = -1; /**< 当前按下的标签页下标。 */
|
||||
bool m_pressedClose = false; /**< 是否按在关闭按钮上。 */
|
||||
bool m_pressedAdd = false; /**< 是否按在新建按钮上。 */
|
||||
|
||||
int m_dragIndex = -1; /**< 正在拖动排序的标签页下标,-1 表示未拖动。 */
|
||||
int m_dragMouseX = 0; /**< 拖动过程中鼠标横坐标。 */
|
||||
bool m_dragMoved = false; /**< 拖动过程中是否发生了位移。 */
|
||||
int m_pressedX = 0; /**< 按下时的横坐标(用于判定拖动阈值)。 */
|
||||
|
||||
int m_editIndex = -1; /**< 正在重命名的标签页下标,-1 表示未编辑。 */
|
||||
std::wstring m_editText; /**< 重命名输入文本。 */
|
||||
bool m_editFresh = false; /**< 是否处于“首次输入整体替换”状态。 */
|
||||
|
||||
int m_lastClickIndex = -1; /**< 上一次单击的标签页下标(用于自行判定双击)。 */
|
||||
DWORD m_lastClickTick = 0; /**< 上一次单击的时刻。 */
|
||||
};
|
||||
|
||||
} // namespace jdi
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
#include "Utf8Util.hpp"
|
||||
|
||||
namespace jdi
|
||||
{
|
||||
|
||||
@@ -134,10 +136,22 @@ namespace jdi
|
||||
|
||||
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);
|
||||
|
||||
// 重命名编辑态:在标签本体之上叠加输入框(标签底色与边框仍然保留)。
|
||||
if (static_cast<int>(index) == m_editIndex)
|
||||
{
|
||||
const gd::RectF editRect(textLeft - 3.0f * m_scale, tab.rect.Y + 3.0f * m_scale,
|
||||
std::max(40.0f, textWidth + 6.0f * m_scale),
|
||||
tab.rect.Height - 6.0f * m_scale);
|
||||
UiDrawEditField(g, editRect, m_editText, m_editFresh, m_fonts->ui, m_scale);
|
||||
}
|
||||
else
|
||||
{
|
||||
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;
|
||||
@@ -155,6 +169,22 @@ namespace jdi
|
||||
cy + closeIconSize * 0.5f, iconColor, 1.4f * m_scale);
|
||||
}
|
||||
|
||||
// 拖拽排序时在插入位置绘制强调色指示条。
|
||||
if (m_dragIndex >= 0 && m_dragMoved && !m_tabs.empty())
|
||||
{
|
||||
const int drop = DropIndexAt(m_dragMouseX);
|
||||
float markerX = m_addRect.X;
|
||||
if (drop < static_cast<int>(m_tabs.size()))
|
||||
{
|
||||
markerX = m_tabs[static_cast<std::size_t>(drop)].rect.X - kAddGap * m_scale * 0.5f;
|
||||
}
|
||||
|
||||
const float top = m_area.Y + kTopMargin * m_scale;
|
||||
const float bottom = top + kTabHeight * m_scale;
|
||||
UiFillRoundRect(g, gd::RectF(markerX - 1.5f * m_scale, top, 3.0f * m_scale, bottom - top),
|
||||
1.5f * m_scale, m_theme->accent);
|
||||
}
|
||||
|
||||
// 新建按钮。
|
||||
const std::uint32_t addBg = m_hoverAdd ? m_theme->hover : m_theme->panelBg;
|
||||
UiFillRoundRect(g, m_addRect, kCorner * m_scale, addBg);
|
||||
@@ -193,6 +223,18 @@ namespace jdi
|
||||
|
||||
bool TabBar::OnMouseMove(int x, int y)
|
||||
{
|
||||
// 拖动排序中:只跟踪鼠标位置,由界面层绘制插入指示。
|
||||
if (m_dragIndex >= 0)
|
||||
{
|
||||
if (x != m_dragMouseX)
|
||||
{
|
||||
m_dragMouseX = x;
|
||||
m_dragMoved = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const int index = TabAtPoint(x, y);
|
||||
const bool overClose =
|
||||
(index >= 0 && UiPointInRect(m_tabs[static_cast<std::size_t>(index)].closeRect,
|
||||
@@ -215,6 +257,13 @@ namespace jdi
|
||||
m_pressedClose = false;
|
||||
m_pressedAdd = false;
|
||||
|
||||
// 编辑态下点击其它位置先提交重命名。
|
||||
if (IsEditing())
|
||||
{
|
||||
TabBarResult ignored;
|
||||
OnEditKey(VK_RETURN, ignored);
|
||||
}
|
||||
|
||||
if (UiPointInRect(m_addRect, static_cast<float>(x), static_cast<float>(y)))
|
||||
{
|
||||
m_pressedAdd = true;
|
||||
@@ -228,8 +277,25 @@ namespace jdi
|
||||
}
|
||||
|
||||
m_pressedIndex = index;
|
||||
m_dragIndex = index;
|
||||
m_dragMouseX = x;
|
||||
m_pressedX = x;
|
||||
m_dragMoved = false;
|
||||
m_pressedClose = UiPointInRect(m_tabs[static_cast<std::size_t>(index)].closeRect,
|
||||
static_cast<float>(x), static_cast<float>(y));
|
||||
|
||||
// 自行判定双击:不依赖系统 WM_LBUTTONDBLCLK,行为在不同环境下更一致。
|
||||
const DWORD now = GetTickCount();
|
||||
const bool sameTab = (index == m_lastClickIndex);
|
||||
const DWORD elapsed = now - m_lastClickTick;
|
||||
if (!m_pressedClose && sameTab && elapsed <= GetDoubleClickTime())
|
||||
{
|
||||
m_lastClickIndex = -1;
|
||||
OnDoubleClick(x, y);
|
||||
return true;
|
||||
}
|
||||
m_lastClickIndex = m_pressedClose ? -1 : index;
|
||||
m_lastClickTick = now;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -249,13 +315,30 @@ namespace jdi
|
||||
|
||||
if (m_pressedIndex < 0)
|
||||
{
|
||||
m_dragIndex = -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
const int index = m_pressedIndex;
|
||||
const bool wasClose = m_pressedClose;
|
||||
const bool dragged = m_dragMoved && (std::abs(x - m_pressedX) > 3);
|
||||
m_pressedIndex = -1;
|
||||
m_pressedClose = false;
|
||||
m_dragIndex = -1;
|
||||
m_dragMoved = false;
|
||||
|
||||
// 拖动超过阈值:按释放位置重新排序。
|
||||
if (dragged && !wasClose)
|
||||
{
|
||||
const int target = DropIndexAt(x);
|
||||
if (target >= 0 && target != index && target != index + 1)
|
||||
{
|
||||
result.type = TabBarResult::Type::REORDER;
|
||||
result.index = index;
|
||||
result.targetIndex = target;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (TabAtPoint(x, y) != index)
|
||||
{
|
||||
@@ -275,6 +358,121 @@ namespace jdi
|
||||
return true;
|
||||
}
|
||||
|
||||
int TabBar::DropIndexAt(int x) const
|
||||
{
|
||||
const float fx = static_cast<float>(x);
|
||||
for (std::size_t index = 0; index < m_tabs.size(); ++index)
|
||||
{
|
||||
const gd::RectF& rect = m_tabs[index].rect;
|
||||
if (fx < rect.X + rect.Width * 0.5f)
|
||||
{
|
||||
return static_cast<int>(index);
|
||||
}
|
||||
}
|
||||
return static_cast<int>(m_tabs.size());
|
||||
}
|
||||
|
||||
bool TabBar::OnDoubleClick(int x, int y)
|
||||
{
|
||||
const int index = TabAtPoint(x, y);
|
||||
if (index < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// 双击关闭按钮不进入重命名。
|
||||
if (UiPointInRect(m_tabs[static_cast<std::size_t>(index)].closeRect, static_cast<float>(x),
|
||||
static_cast<float>(y)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_editIndex = index;
|
||||
m_editText = m_tabs[static_cast<std::size_t>(index)].name;
|
||||
m_editFresh = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TabBar::OnEditChar(wchar_t character)
|
||||
{
|
||||
if (m_editIndex < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (character == L'\r' || character == L'\n')
|
||||
{
|
||||
TabBarResult result;
|
||||
OnEditKey(VK_RETURN, result);
|
||||
return true;
|
||||
}
|
||||
if (character == L'\b')
|
||||
{
|
||||
m_editFresh = false;
|
||||
if (!m_editText.empty())
|
||||
{
|
||||
m_editText.pop_back();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (character < L' ')
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (m_editFresh)
|
||||
{
|
||||
m_editText.clear();
|
||||
m_editFresh = false;
|
||||
}
|
||||
if (m_editText.size() < 48)
|
||||
{
|
||||
m_editText.push_back(character);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TabBar::OnEditKey(WPARAM key, TabBarResult& result)
|
||||
{
|
||||
result = TabBarResult();
|
||||
if (m_editIndex < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const int index = m_editIndex;
|
||||
switch (key)
|
||||
{
|
||||
case VK_RETURN:
|
||||
{
|
||||
const std::wstring text = Trim(m_editText);
|
||||
m_editIndex = -1;
|
||||
m_editFresh = false;
|
||||
m_editText.clear();
|
||||
if (!text.empty())
|
||||
{
|
||||
result.type = TabBarResult::Type::RENAME;
|
||||
result.index = index;
|
||||
result.text = text;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case VK_ESCAPE:
|
||||
m_editIndex = -1;
|
||||
m_editFresh = false;
|
||||
m_editText.clear();
|
||||
return true;
|
||||
case VK_BACK:
|
||||
m_editFresh = false;
|
||||
if (!m_editText.empty())
|
||||
{
|
||||
m_editText.pop_back();
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TabBar::OnRButtonDown(int x, int y, int screenX, int screenY, TabBarResult& result)
|
||||
{
|
||||
result = TabBarResult();
|
||||
|
||||
Reference in new issue
Block a user