分组折起热区与改名输入框修正 + 数据模型去冗余(单一名称)+ 新增 Components/Shared 组件 + 过时注释/命名大清理 + 二进制瘦身 25.6%
## 一、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 历史附录加“时效声明”。
This commit is contained in:
1 parent
5831a0ea0d
commit
0871eb0cba
22 files changed
+1268
-1010
No files matched your search
@@ -0,0 +1,403 @@
|
||||
// 通用 UI 控件:按钮图标 / 复选框 / 滑块 / 内联输入框 / 颜色样块 / 取值胶囊配色。
|
||||
//
|
||||
// 本文件属于 Components/Shared —— 这些控件被信号面板、绘图区、工具栏、浮动面板等
|
||||
// 多个功能组件复用,因此集中放在共享组件里,而不是散落在各自的实现文件中。
|
||||
// 依赖方向:Components/Shared -> Utilities(只用低层绘制原语,不反向依赖)。
|
||||
#include "UiControls.hpp"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace jdi
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
/** Swatch outline opacity threshold (shared with UiSwatchNeedsOutline). */
|
||||
const float kSwatchOutlineOpacity = 0.45f;
|
||||
}
|
||||
|
||||
void UiDrawPlusIcon(gd::Graphics& g, const gd::RectF& rect, std::uint32_t argb, float strokeWidth)
|
||||
{
|
||||
const float cx = rect.X + rect.Width * 0.5f;
|
||||
const float cy = rect.Y + rect.Height * 0.5f;
|
||||
const float arm = std::min(rect.Width, rect.Height) * 0.3f;
|
||||
UiDrawLine(g, cx - arm, cy, cx + arm, cy, argb, strokeWidth);
|
||||
UiDrawLine(g, cx, cy - arm, cx, cy + arm, argb, strokeWidth);
|
||||
}
|
||||
|
||||
void UiDrawCrossIcon(gd::Graphics& g, const gd::RectF& rect, std::uint32_t argb, float strokeWidth)
|
||||
{
|
||||
const float cx = rect.X + rect.Width * 0.5f;
|
||||
const float cy = rect.Y + rect.Height * 0.5f;
|
||||
const float arm = std::min(rect.Width, rect.Height) * 0.3f;
|
||||
UiDrawLine(g, cx - arm, cy - arm, cx + arm, cy + arm, argb, strokeWidth);
|
||||
UiDrawLine(g, cx + arm, cy - arm, cx - arm, cy + arm, argb, strokeWidth);
|
||||
}
|
||||
|
||||
void UiDrawTriangleIcon(gd::Graphics& g, const gd::RectF& rect, std::uint32_t argb, IconDirection direction)
|
||||
{
|
||||
const float cx = rect.X + rect.Width * 0.5f;
|
||||
const float cy = rect.Y + rect.Height * 0.5f;
|
||||
const float arm = std::min(rect.Width, rect.Height) * 0.28f;
|
||||
|
||||
gd::PointF points[3];
|
||||
switch (direction)
|
||||
{
|
||||
case IconDirection::LEFT:
|
||||
points[0] = gd::PointF(cx + arm * 0.7f, cy - arm);
|
||||
points[1] = gd::PointF(cx - arm * 0.7f, cy);
|
||||
points[2] = gd::PointF(cx + arm * 0.7f, cy + arm);
|
||||
break;
|
||||
case IconDirection::RIGHT:
|
||||
points[0] = gd::PointF(cx - arm * 0.7f, cy - arm);
|
||||
points[1] = gd::PointF(cx + arm * 0.7f, cy);
|
||||
points[2] = gd::PointF(cx - arm * 0.7f, cy + arm);
|
||||
break;
|
||||
case IconDirection::UP:
|
||||
points[0] = gd::PointF(cx - arm, cy + arm * 0.7f);
|
||||
points[1] = gd::PointF(cx, cy - arm * 0.7f);
|
||||
points[2] = gd::PointF(cx + arm, cy + arm * 0.7f);
|
||||
break;
|
||||
case IconDirection::DOWN:
|
||||
default:
|
||||
points[0] = gd::PointF(cx - arm, cy - arm * 0.7f);
|
||||
points[1] = gd::PointF(cx, cy + arm * 0.7f);
|
||||
points[2] = gd::PointF(cx + arm, cy - arm * 0.7f);
|
||||
break;
|
||||
}
|
||||
|
||||
gd::SolidBrush brush(ToGdiColor(argb));
|
||||
g.FillPolygon(&brush, points, 3);
|
||||
}
|
||||
|
||||
double UiSliderRatioFromX(const gd::RectF& trackRect, float x)
|
||||
{
|
||||
if (trackRect.Width <= 0.0f)
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
const double ratio = static_cast<double>(x - trackRect.X) / static_cast<double>(trackRect.Width);
|
||||
if (ratio < 0.0)
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
if (ratio > 1.0)
|
||||
{
|
||||
return 1.0;
|
||||
}
|
||||
return ratio;
|
||||
}
|
||||
double UiColorLuminance(std::uint32_t color)
|
||||
{
|
||||
const double r = static_cast<double>((color >> 16) & 0xFFu);
|
||||
const double g = static_cast<double>((color >> 8) & 0xFFu);
|
||||
const double b = static_cast<double>(color & 0xFFu);
|
||||
return (0.299 * r + 0.587 * g + 0.114 * b) / 255.0;
|
||||
}
|
||||
|
||||
UiInk UiContrastInk(std::uint32_t background)
|
||||
{
|
||||
// 极值文字/描边色(Solarized base3 / base02 / base03),亮度差很大,
|
||||
// 因此任意底色下文字与底色之间都有充足对比。
|
||||
const std::uint32_t kInkLight = 0xFFFDF6E3u;
|
||||
const std::uint32_t kInkDark = 0xFF073642u;
|
||||
const std::uint32_t kOutlineLight = 0xFFFDF6E3u;
|
||||
const std::uint32_t kOutlineDark = 0xFF002B36u;
|
||||
/** 向底色互补色混入的比例:线性响应信号配色,同时把对比度损失限制在 15% 以内。 */
|
||||
const double kTint = 0.15;
|
||||
|
||||
const double luminance = UiColorLuminance(background);
|
||||
// 底色越亮 → 文字越暗(取最大对比的一侧)。
|
||||
const bool darkText = (luminance >= 0.5);
|
||||
// 底色的互补色:相对亮度恰为 1 - 底色亮度。
|
||||
const std::uint32_t complement = 0xFF000000u | ((~background) & 0x00FFFFFFu);
|
||||
|
||||
UiInk ink;
|
||||
ink.text = MixColor(darkText ? kInkDark : kInkLight, complement, kTint);
|
||||
ink.text = WithAlpha(ink.text, 0xFFu);
|
||||
ink.outline = MixColor(darkText ? kOutlineLight : kOutlineDark, complement, kTint);
|
||||
ink.outline = WithAlpha(ink.outline, 0x99u);
|
||||
return ink;
|
||||
}
|
||||
void UiDrawCheckBox(gd::Graphics& g, const gd::RectF& rect, int state, float radius)
|
||||
{
|
||||
const Theme& theme = SolarizedLight();
|
||||
const float centerY = rect.Y + rect.Height * 0.5f;
|
||||
|
||||
if (state == 1)
|
||||
{
|
||||
UiFillRoundRect(g, rect, radius, theme.accent);
|
||||
gd::Pen pen(ToGdiColor(theme.textOnAccent), std::max(1.4f, rect.Height * 0.11f));
|
||||
pen.SetStartCap(gd::LineCapRound);
|
||||
pen.SetEndCap(gd::LineCapRound);
|
||||
g.DrawLine(&pen, rect.X + rect.Width * 0.22f, centerY, rect.X + rect.Width * 0.42f,
|
||||
rect.Y + rect.Height * 0.72f);
|
||||
g.DrawLine(&pen, rect.X + rect.Width * 0.42f, rect.Y + rect.Height * 0.72f,
|
||||
rect.X + rect.Width * 0.78f, rect.Y + rect.Height * 0.28f);
|
||||
}
|
||||
else if (state == 2)
|
||||
{
|
||||
UiFillRoundRect(g, rect, radius, theme.accentSoft);
|
||||
UiDrawRoundRect(g, rect, radius, theme.accent, 1.0f);
|
||||
UiFillRect(g, gd::RectF(rect.X + rect.Width * 0.22f, centerY - rect.Height * 0.08f,
|
||||
rect.Width * 0.56f, rect.Height * 0.16f),
|
||||
theme.accent);
|
||||
}
|
||||
else
|
||||
{
|
||||
UiFillRoundRect(g, rect, radius, theme.cardBg);
|
||||
UiDrawRoundRect(g, rect, radius, theme.borderStrong, 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
void UiDrawSlider(gd::Graphics& g, const gd::RectF& track, double ratio, std::uint32_t fillColor,
|
||||
bool active, float scale)
|
||||
{
|
||||
if (track.Width <= 0.0f || track.Height <= 0.0f)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (ratio < 0.0)
|
||||
{
|
||||
ratio = 0.0;
|
||||
}
|
||||
if (ratio > 1.0)
|
||||
{
|
||||
ratio = 1.0;
|
||||
}
|
||||
|
||||
const float radius = track.Height * 0.5f;
|
||||
UiFillRoundRect(g, track, radius, 0x2A657B83u);
|
||||
|
||||
// 已填充部分严格止于圆钮中心,最小值时不会留下超出圆钮的填充残留。
|
||||
const float fillWidth = static_cast<float>(ratio) * track.Width;
|
||||
if (fillWidth > 0.5f)
|
||||
{
|
||||
UiFillRoundRect(g, gd::RectF(track.X, track.Y, fillWidth, track.Height), radius, fillColor);
|
||||
}
|
||||
|
||||
const float knobRadius = radius + (active ? 2.5f * scale : 0.8f * scale);
|
||||
const float knobX = track.X + static_cast<float>(ratio) * track.Width;
|
||||
|
||||
gd::SolidBrush knob(ToGdiColor(0xFFFFFFFFu));
|
||||
gd::Pen knobPen(ToGdiColor(0xFF586E75u), 1.4f * scale);
|
||||
g.FillEllipse(&knob, knobX - knobRadius, track.Y + radius - knobRadius, knobRadius * 2.0f,
|
||||
knobRadius * 2.0f);
|
||||
g.DrawEllipse(&knobPen, knobX - knobRadius, track.Y + radius - knobRadius, knobRadius * 2.0f,
|
||||
knobRadius * 2.0f);
|
||||
}
|
||||
|
||||
float UiEditTextLeft(const gd::RectF& rect, const TextEdit& edit, HFONT font, float scale,
|
||||
float& innerWidth)
|
||||
{
|
||||
innerWidth = std::max(4.0f, rect.Width - 12.0f * scale);
|
||||
const float textLeft = rect.X + 6.0f * scale;
|
||||
|
||||
const std::wstring& text = edit.Text();
|
||||
if (text.empty())
|
||||
{
|
||||
return textLeft;
|
||||
}
|
||||
|
||||
const float textWidth = UiMeasureTextWidth(font, text);
|
||||
if (textWidth <= innerWidth)
|
||||
{
|
||||
return textLeft;
|
||||
}
|
||||
|
||||
// 保证插入符可见:插入符超出右边界时向左滚动,并夹到总可滚动范围内。
|
||||
const float caretX = UiMeasureTextWidth(font, text.substr(0, edit.Caret()));
|
||||
float scroll = 0.0f;
|
||||
if (caretX > innerWidth)
|
||||
{
|
||||
scroll = caretX - innerWidth;
|
||||
}
|
||||
const float maximum = textWidth - innerWidth;
|
||||
scroll = std::max(0.0f, std::min(scroll, maximum));
|
||||
return textLeft - scroll;
|
||||
}
|
||||
|
||||
std::size_t UiEditOffsetAt(HFONT font, const std::wstring& text, float localX)
|
||||
{
|
||||
if (text.empty() || font == nullptr)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (localX <= 0.0f)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 逐字符累加宽度,找到距离最近的字符边界(文本通常很短,线性扫描足够)。
|
||||
float previous = 0.0f;
|
||||
for (std::size_t index = 0; index < text.size(); ++index)
|
||||
{
|
||||
const float current = UiMeasureTextWidth(font, text.substr(0, index + 1));
|
||||
if (localX < current)
|
||||
{
|
||||
// 落在本字符的左半 → 取左边界,右半 → 取右边界。
|
||||
return (localX - previous <= current - localX) ? index : (index + 1);
|
||||
}
|
||||
previous = current;
|
||||
}
|
||||
return text.size();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const Theme& theme = SolarizedLight();
|
||||
const float corner = 3.0f * scale;
|
||||
|
||||
UiFillRoundRect(g, rect, corner, theme.cardBg);
|
||||
UiDrawRoundRect(g, rect, corner, theme.accent, 1.6f);
|
||||
|
||||
UiDrawEditFieldContent(g, rect, edit, font, scale);
|
||||
}
|
||||
|
||||
void UiDrawEditFieldContent(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)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const Theme& theme = SolarizedLight();
|
||||
const std::wstring& text = edit.Text();
|
||||
const float innerLeft = rect.X + 6.0f * scale;
|
||||
|
||||
float innerWidth = 0.0f;
|
||||
const float textLeft = UiEditTextLeft(rect, edit, font, scale, innerWidth);
|
||||
const gd::RectF clipRect(innerLeft, rect.Y + 1.0f * scale, innerWidth, rect.Height - 2.0f * scale);
|
||||
|
||||
if (text.empty())
|
||||
{
|
||||
// 空内容仍绘制插入符,保持焦点可见。
|
||||
UiDrawLine(g, textLeft, rect.Y + 4.0f * scale, textLeft, rect.Y + rect.Height - 4.0f * scale,
|
||||
theme.accent, 1.4f * scale);
|
||||
return;
|
||||
}
|
||||
|
||||
// 光标与选区端点对应的像素位置(以文本左端为原点)。
|
||||
const float caretX = UiMeasureTextWidth(font, text.substr(0, edit.Caret()));
|
||||
const float selBeginX =
|
||||
edit.HasSelection() ? UiMeasureTextWidth(font, text.substr(0, edit.SelectionBegin())) : 0.0f;
|
||||
const float selEndX =
|
||||
edit.HasSelection() ? UiMeasureTextWidth(font, text.substr(0, edit.SelectionEnd())) : 0.0f;
|
||||
|
||||
const bool fullSelection =
|
||||
edit.HasSelection() && edit.SelectionBegin() == 0 && edit.SelectionEnd() == text.size();
|
||||
|
||||
const int saveState = g.Save();
|
||||
g.SetClip(clipRect, gd::CombineModeIntersect);
|
||||
|
||||
// 选区高亮绘制在文本之下,整段选中时呈现“已全选”观感。
|
||||
// ⚠️ 这里**必须自己把矩形夹到内容区**:`UiFillRect` 对面积足够大的不透明矩形会走
|
||||
// GDI `FillRect` 快路径,而 GDI 绘制**不受 GDI+ 裁剪区约束**,长文本的全选高亮
|
||||
// (宽度等于整段文本宽度)因此会溢出到输入框之外。夹取之后矩形始终落在框内,
|
||||
// 既保留快路径又不越界。
|
||||
if (edit.HasSelection() && selEndX > selBeginX)
|
||||
{
|
||||
gd::RectF highlight(textLeft + selBeginX, rect.Y + 3.0f * scale, selEndX - selBeginX,
|
||||
rect.Height - 6.0f * scale);
|
||||
const float left = std::max(highlight.X, clipRect.X);
|
||||
const float right = std::min(highlight.X + highlight.Width, clipRect.X + clipRect.Width);
|
||||
const float top = std::max(highlight.Y, clipRect.Y);
|
||||
const float bottom = std::min(highlight.Y + highlight.Height, clipRect.Y + clipRect.Height);
|
||||
highlight = gd::RectF(left, top, right - left, bottom - top);
|
||||
UiFillRect(g, highlight, theme.accent);
|
||||
}
|
||||
|
||||
// 长文本用 ETO_CLIPPING 交给 GDI 裁剪,避免字符画到输入框之外。
|
||||
UiTextAtClipped(g, text, font, textLeft, rect,
|
||||
fullSelection ? theme.textOnAccent : theme.textStrong, clipRect);
|
||||
|
||||
if (!fullSelection && edit.HasSelection() && selEndX > selBeginX)
|
||||
{
|
||||
// 局部选区:在反白底衬上重绘被选中的片段,其余文字保持常规颜色。
|
||||
const std::wstring selected =
|
||||
text.substr(edit.SelectionBegin(), edit.SelectionEnd() - edit.SelectionBegin());
|
||||
UiTextAtClipped(g, selected, font, textLeft + selBeginX, rect, theme.textOnAccent, clipRect);
|
||||
}
|
||||
|
||||
// 插入符。
|
||||
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 UiEditFieldMouseDown(HFONT font, const gd::RectF& rect, TextEdit& edit, float scale, int x, int y)
|
||||
{
|
||||
if (!edit.Active() || font == nullptr || rect.Width <= 0.0f)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!UiPointInRect(rect, static_cast<float>(x), static_cast<float>(y)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// 用与绘制完全相同的布局函数换算文本起点,保证点哪儿光标就落在哪儿。
|
||||
float innerWidth = 0.0f;
|
||||
const float textLeft = UiEditTextLeft(rect, edit, font, scale, innerWidth);
|
||||
edit.BeginDrag(UiEditOffsetAt(font, edit.Text(), static_cast<float>(x) - textLeft));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UiEditFieldMouseMove(HFONT font, const gd::RectF& rect, TextEdit& edit, float scale, int x)
|
||||
{
|
||||
if (!edit.Active() || !edit.Dragging() || font == nullptr || rect.Width <= 0.0f)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
float innerWidth = 0.0f;
|
||||
const float textLeft = UiEditTextLeft(rect, edit, font, scale, innerWidth);
|
||||
return edit.UpdateDrag(UiEditOffsetAt(font, edit.Text(), static_cast<float>(x) - textLeft));
|
||||
}
|
||||
|
||||
bool UiSwatchNeedsOutline(float opacity)
|
||||
{
|
||||
return !(opacity >= kSwatchOutlineOpacity);
|
||||
}
|
||||
|
||||
std::uint32_t UiDrawSwatch(gd::Graphics& g, const gd::RectF& rect, std::uint32_t color, float opacity,
|
||||
float radius, float scale)
|
||||
{
|
||||
double alpha = static_cast<double>(opacity);
|
||||
if (!(alpha > 0.0))
|
||||
{
|
||||
alpha = 0.0;
|
||||
}
|
||||
if (alpha > 1.0)
|
||||
{
|
||||
alpha = 1.0;
|
||||
}
|
||||
|
||||
const std::uint32_t filled = WithAlpha(color, static_cast<unsigned int>(alpha * 255.0 + 0.5));
|
||||
if (rect.Width > 0.0f && rect.Height > 0.0f)
|
||||
{
|
||||
UiFillRoundRect(g, rect, radius, filled);
|
||||
|
||||
// 透明度过低时色块本身难以辨识,补充一圈描边以保持可读性;可见时不绘制描边。
|
||||
if (UiSwatchNeedsOutline(opacity))
|
||||
{
|
||||
UiDrawRoundRect(g, rect, radius, SolarizedLight().borderStrong,
|
||||
std::max(1.0f, scale));
|
||||
}
|
||||
}
|
||||
return filled;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
// namespace jdi
|
||||
|
||||
Reference in new issue
Block a user