面板/拾色器布局微调 + 修复“拖拽光标飞到视界边缘”(含根因与防复发)
一、样式区「系数/偏移」二级面板:两个偏移输入框等宽对齐 - 带说明文字的 EDIT 行原来各自按自己的文本长度 + 单位后缀算宽度,于是「时间轴」 (文本更长、还带 `s` 后缀)的输入框比「Y轴」宽一截。现在同一次排布里所有 带说明文字的输入框共用**同一个宽度**(取其中最大自然宽度,再按“给最宽的说明文字 留位 / 不超过内容区 3/4”夹取),因此「Y轴」与「时间轴」严格等宽、右边界对齐。 - 断言:两个输入框 126.0 / 126.0,右边界 277.8 / 277.8。 二、自定义颜色浮层(拾色器)的绘制与排版 - **圆角不再漏像素**:色域方块的位图与色相条的渐变填充都**裁剪进同一个圆角路径** (新增公开的 `UiBuildRoundRectPath`,与 `UiFillRoundRect` / `UiDrawRoundRect` 逐点同源),色相条的圆角与色域方块完全一致。以前填充是直角矩形,会在圆角描边之外 露出四个尖角(色域左下/右下本身就是接近黑色的极值,看起来就是"角落里多出黑色像素点")。 - 色域位图改用 `WrapModeTileFlipXY` 贴图:插值不再采样到边界之外,边缘也不会被压暗。 - 色相条改用**一条带 7 个色标的线性渐变**画满(颜色与原来 6 段拼色一致), 顺带去掉段与段之间的接缝横线。 - RGB 三行:轨道**两侧间隙相等**(左:字母 ↔ 轨道;右:轨道 ↔ 数值区,共用同一常量), 数值区固定 **3 个字符宽**(与数字本身无关),三行轨道等长、同 x,R/G/B 字母与数值 都**右对齐**,因此三个字母、三列数字纵向对齐。 - 色号:固定 **6+1 个字符宽**,**右边界与三行数值的右边界对齐**(像素级验证:两者 最后一个字符同列);预览色块的长宽不变、左边界与轨道左边界对齐。 - 数值/色号正好 3 / 7 个字符宽,编辑态需要把文本区向外扩出输入框内边距,否则最后 一个字符会被输入框内边距裁掉(新增 `PaddedEditRect`,绘制、命中与插入符定位共用)。 三、修复“用选区放大把视界放大到某个临界点后,拖拽光标就飞到视界边缘” 两个独立原因,都属于“不变量只在某一个调用点维护”: 1. **吸附到采样点**没有边界检查:只要采样点间距 ≥6px 就吸附,而视界一旦比一个采样间隔还窄 (选区放大很容易做到),“最近的采样点”就落在视界之外,于是每一次鼠标移动都把光标 吸到视界外、再被夹回边缘 → 表现为光标“飞到视界边缘后跟不动鼠标”。现在吸附要求 视界内至少放得下 2 个采样点,且只接受**可见区间内**的采样点。 2. **选区放大没有最小跨度下限**:滚轮缩放有 `数据跨度 × 1e-9` 的下限,选区放大没有, 可以一直放大到视界宽度只有几个 double ULP。此时“像素 → 时间”的映射退化 (相邻像素映射到同一个 double),鼠标一动光标就跨几百像素。现在新增 `MinimumTimeSpan`(数据跨度 × 1e-9 与 `ULP(时间) × 画布宽度` 取大者)与 **视界的唯一写入口 `SetTimeView`**(拒绝非有限值、纠正左右颠倒、抬到下限之上、 再按数据范围收敛),滚轮缩放 / 选区放大 / 平移 / 适应视图 / 时间轴适应网格全部走它。 - 另新增**光标位置的唯一写入口 `PlaceCursorTime`**(拖拽光标必须经由此处): 拒绝非有限值 → 吸附(带上限与可见区间检查)→ 夹回可见区间。`XToTime` 也补上了 跨度退化时的兜底。 - ⚠️ 为什么会反复出现:这两个不变量(“视界必须仍然可表示/可用”“光标必须落在可见区间内、 且对应鼠标位置”)过去是**在每个调用点各自维护**的。后来加入的路径(选区放大、采样点吸附、 派生信号/偏移等新算子)各自绕过了其中一个环节,而故障只有在放大到极限时才可见, 于是每加一个新功能就可能复发一次。现在视界与光标各只有一个守门人,新功能必须经过它们。 四、离屏验证(窗口隐藏、不碰屏幕/鼠标/键盘) - 新增 [AQ]:视界比采样间隔还窄时拖光标必须跟随鼠标(修复前偏差 630px、直接贴边); 视界内采样点仍精确吸附;连续橡胶带放大不会再突破可分辨下限(停在 1e-9 数据跨度), 且在极限缩放下拖拽仍精确跟随(修复前 490px 偏差)。 - 新增 [AR]:色域方块与色相条四角之外不再有填充像素(角像素从填充色变为面板底色)、 两侧间隙相等、数值列 3 字符、色号 7 字符且与数值右边界同列(像素级)、预览色块左边界 与轨道左边界对齐、三条轨道等长同 x。 - [AP] 增加两个偏移输入框等宽/右对齐断言。 - ⚠️ 修正 harness 的一个**假通过**:`SetAllVisible(false)` 会清掉标签页的“视图已初始化”标记, 首次渲染的 `FitAll()` 会把测试设置的深缩放覆盖掉([Z]/[AI]/[AQ] 的“深缩放”其实一直在 整段数据上跑,所以这类回归能溜过去)。现在相关用例显式置位该标记,[Z]/[AI] 真正进入 深缩放;并补上用例间残留弹出菜单的隔离(面板停在窗口下半部会向上翻转盖住按钮, 吞掉下一个用例的首次点击)。 - 合计 669/669 通过(连续 4 次);`make release` 零警告(Target.exe 正在运行,链接待其关闭, 已用临时输出名验证链接自身成功)。
This commit is contained in:
1 parent
fc77b0262f
commit
940b8e67e6
8 files changed
+394
-127
No files matched your search
@@ -219,6 +219,17 @@ namespace jdi
|
||||
*/
|
||||
gd::RectF EditFieldRect() const;
|
||||
|
||||
/**
|
||||
* @brief 把“文本区矩形”扩成**编辑态输入框**矩形(向外扩出输入框的内边距)。
|
||||
*
|
||||
* ⚠️ 数值区正好 3 个字符宽、色号正好 6+1 个字符宽,若直接拿文本区当输入框,
|
||||
* 输入框内部的 6px 内边距会把最后一个字符裁掉。
|
||||
*
|
||||
* @param [IN] textRect 文本区矩形(数值区或色号区)。
|
||||
* @return 输入框矩形。
|
||||
*/
|
||||
gd::RectF PaddedEditRect(const gd::RectF& textRect) const;
|
||||
|
||||
/**
|
||||
* @brief 查询坐标命中的滑块下标。
|
||||
* @param [IN] x 客户区横坐标。
|
||||
@@ -227,6 +238,17 @@ namespace jdi
|
||||
*/
|
||||
int SliderAtPoint(int x, int y) const;
|
||||
|
||||
/**
|
||||
* @brief 计算通道标签(R/G/B)的矩形。
|
||||
*
|
||||
* 标签**右边界**到轨道左端的距离与轨道右端到数值区的距离相等
|
||||
* (用户要求:滑块两侧留白一致,三个字母纵向对齐)。
|
||||
*
|
||||
* @param [IN] index 通道下标(0=R,1=G,2=B)。
|
||||
* @return 标签矩形;下标非法时返回空矩形。
|
||||
*/
|
||||
gd::RectF ChannelLabelRect(int index) const;
|
||||
|
||||
/**
|
||||
* @brief 应用滑块拖拽位置到对应通道。
|
||||
* @param [IN] index 滑块下标。
|
||||
|
||||
@@ -115,6 +115,18 @@ namespace jdi
|
||||
*/
|
||||
void UiDrawRoundRect(gd::Graphics& g, const gd::RectF& rect, float radius, std::uint32_t argb, float width);
|
||||
|
||||
/**
|
||||
* @brief 构造圆角矩形路径(与 `UiFillRoundRect` / `UiDrawRoundRect` 使用完全相同的几何)。
|
||||
*
|
||||
* 需要把一张位图 / 渐变**裁剪进圆角形状**时使用:
|
||||
* `g.SetClip(&path)` 之后再填充,就不会在圆角之外漏出直角矩形的角。
|
||||
*
|
||||
* @param [IN,OUT] path 目标路径对象(不会被清空,直接追加)。
|
||||
* @param [IN] rect 目标矩形。
|
||||
* @param [IN] radius 圆角半径。
|
||||
*/
|
||||
void UiBuildRoundRectPath(gd::GraphicsPath& path, const gd::RectF& rect, float radius);
|
||||
|
||||
/**
|
||||
* @brief 绘制一条直线。
|
||||
* @param [IN,OUT] g 绘图上下文。
|
||||
|
||||
@@ -397,6 +397,14 @@ namespace jdi
|
||||
|
||||
gd::RectF m_rect; /**< 菜单整体矩形。 */
|
||||
std::vector<gd::RectF> m_itemRects; /**< 各项矩形。 */
|
||||
/**
|
||||
* 同一次排布中,**带说明文字的 EDIT 项**共用的输入框宽度(0 表示没有这类项)。
|
||||
*
|
||||
* 宽度取这些项里最宽的自然宽度,并在排布时按“不能挤掉说明文字 / 不超过内容区”夹好。
|
||||
* 同一面板内的输入框因此一样宽、右边界对齐(用户要求「Y轴」与「时间轴」等宽对齐,
|
||||
* 而不是各自按自己的文本长度自适应)。
|
||||
*/
|
||||
float m_editFieldWidth = 0.0f;
|
||||
std::vector<std::vector<gd::RectF>> m_swatchRects; /**< 各项内的色块矩形。 */
|
||||
|
||||
int m_hoverIndex = -1; /**< 当前悬停项。 */
|
||||
|
||||
@@ -20,8 +20,12 @@ namespace jdi
|
||||
const float kRowGap = 2.0f; /**< 滑块行间距。 */
|
||||
const float kPreviewHeight = 24.0f; /**< 预览行(预览色块 + 色号)高度。 */
|
||||
const float kLabelWidth = 16.0f; /**< 通道标签宽度。 */
|
||||
const float kLabelGap = 6.0f; /**< 标签与滑块间距。 */
|
||||
const float kValueWidth = 40.0f; /**< 数值文本宽度。 */
|
||||
/**
|
||||
* 滑块**两侧**的间隙(左:通道字母 ↔ 轨道;右:轨道 ↔ 数值区)。
|
||||
*
|
||||
* ⚠️ 必须共用同一个常量:用户明确要求轨道左右两侧的留白相等。
|
||||
*/
|
||||
const float kSliderGap = 8.0f;
|
||||
const float kTrackHeight = 8.0f; /**< 滑块轨道高度。 */
|
||||
const float kCorner = 6.0f; /**< 面板圆角半径。 */
|
||||
/** 色域方块 / 色相条 / 预览色块 / 色号框共用同一圆角(视觉上统一)。 */
|
||||
@@ -31,7 +35,7 @@ namespace jdi
|
||||
const float kGamutGap = 10.0f; /**< 色域方块与色相条间距。 */
|
||||
const float kColumnGap = 12.0f; /**< 色相条与滑块列间距。 */
|
||||
const float kSwatchWidth = 52.0f; /**< 预览色块宽度。 */
|
||||
const float kSwatchHexGap = 8.0f; /**< 预览色块与色号间距。 */
|
||||
const float kSwatchHexGap = 8.0f; /**< 预览色块与色号间距(下限,空间不足时以右对齐优先)。 */
|
||||
const float kGamutBorder = 1.0f; /**< 色域方块/色相条描边宽度。 */
|
||||
|
||||
/** @brief 通道显示名称。 */
|
||||
@@ -270,16 +274,29 @@ namespace jdi
|
||||
const float previewRowGap =
|
||||
std::max(0.0f, kGamutSize - kPreviewHeight - (kRowHeight * 3.0f + kRowGap * 2.0f)) * m_scale;
|
||||
|
||||
m_previewRect = gd::RectF(columnLeft, contentTop, kSwatchWidth * m_scale, kPreviewHeight * m_scale);
|
||||
m_hexRect = gd::RectF(m_previewRect.X + m_previewRect.Width + kSwatchHexGap * m_scale, contentTop,
|
||||
std::max(40.0f * m_scale,
|
||||
columnWidth - (kSwatchWidth + kSwatchHexGap) * m_scale),
|
||||
kPreviewHeight * m_scale);
|
||||
// 通道数值区固定占 **3 个字符宽**(0-255 最多三位):与数字本身的宽度无关,
|
||||
// 这样三行数值的右边界严格一致(右对齐后三列数字纵向对齐)。
|
||||
const float valueWidth =
|
||||
std::max(1.0f, UiMeasureTextWidth(m_fonts->monoSmall, L"000"));
|
||||
// 轨道两侧用**同一个**间隙(用户要求两侧留白相等)。
|
||||
const float sliderGap = kSliderGap * m_scale;
|
||||
const float labelWidth = kLabelWidth * m_scale;
|
||||
const float trackLeft = columnLeft + labelWidth + sliderGap;
|
||||
const float trackWidth = std::max(
|
||||
24.0f, columnWidth - (labelWidth + sliderGap + sliderGap + valueWidth));
|
||||
const float valueLeft = trackLeft + trackWidth + sliderGap;
|
||||
const float valueRight = valueLeft + valueWidth;
|
||||
|
||||
// 预览色块的**左边界与轨道左边界对齐**(长宽不变)。
|
||||
m_previewRect =
|
||||
gd::RectF(trackLeft, contentTop, kSwatchWidth * m_scale, kPreviewHeight * m_scale);
|
||||
// 色号 "#RRGGBB" 固定 **6+1 个字符宽**,并且**右边界与三行数值的右边界对齐**。
|
||||
const float hexWidth = UiMeasureTextWidth(m_fonts->monoSmall, L"#000000");
|
||||
const float hexLeft = std::max(m_previewRect.X + m_previewRect.Width + kSwatchHexGap * m_scale,
|
||||
valueRight - hexWidth);
|
||||
m_hexRect = gd::RectF(hexLeft, contentTop, valueRight - hexLeft, kPreviewHeight * m_scale);
|
||||
|
||||
const float sliderTop = m_previewRect.Y + m_previewRect.Height + previewRowGap;
|
||||
const float trackLeft = columnLeft + (kLabelWidth + kLabelGap) * m_scale;
|
||||
const float trackWidth =
|
||||
std::max(24.0f, columnWidth - (kLabelWidth + kLabelGap + kValueWidth + 6.0f) * m_scale);
|
||||
|
||||
for (int index = 0; index < 3; ++index)
|
||||
{
|
||||
@@ -288,8 +305,7 @@ namespace jdi
|
||||
gd::RectF(trackLeft, rowTop + (kRowHeight * m_scale - kTrackHeight * m_scale) * 0.5f,
|
||||
trackWidth, kTrackHeight * m_scale);
|
||||
m_values[static_cast<std::size_t>(index)] =
|
||||
gd::RectF(trackLeft + trackWidth + 6.0f * m_scale, rowTop, kValueWidth * m_scale,
|
||||
kRowHeight * m_scale);
|
||||
gd::RectF(valueLeft, rowTop, valueWidth, kRowHeight * m_scale);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -447,19 +463,42 @@ namespace jdi
|
||||
switch (m_editField)
|
||||
{
|
||||
case EditField::R:
|
||||
return m_values[0];
|
||||
return PaddedEditRect(m_values[0]);
|
||||
case EditField::G:
|
||||
return m_values[1];
|
||||
return PaddedEditRect(m_values[1]);
|
||||
case EditField::B:
|
||||
return m_values[2];
|
||||
return PaddedEditRect(m_values[2]);
|
||||
case EditField::HEX:
|
||||
return m_hexRect;
|
||||
return PaddedEditRect(m_hexRect);
|
||||
case EditField::NONE:
|
||||
default:
|
||||
return gd::RectF();
|
||||
}
|
||||
}
|
||||
|
||||
gd::RectF ColorPickerPopup::PaddedEditRect(const gd::RectF& textRect) const
|
||||
{
|
||||
// 与 `UiDrawEditField` 的内边距(6*scale)一致:文本区向外扩这么多,
|
||||
// 编辑态才能完整显示 3 位数值 / 7 位色号(否则最后一个字符被裁掉)。
|
||||
const float padding = 6.0f * m_scale;
|
||||
return gd::RectF(textRect.X - padding, textRect.Y, textRect.Width + padding * 2.0f,
|
||||
textRect.Height);
|
||||
}
|
||||
|
||||
gd::RectF ColorPickerPopup::ChannelLabelRect(int index) const
|
||||
{
|
||||
if (index < 0 || index >= 3)
|
||||
{
|
||||
return gd::RectF();
|
||||
}
|
||||
const std::size_t slot = static_cast<std::size_t>(index);
|
||||
const gd::RectF& track = m_tracks[slot];
|
||||
// 间隙直接由实际几何推出(轨道右端 → 数值区左端),因此标签侧与数值侧**必然**相等。
|
||||
const float gap = std::max(0.0f, m_values[slot].X - (track.X + track.Width));
|
||||
return gd::RectF(track.X - gap - kLabelWidth * m_scale, m_values[slot].Y,
|
||||
kLabelWidth * m_scale, kRowHeight * m_scale);
|
||||
}
|
||||
|
||||
bool ColorPickerPopup::BeginEdit(EditField field)
|
||||
{
|
||||
if (!m_open || field == EditField::NONE)
|
||||
@@ -796,16 +835,18 @@ namespace jdi
|
||||
}
|
||||
|
||||
// 数值与色号文本优先于滑块:两者几何重叠时要能进入输入状态。
|
||||
// 命中区用**编辑框**矩形(比 3 / 7 个字符宽的文本区宽出输入框内边距):
|
||||
// 文本区只有 3 个字符宽,命中区太小不便点击。
|
||||
for (int index = 0; index < 3; ++index)
|
||||
{
|
||||
if (UiPointInRect(m_values[static_cast<std::size_t>(index)], static_cast<float>(x),
|
||||
static_cast<float>(y)))
|
||||
if (UiPointInRect(PaddedEditRect(m_values[static_cast<std::size_t>(index)]),
|
||||
static_cast<float>(x), static_cast<float>(y)))
|
||||
{
|
||||
BeginEdit(static_cast<EditField>(index + 1));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (UiPointInRect(m_hexRect, static_cast<float>(x), static_cast<float>(y)))
|
||||
if (UiPointInRect(PaddedEditRect(m_hexRect), static_cast<float>(x), static_cast<float>(y)))
|
||||
{
|
||||
BeginEdit(EditField::HEX);
|
||||
return true;
|
||||
@@ -924,35 +965,57 @@ namespace jdi
|
||||
// ---- 色域方块(横轴饱和度、纵轴明度)----
|
||||
// 方块按当前色相预渲染到缓存位图里,避免每帧重画上百条渐变;
|
||||
// 色相变化时才重建一次。
|
||||
//
|
||||
// ⚠️ 填充必须**裁剪进圆角路径**里:
|
||||
// * 缓存的位图是直角矩形,直接贴上去会在四个角的多出来像素(用户报告的"角落里出现
|
||||
// 莫名其妙的黑色像素点"——方块左下/右下本身就是接近黑色的饱和/明度极值)。
|
||||
// * `WrapModeTileFlipXY` 让采样到边界之外的插值镜像取边,不再混入透明黑,
|
||||
// 边界也就不会再被"压暗"出一圈深色。
|
||||
if (EnsureGamutCache())
|
||||
{
|
||||
g.DrawImage(m_gamutCache.get(), m_gamutRect);
|
||||
gd::GraphicsPath gamutPath;
|
||||
UiBuildRoundRectPath(gamutPath, m_gamutRect, kSwatchCorner * m_scale);
|
||||
gd::ImageAttributes attributes;
|
||||
attributes.SetWrapMode(gd::WrapModeTileFlipXY, gd::Color(), FALSE);
|
||||
const int saveState = g.Save();
|
||||
g.SetClip(&gamutPath);
|
||||
g.DrawImage(m_gamutCache.get(), m_gamutRect, 0.0f, 0.0f,
|
||||
static_cast<gd::REAL>(m_gamutCacheSize),
|
||||
static_cast<gd::REAL>(m_gamutCacheSize), gd::UnitPixel, &attributes);
|
||||
g.Restore(saveState);
|
||||
}
|
||||
UiDrawRoundRect(g, m_gamutRect, kSwatchCorner * m_scale, m_theme->border, kGamutBorder);
|
||||
|
||||
// ---- 色相条(纵向 0-1):6 段线性渐变拼出完整色相环 ----
|
||||
// ---- 色相条(纵向 0-1)----
|
||||
{
|
||||
for (int segment = 0; segment < 6; ++segment)
|
||||
// 一条带 7 个色标的线性渐变画满整条(0、1/6 … 1,每段内 RGB 线性):
|
||||
// 与"6 段拼色"的颜色完全一致,但不会有段与段之间的接缝横线。
|
||||
gd::Color stops[7];
|
||||
gd::REAL positions[7];
|
||||
for (int index = 0; index < 7; ++index)
|
||||
{
|
||||
const double hue0 = static_cast<double>(segment) / 6.0;
|
||||
const double hue1 = static_cast<double>(segment + 1) / 6.0;
|
||||
const std::array<double, 3> rgb0 = FromHsv(hue0, 1.0, 1.0);
|
||||
const std::array<double, 3> rgb1 = FromHsv(hue1, 1.0, 1.0);
|
||||
const std::uint32_t color0 =
|
||||
0xFF000000u | (ToByte(rgb0[0]) << 16) | (ToByte(rgb0[1]) << 8) | ToByte(rgb0[2]);
|
||||
const std::uint32_t color1 =
|
||||
0xFF000000u | (ToByte(rgb1[0]) << 16) | (ToByte(rgb1[1]) << 8) | ToByte(rgb1[2]);
|
||||
|
||||
const float top = m_hueRect.Y + m_hueRect.Height * static_cast<float>(hue0);
|
||||
const float bottom = m_hueRect.Y + m_hueRect.Height * static_cast<float>(hue1);
|
||||
const gd::Point from(static_cast<INT>(std::lround(m_hueRect.X)),
|
||||
static_cast<INT>(std::lround(top)));
|
||||
const gd::Point to(static_cast<INT>(std::lround(m_hueRect.X)),
|
||||
static_cast<INT>(std::lround(bottom)));
|
||||
gd::LinearGradientBrush brush(from, to, ToGdiColor(color0), ToGdiColor(color1));
|
||||
// 渐变端点会各自向两侧延伸半段,逐段微重叠地填充即可无缝拼接。
|
||||
g.FillRectangle(&brush, m_hueRect.X, top, m_hueRect.Width, bottom - top);
|
||||
const double hue = static_cast<double>(index) / 6.0;
|
||||
const std::array<double, 3> rgb = FromHsv((hue > 1.0) ? 1.0 : hue, 1.0, 1.0);
|
||||
stops[index] = ToGdiColor(0xFF000000u | (ToByte(rgb[0]) << 16) | (ToByte(rgb[1]) << 8) |
|
||||
ToByte(rgb[2]));
|
||||
positions[index] = static_cast<gd::REAL>(static_cast<double>(index) / 6.0);
|
||||
}
|
||||
gd::LinearGradientBrush brush(
|
||||
gd::Point(static_cast<INT>(std::lround(m_hueRect.X)),
|
||||
static_cast<INT>(std::lround(m_hueRect.Y))),
|
||||
gd::Point(static_cast<INT>(std::lround(m_hueRect.X)),
|
||||
static_cast<INT>(std::lround(m_hueRect.Y + m_hueRect.Height))),
|
||||
stops[0], stops[6]);
|
||||
brush.SetInterpolationColors(stops, positions, 7);
|
||||
|
||||
// 与色域方块**共用同一个圆角**(`kSwatchCorner`),并且同样裁剪进圆角路径:
|
||||
// 直角填充会在圆角描边之外露出四个尖角(用户报告的"四个角的杂色像素点")。
|
||||
gd::GraphicsPath huePath;
|
||||
UiBuildRoundRectPath(huePath, m_hueRect, kSwatchCorner * m_scale);
|
||||
const int saveState = g.Save();
|
||||
g.SetClip(&huePath);
|
||||
g.FillRectangle(&brush, m_hueRect);
|
||||
g.Restore(saveState);
|
||||
UiDrawRoundRect(g, m_hueRect, kSwatchCorner * m_scale, m_theme->border, kGamutBorder);
|
||||
|
||||
// ---- 色域方块上的选点:中心就是当前选中的颜色,外面只加一圈白色描边 ----
|
||||
@@ -988,17 +1051,19 @@ namespace jdi
|
||||
const std::size_t slot = static_cast<std::size_t>(index);
|
||||
const gd::RectF& track = m_tracks[slot];
|
||||
|
||||
// 通道标签放在滑块同一行的左侧,与轨道/数值纵向对齐。
|
||||
const gd::RectF labelRect(track.X - (kLabelWidth + kLabelGap) * m_scale, m_values[slot].Y,
|
||||
kLabelWidth * m_scale, kRowHeight * m_scale);
|
||||
UiText(g, kChannelNames[index], m_fonts->uiSmall, labelRect, m_theme->textMuted, TextAlign::LEFT);
|
||||
// 通道标签放在滑块同一行的左侧,**右对齐**到"轨道左端 − 间隙":
|
||||
// 这样 R/G/B 三个字母的右边界与轨道的距离严格等于轨道到数值区的距离
|
||||
// (用户要求两侧留白相同,且三个字母纵向对齐)。
|
||||
const gd::RectF labelRect = ChannelLabelRect(index);
|
||||
UiText(g, kChannelNames[index], m_fonts->uiSmall, labelRect, m_theme->textMuted,
|
||||
TextAlign::RIGHT);
|
||||
|
||||
const bool active = (m_draggingSlider == index) || (m_hoverSlider == index);
|
||||
DrawChannelSlider(g, track, m_channels[slot], kChannelColors[index], active, m_scale);
|
||||
|
||||
if (m_editField == static_cast<EditField>(index + 1))
|
||||
{
|
||||
UiDrawEditField(g, m_values[slot], m_edit, m_fonts->monoSmall, m_scale);
|
||||
UiDrawEditField(g, PaddedEditRect(m_values[slot]), m_edit, m_fonts->monoSmall, m_scale);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1014,14 +1079,16 @@ namespace jdi
|
||||
|
||||
if (m_editField == EditField::HEX)
|
||||
{
|
||||
UiDrawEditField(g, m_hexRect, m_edit, m_fonts->monoSmall, m_scale);
|
||||
UiDrawEditField(g, PaddedEditRect(m_hexRect), m_edit, m_fonts->monoSmall, m_scale);
|
||||
}
|
||||
else
|
||||
{
|
||||
wchar_t buffer[16];
|
||||
swprintf(buffer, sizeof(buffer) / sizeof(buffer[0]), L"#%02X%02X%02X", (color >> 16) & 0xFFu,
|
||||
(color >> 8) & 0xFFu, color & 0xFFu);
|
||||
UiText(g, std::wstring(buffer), m_fonts->monoSmall, m_hexRect, m_theme->text, TextAlign::LEFT);
|
||||
// 与三行数值一样**右对齐**:色号的最后一位与数值的最后一位纵向对齐。
|
||||
UiText(g, std::wstring(buffer), m_fonts->monoSmall, m_hexRect, m_theme->text,
|
||||
TextAlign::RIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+37
-38
@@ -29,45 +29,44 @@ namespace jdi
|
||||
* 固定开销反而不划算,因此在阈值以下仍走 GDI+。
|
||||
*/
|
||||
const float kGdiFillAreaThreshold = 20000.0f;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 构造圆角矩形路径。
|
||||
* @param [IN,OUT] path 目标路径对象。
|
||||
* @param [IN] rect 目标矩形。
|
||||
* @param [IN] radius 圆角半径。
|
||||
*/
|
||||
void BuildRoundRectPath(gd::GraphicsPath& path, const gd::RectF& rect, float radius)
|
||||
// 圆角矩形路径是公开的几何构建器:`UiFillRoundRect` / `UiDrawRoundRect` / 需要把位图或渐变
|
||||
// **裁剪进同一个圆角形状**的调用方共用它,保证"填充的形状"与"描边的形状"逐点一致。
|
||||
void UiBuildRoundRectPath(gd::GraphicsPath& path, const gd::RectF& rect, float radius)
|
||||
{
|
||||
if (rect.Width <= 0.0f || rect.Height <= 0.0f)
|
||||
{
|
||||
if (rect.Width <= 0.0f || rect.Height <= 0.0f)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float diameter = radius * 2.0f;
|
||||
if (diameter > rect.Width)
|
||||
{
|
||||
diameter = rect.Width;
|
||||
}
|
||||
if (diameter > rect.Height)
|
||||
{
|
||||
diameter = rect.Height;
|
||||
}
|
||||
if (diameter < 1.0f)
|
||||
{
|
||||
path.AddRectangle(rect);
|
||||
return;
|
||||
}
|
||||
|
||||
const float right = rect.X + rect.Width;
|
||||
const float bottom = rect.Y + rect.Height;
|
||||
|
||||
path.AddArc(rect.X, rect.Y, diameter, diameter, 180.0f, 90.0f);
|
||||
path.AddArc(right - diameter, rect.Y, diameter, diameter, 270.0f, 90.0f);
|
||||
path.AddArc(right - diameter, bottom - diameter, diameter, diameter, 0.0f, 90.0f);
|
||||
path.AddArc(rect.X, bottom - diameter, diameter, diameter, 90.0f, 90.0f);
|
||||
path.CloseFigure();
|
||||
return;
|
||||
}
|
||||
|
||||
float diameter = radius * 2.0f;
|
||||
if (diameter > rect.Width)
|
||||
{
|
||||
diameter = rect.Width;
|
||||
}
|
||||
if (diameter > rect.Height)
|
||||
{
|
||||
diameter = rect.Height;
|
||||
}
|
||||
if (diameter < 1.0f)
|
||||
{
|
||||
path.AddRectangle(rect);
|
||||
return;
|
||||
}
|
||||
|
||||
const float right = rect.X + rect.Width;
|
||||
const float bottom = rect.Y + rect.Height;
|
||||
|
||||
path.AddArc(rect.X, rect.Y, diameter, diameter, 180.0f, 90.0f);
|
||||
path.AddArc(right - diameter, rect.Y, diameter, diameter, 270.0f, 90.0f);
|
||||
path.AddArc(right - diameter, bottom - diameter, diameter, diameter, 0.0f, 90.0f);
|
||||
path.AddArc(rect.X, bottom - diameter, diameter, diameter, 90.0f, 90.0f);
|
||||
path.CloseFigure();
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
/**
|
||||
* @brief 创建指定字号的界面字体。
|
||||
* @param [IN] face 字体名称。
|
||||
@@ -224,7 +223,7 @@ namespace jdi
|
||||
return;
|
||||
}
|
||||
gd::GraphicsPath path;
|
||||
BuildRoundRectPath(path, rect, radius);
|
||||
UiBuildRoundRectPath(path, rect, radius);
|
||||
gd::SolidBrush brush(ToGdiColor(argb));
|
||||
g.FillPath(&brush, &path);
|
||||
}
|
||||
@@ -236,7 +235,7 @@ namespace jdi
|
||||
return;
|
||||
}
|
||||
gd::GraphicsPath path;
|
||||
BuildRoundRectPath(path, rect, radius);
|
||||
UiBuildRoundRectPath(path, rect, radius);
|
||||
gd::Pen pen(ToGdiColor(argb), width);
|
||||
g.DrawPath(&pen, &path);
|
||||
}
|
||||
@@ -255,7 +254,7 @@ namespace jdi
|
||||
{
|
||||
continue;
|
||||
}
|
||||
BuildRoundRectPath(path, rect, radius);
|
||||
UiBuildRoundRectPath(path, rect, radius);
|
||||
}
|
||||
if (path.GetPointCount() > 0)
|
||||
{
|
||||
|
||||
@@ -169,6 +169,33 @@ namespace jdi
|
||||
const float width = contentWidth;
|
||||
const float height = totalHeight;
|
||||
|
||||
// 带说明文字的 EDIT 项共用**同一个输入框宽度**:取其中最大的自然宽度,
|
||||
// 再按“给最宽的说明文字留位 / 不超过内容区 3/4”夹取。
|
||||
// ⚠️ 若每项各自按自己的文本长度算,同一面板里就会出现一个宽一个窄
|
||||
// (时间轴行的文本更长、还带单位后缀,于是它的输入框比 Y 轴行宽一截)。
|
||||
float labeledFieldWidth = 0.0f;
|
||||
float widestLabel = 0.0f;
|
||||
for (const MenuItem& item : m_items)
|
||||
{
|
||||
if (item.kind != MenuItemKind::EDIT || item.label.empty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
labeledFieldWidth = std::max(labeledFieldWidth, NaturalEditFieldWidth(item));
|
||||
widestLabel = std::max(widestLabel,
|
||||
UiMeasureTextWidth(m_fonts->uiSmall, item.label) +
|
||||
kEditFieldGap * m_scale);
|
||||
}
|
||||
if (labeledFieldWidth > 0.0f)
|
||||
{
|
||||
const float rowContent =
|
||||
std::max(40.0f * m_scale, (width - 2.0f * (kPadH + kItemPad) * m_scale));
|
||||
const float limit = std::max(40.0f * m_scale,
|
||||
std::min(rowContent * 0.75f, rowContent - widestLabel));
|
||||
labeledFieldWidth = std::min(labeledFieldWidth, limit);
|
||||
}
|
||||
m_editFieldWidth = labeledFieldWidth;
|
||||
|
||||
float left = static_cast<float>(x);
|
||||
float top = static_cast<float>(y);
|
||||
|
||||
@@ -374,6 +401,8 @@ namespace jdi
|
||||
// 避免菜单被最大宽度夹取后输入框把左侧标签挤成省略号。
|
||||
// ⚠️ 说明文字为空(例如「系数调整」面板的整行输入框)时不设 3/4 上限,
|
||||
// 让输入框独占整行。
|
||||
// ⚠️ 带说明文字的项统一使用排布阶段算好的 `m_editFieldWidth`:
|
||||
// 同一面板里所有这类输入框必须一样宽、右边界对齐。
|
||||
const gd::RectF& rect = m_itemRects[static_cast<std::size_t>(index)];
|
||||
const float contentWidth = std::max(40.0f * m_scale, rect.Width - 2.0f * kItemPad * m_scale);
|
||||
const float labelWidth = UiMeasureTextWidth(m_fonts->uiSmall, item.label) + kEditFieldGap * m_scale;
|
||||
@@ -386,6 +415,11 @@ namespace jdi
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_editFieldWidth > 0.0f)
|
||||
{
|
||||
width = m_editFieldWidth;
|
||||
}
|
||||
width = std::min(width, std::max(40.0f * m_scale, contentWidth - labelWidth));
|
||||
width = std::min(width, contentWidth * 0.75f);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user