## 一、UI 交互修复(用户报告) ① 分组折起热区(用户要求):点分组**名称**不再折起,只有**折叠三角**或**「组X」标签** 才折起。RowPart 新增 GROUP_TITLE;RowHitPart() 为分组行判出三角 / 复选框 / 关闭 ✕ / 「组X」标签矩形 / 其余 BODY;OnLButtonDown 只在这两个热区调用 ToggleGroupFromRow()。 附带:双击「组X」不再进入改名(该区域现为折起热区),双击分组名仍可改名。 ② 分组改名输入框不再吞掉「N 项」:RowNameRect() 对分组行的右边界改为「项数左边缘 − 6*scale」; 新增 GroupLabelText()/GroupStatsText() 作为文本与宽度的唯一来源(PaintGroupRow 与 RowNameRect 共用),避免名称可用宽度与实际绘制文本漂移。 ## 二、数据模型去冗余(用户指出的重点) - SignalData / SignalGroup **只保留一个名称字段** name:删除 displayName、删除 Title() (31 处调用点改为直接用 name);DataSet::SetSignalDisplayName / SetGroupDisplayName → RenameSignal / RenameGroup,且**空串 / 纯空白一律拒绝**(名称不再有回退值)。 依据:信号靠 SignalRef 下标定位、从不按名字匹配 ⇒ 两个字段是同一语义的两份副本。 收益:每条信号 / 每个分组少一个 std::wstring(24B + 堆分配)与一条 Title() 分支。 - 删除 Application::m_loadingBytes(全仓既不读也不写的死成员,注释却称“用于展示体积”)。 ## 三、新增 Components/Shared 组件(通用 UI 控件) - 从 Utilities/PaintUtil.* 迁出全部「控件类」绘制/命中:图标(+ / ✕ / 三角)、复选框、 滑块(UiSliderRatioFromX / UiDrawSlider)、内联输入框(UiDrawEditField / UiDrawEditFieldContent / UiEditTextLeft / UiEditOffsetAt / UiEditFieldMouseDown / UiEditFieldMouseMove)、颜色样块(UiDrawSwatch / UiSwatchNeedsOutline)、 取值胶囊配色(UiInk / UiColorLuminance / UiContrastInk)。 - PaintUtil.* 只保留低层绘制原语(矩形 / 圆角 / 直线 / 批量实线 / 颜色混合 / 文本与测量)。 - 依赖方向固定:Components/* → Components/Shared → Utilities(不得反向,Utilities 不再含控件)。 - Makefile 与 .preflight/perf/build.ps1 已登记新目录;调用方改 include "UiControls.hpp"。 ## 四、过时注释 / 命名批量修正(承接上一轮未做完的部分) - 注释:文件下标→分组下标、文件内信号下标→组内信号下标、所属文件下标→所属分组下标; 措辞统一 文件分组→分组、移除该文件→移除该分组、打开 CSV 文件→打开数据文件 等一批。 - 文不对题的形参名:VisibleIndexRange(const TimeAxis& file,…) → axis; Application::LoadFileAsync(…, SignalGroup& file,…) → group。 - 函数名里的 File 语义(上一轮只改了 RowKind::FILE):PaintFileRow→PaintGroupRow、 FileCloseRect→GroupCloseRect、OpenFileMenu→OpenGroupMenu、FileGroupLabelWidth→GroupLabelWidth、 StyleEditField::FILE_NAME→GROUP_TITLE;局部变量 fileRow/fileHeight/isFile → groupRow/groupHeight/isGroup。 - 修复 DataModel.hpp 两处被压扁的注释块(/**<TAB><TAB>* @brief …)与 Application::NewTab 上方重复的文档块。 - ⚠️ 踩坑:GROUP_NAME 撞上 nb30.h(windows.h 引入)的 #define GROUP_NAME 0x80, 导致枚举编译失败,改名 GROUP_TITLE 解决。 ## 五、二进制瘦身:1 013 248 → 754 176 B(−25.6%,省 259 KB) - 真因不是 PlotView.cpp,而是 Resources/JustDataInspector.ico 里 **256×256@32bpp 以未压缩 BMP 存储的条目(270 376 B,占整包 27%)**。改为 PNG 存储(Vista+ 标准做法,观感零变化) ⇒ 该条目 270 376 → 11 280 B、整个 ico 302 430 → 43 334 B(小尺寸仍保留 BMP)。 - 实测结论:“拆分大文件 ⇒ 瘦身”不成立(同一批机器码仍要进二进制); -ffunction-sections/-fdata-sections/-Wl,--gc-sections 在本工程反而 +9 216 B(已回退)。 - ⚠️ .o 体积受节对齐/重定位表主导,判断“代码搬去哪了”要用 nm,不要看 .o 字节数。 ## 六、验证(全部离屏:SW_HIDE + 不注入真实输入 + 进程/线程 BELOW_NORMAL) - panelanim 156/156(连跑 5 次稳定;新增/更新:点分组名不折起也不滚动、扫掠定位「组X」热区、 筛选态与普通态折叠三角逐像素一致、改名输入框右边界早于项数文本);verify 49/49; datacheck 69/69(含“重命名写入唯一名称字段且空名被拒”);edgecheck 46/46。 - A/B:回退两处 UI 修复 ⇒ 10 项如实失败;恢复后全绿。 - make release / make debug 零警告。 ## 七、本轮未完成(已在报告与 agent_mem.md 中如实记录) - PlotView.cpp(13 695 行 / 544 KB)按功能拆分为多个协作文件:未执行。 前置改造是把第 13–888 行的匿名命名空间(~870 行常量与工具函数)改成具名命名空间并逐个 inline,再逐个文件搬移并反复验证;时间不足以安全完成,故主动不做(附可执行方案)。 - SignalPanel.cpp / Application.cpp / DataModel.cpp 的多文件化、Lane 抽出 LanePanelState、 SetStatusMessage 模态阻塞解耦:均未执行。 ## 八、文档 - 新增 Documents/refactor_report_2026-10-16.md(本轮详细报告); 删除 Documents/refactor_report_2026-10-15.md(有效内容已并入 agent_mem.md 与本报告)。 - Documents/agent_mem.md 新增 §9.37 与 §11.2 第 85–90 条;更新数据层架构摘要(单一名称字段); §12 历史附录加“时效声明”。
608 lines
17 KiB
C++
608 lines
17 KiB
C++
#include "TabBar.hpp"
|
|
|
|
#include "UiControls.hpp"
|
|
#include <algorithm>
|
|
#include <cmath>
|
|
|
|
#include "Utf8Util.hpp"
|
|
|
|
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; /**< 单个标签最大宽度(逻辑像素)。 */
|
|
const float kEditingTabWidth = 320.0f; /**< 重命名输入时标签的最大宽度(便于看清长名称)。 */
|
|
const float kMinTabWidth = 70.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 minWidth = kMinTabWidth * m_scale;
|
|
const float addSize = kAddSize * m_scale;
|
|
|
|
// 标签宽度按「加粗字体」测量:激活页用 uiBold 绘制,
|
|
// 若按常规字体测量,加粗后的长名称会在激活时被省略号截断(预览过短)。
|
|
std::vector<float> desired;
|
|
desired.reserve(m_tabs.size());
|
|
float total = kLeftPadding * m_scale;
|
|
for (std::size_t index = 0; index < m_tabs.size(); ++index)
|
|
{
|
|
const bool editing = (static_cast<int>(index) == m_editIndex);
|
|
|
|
// 重命名过程中按「正在输入的文本」测量,标签才能随输入逐步变宽;
|
|
// 否则始终按已提交的旧名称算宽度,长名称会被挤成很短的一截(预览过短)。
|
|
const std::wstring& measureText = editing ? m_edit.Text() : m_tabs[index].name;
|
|
const float boldWidth = UiMeasureTextWidth(m_fonts->uiBold, measureText);
|
|
const float regularWidth = UiMeasureTextWidth(m_fonts->ui, measureText);
|
|
const float textWidth = std::max(boldWidth, regularWidth);
|
|
|
|
const float maxWidth = (editing ? kEditingTabWidth : kMaxTabWidth) * m_scale;
|
|
|
|
float width = kTabPadding * 2.0f * m_scale + textWidth + kCloseGap * m_scale + closeSize;
|
|
width = std::max(minWidth, std::min(width, maxWidth));
|
|
desired.push_back(width);
|
|
total += width + kAddGap * m_scale;
|
|
}
|
|
total += addSize;
|
|
|
|
// 标签总宽超出可用宽度时整体等比收缩,保证「+」按钮始终可见。
|
|
const float available = area.Width - kLeftPadding * m_scale;
|
|
float shrink = 1.0f;
|
|
if (total > available && total > 0.0f)
|
|
{
|
|
shrink = available / total;
|
|
}
|
|
|
|
float cursorX = area.X + kLeftPadding * m_scale;
|
|
for (std::size_t index = 0; index < m_tabs.size(); ++index)
|
|
{
|
|
TabItem& tab = m_tabs[index];
|
|
float width = std::max(minWidth * shrink, desired[index] * shrink);
|
|
|
|
// 收缩后仍要保证「文本 + 关闭按钮」有最小可用空间。
|
|
width = std::max(width, closeSize + kTabPadding * m_scale + 8.0f * m_scale);
|
|
|
|
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;
|
|
}
|
|
|
|
m_addRect = gd::RectF(std::min(cursorX, area.X + area.Width - addSize - 2.0f * m_scale),
|
|
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;
|
|
|
|
// 重命名编辑态:在标签本体之上叠加输入框(标签底色与边框仍然保留)。
|
|
if (static_cast<int>(index) == m_editIndex)
|
|
{
|
|
UiDrawEditField(g, EditRect(), m_edit, m_fonts->ui, m_scale);
|
|
}
|
|
else
|
|
{
|
|
const std::wstring label = UiEllipsize(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);
|
|
}
|
|
|
|
// 拖拽排序时在插入位置绘制强调色指示条。
|
|
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);
|
|
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)
|
|
{
|
|
// 拖动排序中:只跟踪鼠标位置,由界面层绘制插入指示。
|
|
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,
|
|
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 (IsEditing())
|
|
{
|
|
TabBarResult ignored;
|
|
OnEditKey(VK_RETURN, ignored);
|
|
}
|
|
|
|
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_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;
|
|
}
|
|
|
|
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)
|
|
{
|
|
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)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
if (wasClose)
|
|
{
|
|
// 关闭 ✕ 只在"按下后仍在 ✕ 上抬起"时生效:按住后移开再松开视为放弃
|
|
// (与信号面板的分组/信号 ✕ 保持一致的交互语义)。
|
|
if (UiPointInRect(m_tabs[static_cast<std::size_t>(index)].closeRect,
|
|
static_cast<float>(x), static_cast<float>(y)))
|
|
{
|
|
result.type = TabBarResult::Type::CLOSE;
|
|
result.index = index;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
result.type = TabBarResult::Type::SELECT;
|
|
result.index = index;
|
|
}
|
|
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_edit.Begin(m_tabs[static_cast<std::size_t>(index)].name, true, EditFilter::ANY, 0u);
|
|
return true;
|
|
}
|
|
|
|
bool TabBar::OnEditChar(wchar_t character)
|
|
{
|
|
if (m_editIndex < 0)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
// 剪贴板与全选快捷键经 WM_CHAR 送达(Ctrl+C/X/V/A 分别对应 3/24/22/1)。
|
|
switch (character)
|
|
{
|
|
case 0x03: // Ctrl+C
|
|
m_edit.CopyToClipboard(m_host);
|
|
return false;
|
|
case 0x18: // Ctrl+X
|
|
return m_edit.CutToClipboard(m_host);
|
|
case 0x16: // Ctrl+V
|
|
return m_edit.PasteFromClipboard(m_host);
|
|
case 0x01: // Ctrl+A
|
|
m_edit.SelectAll();
|
|
return true;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
if (character == L'\r' || character == L'\n')
|
|
{
|
|
TabBarResult result;
|
|
OnEditKey(VK_RETURN, result);
|
|
return true;
|
|
}
|
|
// 退格/删除已由 WM_KEYDOWN 的 OnEditKey 处理,此处忽略全部控制字符。
|
|
if (character < L' ' || character == 0x7F)
|
|
{
|
|
return false;
|
|
}
|
|
return m_edit.Insert(character);
|
|
}
|
|
|
|
bool TabBar::OnEditKey(WPARAM key, TabBarResult& result)
|
|
{
|
|
result = TabBarResult();
|
|
if (m_editIndex < 0)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
const int index = m_editIndex;
|
|
const bool shift = (GetKeyState(VK_SHIFT) & 0x8000) != 0;
|
|
const bool control = (GetKeyState(VK_CONTROL) & 0x8000) != 0;
|
|
|
|
switch (key)
|
|
{
|
|
case VK_RETURN:
|
|
{
|
|
const std::wstring text = Trim(m_edit.Text());
|
|
m_editIndex = -1;
|
|
m_edit.End();
|
|
if (!text.empty())
|
|
{
|
|
result.type = TabBarResult::Type::RENAME;
|
|
result.index = index;
|
|
result.text = text;
|
|
}
|
|
return true;
|
|
}
|
|
case VK_ESCAPE:
|
|
m_editIndex = -1;
|
|
m_edit.End();
|
|
return true;
|
|
case VK_BACK:
|
|
return m_edit.Backspace();
|
|
case VK_DELETE:
|
|
return m_edit.DeleteForward();
|
|
case VK_LEFT:
|
|
return m_edit.MoveCaret(-1, shift);
|
|
case VK_RIGHT:
|
|
return m_edit.MoveCaret(1, shift);
|
|
case VK_HOME:
|
|
return m_edit.MoveHome(shift);
|
|
case VK_END:
|
|
return m_edit.MoveEnd(shift);
|
|
case 'A':
|
|
if (control)
|
|
{
|
|
m_edit.SelectAll();
|
|
}
|
|
return true;
|
|
default:
|
|
break;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool TabBar::CollapseEditSelectionToEnd()
|
|
{
|
|
if (m_editIndex < 0)
|
|
{
|
|
return false;
|
|
}
|
|
return m_edit.DeselectToEnd();
|
|
}
|
|
|
|
gd::RectF TabBar::EditRect() const
|
|
{
|
|
if (m_editIndex < 0 || m_editIndex >= static_cast<int>(m_tabs.size()) || m_fonts == nullptr)
|
|
{
|
|
return gd::RectF();
|
|
}
|
|
|
|
const TabItem& tab = m_tabs[static_cast<std::size_t>(m_editIndex)];
|
|
const float textLeft = tab.rect.X + kTabPadding * m_scale;
|
|
const float textWidth = tab.closeRect.X - kCloseGap * m_scale - textLeft;
|
|
return gd::RectF(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);
|
|
}
|
|
|
|
bool TabBar::OnEditMouseDown(int x, int y)
|
|
{
|
|
if (m_editIndex < 0)
|
|
{
|
|
return false;
|
|
}
|
|
return UiEditFieldMouseDown(m_fonts->ui, EditRect(), m_edit, m_scale, x, y);
|
|
}
|
|
|
|
bool TabBar::OnEditMouseMove(int x)
|
|
{
|
|
if (m_editIndex < 0)
|
|
{
|
|
return false;
|
|
}
|
|
return UiEditFieldMouseMove(m_fonts->ui, EditRect(), m_edit, m_scale, x);
|
|
}
|
|
|
|
bool TabBar::OnEditMouseUp()
|
|
{
|
|
if (!m_edit.Dragging())
|
|
{
|
|
return false;
|
|
}
|
|
m_edit.EndDrag();
|
|
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
|