fix: 统一输入框编辑能力、修复拖拽合并网格并支持光标吸附数据点
统一文本输入(新增 Utilities/Inc/TextEdit.hpp + TextEdit.cpp) - 一个共享的编辑模型,提供光标/选区/过滤/限长,接入全部输入框: 样式区数值与信号名/分组名、波形图例改名、视图标签页改名、 拾色器 R/G/B 与色号、光标时间与网格上下限。 - 新增能力:Ctrl+A/C/X/V(含剪贴板清洗)、Shift+方向键与 Home/End 选区、 退格与删除清除选区、代理对安全的光标步进。 - 渲染改为选区高亮 + 插入符,文本超出框宽时水平滚动并让插入符始终可见; 初始态为整段选中,首字符键入即整体替换(保持"登录框"式交互)。 - 新增 Utf8Util::PasteTextFromClipboard(换行/制表符折叠为空格)。 修复网格合并(Utilities/Src/DataModel.cpp) - 拖拽信号到其它网格时先固定目标网格的锚信号,再移除源信号并按引用找回目标, 避免空网格回收导致下标错位,从"与原网格交换位置"改为真正合并。 - 自定义划分下未分配网格的可见信号改为各自独占一个新网格, 修复"拖拽合并后再勾选新信号被并入该合并网格"的问题。 绘图区(Components/PlotView) - 网格右键菜单新增"时间轴自适应(匹配本网格)",把时间轴对齐到该网格信号范围。 - 时间轴放大到采样点在屏幕上可分辨(>=6 逻辑像素)时,拖动光标吸附到最近数据点; 缩小到无法分辨时保持自由移动,避免光标"跳格"。 验证:真实输入脚本逐项核对——拖拽合并后单网格含两条曲线、拖拽合并再勾选新信号得 G2 独立网格、 Shift 选区 + Delete 清除、Ctrl+A/C/V 复制粘贴、46 字符文本水平滚动、拾色器色号 1E90FF、 标签页改名 A1、光标时间框复制粘贴、全视图拖动得 0.522213(不吸附)而放大后得 0.28125(= 225 × 0.00125,已吸附)。
This commit is contained in:
1 parent
4e295a2a7d
commit
53768b8b25
16 files changed
+1135
-288
No files matched your search
+67
-18
@@ -428,8 +428,7 @@ namespace jdi
|
||||
knobRadius * 2.0f);
|
||||
}
|
||||
|
||||
void UiDrawEditField(gd::Graphics& g, const gd::RectF& rect, const std::wstring& text, bool fresh,
|
||||
HFONT font, float scale)
|
||||
void UiDrawEditField(gd::Graphics& g, const gd::RectF& rect, const TextEdit& edit, HFONT font, float scale)
|
||||
{
|
||||
if (rect.Width <= 0.0f || rect.Height <= 0.0f || font == nullptr)
|
||||
{
|
||||
@@ -442,29 +441,79 @@ namespace jdi
|
||||
UiFillRoundRect(g, rect, corner, theme.cardBg);
|
||||
UiDrawRoundRect(g, rect, corner, theme.accent, 1.6f);
|
||||
|
||||
const std::wstring shown = text.empty() ? std::wstring(L" ") : text;
|
||||
|
||||
if (fresh)
|
||||
const std::wstring& text = edit.Text();
|
||||
if (text.empty())
|
||||
{
|
||||
// 整段内容处于“将被覆盖”状态:以强调色底衬表示已全选。
|
||||
const float textWidth = UiTextWidth(g, shown, font) + 8.0f * scale;
|
||||
const gd::RectF highlight(rect.X + (rect.Width - textWidth) * 0.5f, rect.Y + 2.0f * scale,
|
||||
textWidth, rect.Height - 4.0f * scale);
|
||||
UiFillRoundRect(g, highlight, 2.0f * scale, theme.accent);
|
||||
UiText(g, shown, font, highlight, theme.textOnAccent, TextAlign::CENTER);
|
||||
// 空内容仍绘制插入符,保持焦点可见。
|
||||
const float caretX = rect.X + 6.0f * scale;
|
||||
UiDrawLine(g, caretX, rect.Y + 4.0f * scale, caretX, rect.Y + rect.Height - 4.0f * scale,
|
||||
theme.accent, 1.4f * scale);
|
||||
return;
|
||||
}
|
||||
|
||||
UiText(g, shown, font, rect, theme.textStrong, TextAlign::CENTER);
|
||||
const float innerLeft = rect.X + 6.0f * scale;
|
||||
const float innerWidth = std::max(4.0f, rect.Width - 12.0f * scale);
|
||||
|
||||
// 已开始键入:在文本末尾显示插入符。
|
||||
const float textWidth = UiTextWidth(g, shown, font);
|
||||
const float caretX = rect.X + (rect.Width + textWidth) * 0.5f + 1.0f * scale;
|
||||
if (caretX < rect.X + rect.Width - 2.0f * scale)
|
||||
// 光标与选区端点对应的像素位置(以文本左端为原点)。
|
||||
const float caretX = UiTextWidth(g, text.substr(0, edit.Caret()), font);
|
||||
const float selBeginX =
|
||||
edit.HasSelection() ? UiTextWidth(g, text.substr(0, edit.SelectionBegin()), font) : 0.0f;
|
||||
const float selEndX =
|
||||
edit.HasSelection() ? UiTextWidth(g, text.substr(0, edit.SelectionEnd()), font) : 0.0f;
|
||||
const float textWidth = UiTextWidth(g, text, font);
|
||||
|
||||
// 内容超出可视宽度时横向滚动,保证光标始终可见(向常规输入框靠齐)。
|
||||
float scroll = 0.0f;
|
||||
if (textWidth > innerWidth)
|
||||
{
|
||||
UiDrawLine(g, caretX, rect.Y + 4.0f * scale, caretX, rect.Y + rect.Height - 4.0f * scale,
|
||||
theme.accent, 1.4f * scale);
|
||||
if (caretX > innerWidth)
|
||||
{
|
||||
scroll = caretX - innerWidth;
|
||||
}
|
||||
const float maximum = textWidth - innerWidth;
|
||||
scroll = std::max(0.0f, std::min(scroll, maximum));
|
||||
}
|
||||
|
||||
const gd::RectF clipRect(innerLeft, rect.Y + 1.0f * scale, innerWidth, rect.Height - 2.0f * scale);
|
||||
const int saveState = g.Save();
|
||||
g.SetClip(clipRect, gd::CombineModeIntersect);
|
||||
|
||||
const float textLeft = innerLeft - scroll;
|
||||
|
||||
// 选区高亮绘制在文本之下,整段选中时呈现“已全选”观感。
|
||||
const bool fullSelection = edit.HasSelection() && edit.SelectionBegin() == 0 &&
|
||||
edit.SelectionEnd() == text.size();
|
||||
if (edit.HasSelection() && selEndX > selBeginX)
|
||||
{
|
||||
const gd::RectF highlight(textLeft + selBeginX, rect.Y + 3.0f * scale,
|
||||
selEndX - selBeginX, rect.Height - 6.0f * scale);
|
||||
UiFillRect(g, highlight, theme.accent);
|
||||
}
|
||||
|
||||
UiText(g, text, font, gd::RectF(textLeft, rect.Y, std::max(textWidth, innerWidth), rect.Height),
|
||||
theme.textStrong, TextAlign::LEFT);
|
||||
|
||||
if (edit.HasSelection() && !fullSelection && selEndX > selBeginX)
|
||||
{
|
||||
// 局部选区:在反白底衬上重绘被选中的片段,其余文字保持常规颜色。
|
||||
const std::wstring selected =
|
||||
text.substr(edit.SelectionBegin(), edit.SelectionEnd() - edit.SelectionBegin());
|
||||
UiText(g, selected, font,
|
||||
gd::RectF(textLeft + selBeginX, rect.Y, selEndX - selBeginX, rect.Height),
|
||||
theme.textOnAccent, TextAlign::LEFT);
|
||||
}
|
||||
else if (fullSelection)
|
||||
{
|
||||
UiText(g, text, font, gd::RectF(textLeft, rect.Y, std::max(textWidth, innerWidth), rect.Height),
|
||||
theme.textOnAccent, TextAlign::LEFT);
|
||||
}
|
||||
|
||||
// 插入符。
|
||||
const float caretDrawX = textLeft + caretX;
|
||||
UiDrawLine(g, caretDrawX, rect.Y + 4.0f * scale, caretDrawX, rect.Y + rect.Height - 4.0f * scale,
|
||||
theme.textStrong, 1.4f * scale);
|
||||
|
||||
g.Restore(saveState);
|
||||
}
|
||||
|
||||
bool UiSwatchNeedsOutline(float opacity)
|
||||
|
||||
Reference in new issue
Block a user