fix: 修复网格徽标菜单与标签页编号,重构样式区并新增透明度与浮动拾色器
信号列表 - 网格徽标(G1/G2)改为在左键抬起时弹出菜单,修复此前「按住才显示、松手即消失」的问题。 - 文件分组行新增关闭按钮(✕),可直接从工作区移除文件,与右键菜单「关闭该文件」等价。 - 信号名改为完整保留文件内的列名原文,不再剥离 "[n]" 序号前缀与括号内容。 标签页 - 新建标签页改用「当前未被占用的最小编号」,关闭标签页后编号可被复用, 修复「开 3 关 2 再新建会变成视图 4」的问题。 样式编辑区(统一为固定四行网格布局,面板缩放时不再错位) - 移除顶部「样式 · 信号名 · 文件名」标题行,选中信号即为编辑对象。 - 绘制方式取消「阶梯」,标签由「方式」改为「样式」,仅保留线段 / 散点 / 点线。 - 线宽仅保留最细与最粗两个预设,中间改为带左右箭头的数值旋钮,单位为 px; 支持单击或双击数值框直接键入(首次键入替换原值,回车提交、Esc 取消、越界钳制到 0.5-6.0)。 - 颜色预设后新增与预设色块完全同尺寸、同外框样式的「加号」小方格, 点击后弹出浮动拾色面板(与 G1/G2 菜单同风格的浮动窗口),支持 RGB 三通道滑块、 实时预览与十六进制显示;点击面板外部即收起,取色实时应用到当前信号。 - 移除样式区末尾的网格选择控件,该功能统一由信号行的 G 徽标承载。 - 新增透明度滑块,默认 100%,可在 0-100% 之间调节,并实时反映到波形、 图例色块与信号行色块的显示效果。 其他 - 信号面板默认宽度与行内间距微调,使较长的列名可以完整显示。 - 失焦时提交线宽输入并收起浮动拾色器与弹出菜单。
This commit is contained in:
1 parent
eb868b2679
commit
729494d1ec
9 files changed
+1254
-471
No files matched your search
@@ -0,0 +1,161 @@
|
||||
#ifndef __COLOR_PICKER_POPUP_HPP__
|
||||
#define __COLOR_PICKER_POPUP_HPP__
|
||||
|
||||
#include <windows.h>
|
||||
#include <objidl.h>
|
||||
#include <gdiplus.h>
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
|
||||
#include "PaintUtil.hpp"
|
||||
#include "Theme.hpp"
|
||||
|
||||
namespace jdi
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief 浮动式 RGB 自定义颜色拾取器。
|
||||
*
|
||||
* 与弹出菜单一致,不创建独立窗口,而是作为宿主绘制的最后一步直接画到后备缓冲区,
|
||||
* 以浮动面板的形式出现在触发控件附近;取值变化实时生效,点击面板外部即收起。
|
||||
*/
|
||||
class ColorPickerPopup
|
||||
{
|
||||
public:
|
||||
ColorPickerPopup();
|
||||
|
||||
/**
|
||||
* @brief 绑定字体与主题资源。
|
||||
* @param [IN] fonts 字体集合,需在弹出面板生命周期内保持有效。
|
||||
* @param [IN] theme 主题配色,需在弹出面板生命周期内保持有效。
|
||||
*/
|
||||
void Setup(const UiFonts* fonts, const Theme* theme);
|
||||
|
||||
/**
|
||||
* @brief 设置 DPI 缩放比例。
|
||||
* @param [IN] scale 缩放比例(1.0 对应 96 DPI)。
|
||||
*/
|
||||
void SetScale(float scale);
|
||||
|
||||
/**
|
||||
* @brief 在指定位置打开拾色面板。
|
||||
* @param [IN] bounds 宿主客户区矩形,用于把面板限制在窗口内。
|
||||
* @param [IN] x 锚点横坐标(客户区坐标)。
|
||||
* @param [IN] y 锚点纵坐标(客户区坐标)。
|
||||
* @param [IN] color 初始颜色(0xAARRGGBB,仅取 RGB 分量)。
|
||||
*/
|
||||
void Open(const gd::RectF& bounds, int x, int y, std::uint32_t color);
|
||||
|
||||
/**
|
||||
* @brief 关闭拾色面板。
|
||||
*/
|
||||
void Close();
|
||||
|
||||
/**
|
||||
* @brief 判断拾色面板是否处于打开状态。
|
||||
* @return 打开返回 true。
|
||||
*/
|
||||
bool IsOpen() const { return m_open; }
|
||||
|
||||
/**
|
||||
* @brief 获取当前取色结果。
|
||||
* @return 0xAARRGGBB 颜色值(Alpha 固定为不透明)。
|
||||
*/
|
||||
std::uint32_t CurrentColor() const;
|
||||
|
||||
/**
|
||||
* @brief 取出并清除“取值已变化”标记。
|
||||
* @param [OUT] color 变化后的颜色。
|
||||
* @return 自上次调用以来取值发生过变化返回 true。
|
||||
*/
|
||||
bool TakeChanged(std::uint32_t& color);
|
||||
|
||||
/**
|
||||
* @brief 绘制拾色面板(应在宿主绘制的最后一步调用)。
|
||||
* @param [IN,OUT] g 绘图上下文。
|
||||
*/
|
||||
void Paint(gd::Graphics& g);
|
||||
|
||||
/**
|
||||
* @brief 处理鼠标移动(含滑块拖拽)。
|
||||
* @param [IN] x 客户区横坐标。
|
||||
* @param [IN] y 客户区纵坐标。
|
||||
* @return 需要重绘返回 true。
|
||||
*/
|
||||
bool OnMouseMove(int x, int y);
|
||||
|
||||
/**
|
||||
* @brief 处理鼠标左键按下。
|
||||
* @param [IN] x 客户区横坐标。
|
||||
* @param [IN] y 客户区纵坐标。
|
||||
* @return 事件已被消费返回 true。
|
||||
*/
|
||||
bool OnLButtonDown(int x, int y);
|
||||
|
||||
/**
|
||||
* @brief 处理鼠标左键抬起。
|
||||
* @return 需要重绘返回 true。
|
||||
*/
|
||||
bool OnLButtonUp();
|
||||
|
||||
/**
|
||||
* @brief 处理键盘按键(Esc 收起)。
|
||||
* @param [IN] key 虚拟键码。
|
||||
* @return 事件已被消费返回 true。
|
||||
*/
|
||||
bool OnKeyDown(WPARAM key);
|
||||
|
||||
/**
|
||||
* @brief 判断坐标是否落在拾色面板内部。
|
||||
* @param [IN] x 客户区横坐标。
|
||||
* @param [IN] y 客户区纵坐标。
|
||||
* @return 落在内部返回 true。
|
||||
*/
|
||||
bool ContainsPoint(int x, int y) const;
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief 依据锚点与客户区计算面板矩形与内部控件矩形。
|
||||
* @param [IN] bounds 宿主客户区矩形。
|
||||
* @param [IN] x 锚点横坐标。
|
||||
* @param [IN] y 锚点纵坐标。
|
||||
*/
|
||||
void BuildLayout(const gd::RectF& bounds, int x, int y);
|
||||
|
||||
/**
|
||||
* @brief 查询坐标命中的滑块下标。
|
||||
* @param [IN] x 客户区横坐标。
|
||||
* @param [IN] y 客户区纵坐标。
|
||||
* @return 滑块下标(0=R,1=G,2=B),未命中返回 -1。
|
||||
*/
|
||||
int SliderAtPoint(int x, int y) const;
|
||||
|
||||
/**
|
||||
* @brief 应用滑块拖拽位置到对应通道。
|
||||
* @param [IN] index 滑块下标。
|
||||
* @param [IN] x 客户区横坐标。
|
||||
*/
|
||||
void ApplySlider(int index, float x);
|
||||
|
||||
const UiFonts* m_fonts = nullptr; /**< 字体资源。 */
|
||||
const Theme* m_theme = nullptr; /**< 主题资源。 */
|
||||
float m_scale = 1.0f; /**< DPI 缩放比例。 */
|
||||
|
||||
bool m_open = false; /**< 是否处于打开状态。 */
|
||||
bool m_changed = false; /**< 取值是否发生变化。 */
|
||||
int m_draggingSlider = -1; /**< 正在拖拽的滑块下标,-1 表示未拖拽。 */
|
||||
int m_hoverSlider = -1; /**< 当前悬停的滑块下标。 */
|
||||
std::array<double, 3> m_channels = {0.0, 0.0, 0.0}; /**< RGB 分量(0-1)。 */
|
||||
|
||||
gd::RectF m_rect; /**< 面板整体矩形。 */
|
||||
gd::RectF m_titleRect; /**< 标题区域。 */
|
||||
std::array<gd::RectF, 3> m_tracks; /**< 滑块轨道矩形。 */
|
||||
std::array<gd::RectF, 3> m_values; /**< 数值文本矩形。 */
|
||||
gd::RectF m_previewRect; /**< 预览色块矩形。 */
|
||||
gd::RectF m_hexRect; /**< 十六进制文本矩形。 */
|
||||
};
|
||||
|
||||
} // namespace jdi
|
||||
|
||||
#endif // __COLOR_PICKER_POPUP_HPP__
|
||||
@@ -195,6 +195,7 @@ namespace jdi
|
||||
{
|
||||
bool visible = false; /**< 是否参与绘制。默认关闭,由用户自行勾选。 */
|
||||
std::uint32_t color = 0xFF268BD2; /**< 波形颜色,格式 0xAARRGGBB。 */
|
||||
float opacity = 1.0f; /**< 不透明度,取值 0.0-1.0,默认 1.0。 */
|
||||
float lineWidth = 1.6f; /**< 线宽(逻辑像素,未乘 DPI 缩放)。 */
|
||||
DrawMode mode = DrawMode::LINE; /**< 绘制方式。 */
|
||||
};
|
||||
|
||||
@@ -0,0 +1,347 @@
|
||||
#include "ColorPickerPopup.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
namespace jdi
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
const float kPanelWidth = 214.0f; /**< 面板宽度(逻辑像素)。 */
|
||||
const float kPadH = 12.0f; /**< 面板左右内边距。 */
|
||||
const float kPadV = 10.0f; /**< 面板上下内边距。 */
|
||||
const float kTitleHeight = 20.0f; /**< 标题行高度。 */
|
||||
const float kTitleGap = 8.0f; /**< 标题与滑块区间距。 */
|
||||
const float kRowHeight = 26.0f; /**< 单个滑块行高度。 */
|
||||
const float kRowGap = 2.0f; /**< 滑块行间距。 */
|
||||
const float kPreviewGap = 10.0f; /**< 滑块区与预览区间距。 */
|
||||
const float kPreviewHeight = 24.0f; /**< 预览行高度。 */
|
||||
const float kLabelWidth = 16.0f; /**< 通道标签宽度。 */
|
||||
const float kLabelGap = 6.0f; /**< 标签与滑块间距。 */
|
||||
const float kValueWidth = 40.0f; /**< 数值文本宽度。 */
|
||||
const float kTrackHeight = 6.0f; /**< 滑块轨道高度。 */
|
||||
const float kCorner = 6.0f; /**< 面板圆角半径。 */
|
||||
|
||||
/** @brief 通道显示名称。 */
|
||||
const wchar_t* kChannelNames[3] = {L"R", L"G", L"B"};
|
||||
|
||||
/** @brief 通道滑块填充色。 */
|
||||
const std::uint32_t kChannelColors[3] = {0xFFDC322Fu, 0xFF859900u, 0xFF268BD2u};
|
||||
|
||||
/**
|
||||
* @brief 绘制水平滑块(轨道 + 已填充部分 + 圆钮)。
|
||||
* @param [IN,OUT] g 绘图上下文。
|
||||
* @param [IN] track 轨道矩形。
|
||||
* @param [IN] ratio 当前值比例(0-1)。
|
||||
* @param [IN] fillColor 已填充部分颜色。
|
||||
* @param [IN] hovered 是否处于悬停或拖拽状态。
|
||||
* @param [IN] scale 缩放比例。
|
||||
*/
|
||||
void DrawChannelSlider(gd::Graphics& g, const gd::RectF& track, double ratio, std::uint32_t fillColor,
|
||||
bool hovered, float scale)
|
||||
{
|
||||
const float radius = track.Height * 0.5f;
|
||||
UiFillRoundRect(g, track, radius, 0x2A657B83u);
|
||||
|
||||
ratio = std::max(0.0, std::min(1.0, ratio));
|
||||
const float fillWidth = std::max(track.Height, static_cast<float>(ratio) * track.Width);
|
||||
UiFillRoundRect(g, gd::RectF(track.X, track.Y, fillWidth, track.Height), radius, fillColor);
|
||||
|
||||
const float knobX = track.X + static_cast<float>(ratio) * track.Width;
|
||||
const float knobRadius = radius + (hovered ? 2.5f * scale : 0.8f * scale);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 将 0-1 分量换算为 0-255 整数。
|
||||
* @param [IN] value 分量值。
|
||||
* @return 整数分量。
|
||||
*/
|
||||
unsigned int ToByte(double value)
|
||||
{
|
||||
const double scaled = value * 255.0 + 0.5;
|
||||
if (scaled < 0.0)
|
||||
{
|
||||
return 0u;
|
||||
}
|
||||
if (scaled > 255.0)
|
||||
{
|
||||
return 255u;
|
||||
}
|
||||
return static_cast<unsigned int>(scaled);
|
||||
}
|
||||
}
|
||||
|
||||
ColorPickerPopup::ColorPickerPopup() = default;
|
||||
|
||||
void ColorPickerPopup::Setup(const UiFonts* fonts, const Theme* theme)
|
||||
{
|
||||
m_fonts = fonts;
|
||||
m_theme = theme;
|
||||
}
|
||||
|
||||
void ColorPickerPopup::SetScale(float scale)
|
||||
{
|
||||
m_scale = (scale > 0.1f) ? scale : 1.0f;
|
||||
}
|
||||
|
||||
std::uint32_t ColorPickerPopup::CurrentColor() const
|
||||
{
|
||||
const unsigned int r = ToByte(m_channels[0]);
|
||||
const unsigned int g = ToByte(m_channels[1]);
|
||||
const unsigned int b = ToByte(m_channels[2]);
|
||||
return 0xFF000000u | (r << 16) | (g << 8) | b;
|
||||
}
|
||||
|
||||
bool ColorPickerPopup::TakeChanged(std::uint32_t& color)
|
||||
{
|
||||
if (!m_changed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
m_changed = false;
|
||||
color = CurrentColor();
|
||||
return true;
|
||||
}
|
||||
|
||||
void ColorPickerPopup::BuildLayout(const gd::RectF& bounds, int x, int y)
|
||||
{
|
||||
const float width = kPanelWidth * m_scale;
|
||||
const float height = (kPadV * 2.0f + kTitleHeight + kTitleGap + kRowHeight * 3.0f + kRowGap * 2.0f +
|
||||
kPreviewGap + kPreviewHeight) *
|
||||
m_scale;
|
||||
|
||||
float left = static_cast<float>(x);
|
||||
float top = static_cast<float>(y);
|
||||
|
||||
// 优先向右下展开;越界时翻转,最后做边界收敛。
|
||||
if (left + width > bounds.X + bounds.Width)
|
||||
{
|
||||
left = static_cast<float>(x) - width;
|
||||
}
|
||||
if (top + height > bounds.Y + bounds.Height)
|
||||
{
|
||||
top = static_cast<float>(y) - height;
|
||||
}
|
||||
left = std::max(bounds.X + 2.0f, std::min(left, bounds.X + bounds.Width - width - 2.0f));
|
||||
top = std::max(bounds.Y + 2.0f, std::min(top, bounds.Y + bounds.Height - height - 2.0f));
|
||||
|
||||
m_rect = gd::RectF(left, top, width, height);
|
||||
|
||||
m_titleRect = gd::RectF(left + kPadH * m_scale, top + kPadV * m_scale,
|
||||
width - kPadH * 2.0f * m_scale, kTitleHeight * m_scale);
|
||||
|
||||
const float trackLeft = left + (kPadH + kLabelWidth + kLabelGap) * m_scale;
|
||||
const float trackWidth =
|
||||
std::max(40.0f, width - (trackLeft - left) - (kPadH + kValueWidth) * m_scale);
|
||||
const float firstTop = m_titleRect.Y + m_titleRect.Height + kTitleGap * m_scale;
|
||||
|
||||
for (int index = 0; index < 3; ++index)
|
||||
{
|
||||
const float rowTop = firstTop + static_cast<float>(index) * (kRowHeight + kRowGap) * m_scale;
|
||||
m_tracks[static_cast<std::size_t>(index)] =
|
||||
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 - 6.0f * m_scale, kRowHeight * m_scale);
|
||||
}
|
||||
|
||||
const float previewTop = firstTop + 3.0f * (kRowHeight + kRowGap) * m_scale + kPreviewGap * m_scale;
|
||||
m_previewRect = gd::RectF(trackLeft, previewTop + 2.0f * m_scale, 52.0f * m_scale, 20.0f * m_scale);
|
||||
m_hexRect = gd::RectF(m_previewRect.X + m_previewRect.Width + 8.0f * m_scale, previewTop + 2.0f * m_scale,
|
||||
96.0f * m_scale, 20.0f * m_scale);
|
||||
}
|
||||
|
||||
void ColorPickerPopup::Open(const gd::RectF& bounds, int x, int y, std::uint32_t color)
|
||||
{
|
||||
m_channels[0] = static_cast<double>((color >> 16) & 0xFFu) / 255.0;
|
||||
m_channels[1] = static_cast<double>((color >> 8) & 0xFFu) / 255.0;
|
||||
m_channels[2] = static_cast<double>(color & 0xFFu) / 255.0;
|
||||
|
||||
m_open = true;
|
||||
m_changed = false;
|
||||
m_draggingSlider = -1;
|
||||
m_hoverSlider = -1;
|
||||
|
||||
BuildLayout(bounds, x, y);
|
||||
}
|
||||
|
||||
void ColorPickerPopup::Close()
|
||||
{
|
||||
m_open = false;
|
||||
m_draggingSlider = -1;
|
||||
m_hoverSlider = -1;
|
||||
}
|
||||
|
||||
bool ColorPickerPopup::ContainsPoint(int x, int y) const
|
||||
{
|
||||
if (!m_open)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return UiPointInRect(m_rect, static_cast<float>(x), static_cast<float>(y));
|
||||
}
|
||||
|
||||
int ColorPickerPopup::SliderAtPoint(int x, int y) const
|
||||
{
|
||||
if (!m_open)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
const float fx = static_cast<float>(x);
|
||||
const float fy = static_cast<float>(y);
|
||||
for (int index = 0; index < 3; ++index)
|
||||
{
|
||||
const gd::RectF& track = m_tracks[static_cast<std::size_t>(index)];
|
||||
// 命中范围在纵向适当放宽,便于拖拽。
|
||||
const gd::RectF hit(track.X - 4.0f * m_scale, track.Y - 9.0f * m_scale,
|
||||
track.Width + 8.0f * m_scale, track.Height + 18.0f * m_scale);
|
||||
if (UiPointInRect(hit, fx, fy))
|
||||
{
|
||||
return index;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void ColorPickerPopup::ApplySlider(int index, float x)
|
||||
{
|
||||
if (index < 0 || index >= 3)
|
||||
{
|
||||
return;
|
||||
}
|
||||
const std::size_t slot = static_cast<std::size_t>(index);
|
||||
const double ratio = UiSliderRatioFromX(m_tracks[slot], x);
|
||||
if (std::fabs(ratio - m_channels[slot]) < 1.0e-6)
|
||||
{
|
||||
return;
|
||||
}
|
||||
m_channels[slot] = ratio;
|
||||
m_changed = true;
|
||||
}
|
||||
|
||||
bool ColorPickerPopup::OnMouseMove(int x, int y)
|
||||
{
|
||||
if (!m_open)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_draggingSlider >= 0)
|
||||
{
|
||||
ApplySlider(m_draggingSlider, static_cast<float>(x));
|
||||
return true;
|
||||
}
|
||||
|
||||
const int hover = SliderAtPoint(x, y);
|
||||
if (hover == m_hoverSlider)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
m_hoverSlider = hover;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ColorPickerPopup::OnLButtonDown(int x, int y)
|
||||
{
|
||||
if (!m_open)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ContainsPoint(x, y))
|
||||
{
|
||||
// 点击面板外部:收起面板(外部点击不再下传,避免误触其他控件)。
|
||||
Close();
|
||||
return true;
|
||||
}
|
||||
|
||||
m_draggingSlider = SliderAtPoint(x, y);
|
||||
if (m_draggingSlider >= 0)
|
||||
{
|
||||
ApplySlider(m_draggingSlider, static_cast<float>(x));
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ColorPickerPopup::OnLButtonUp()
|
||||
{
|
||||
if (!m_open || m_draggingSlider < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
m_draggingSlider = -1;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ColorPickerPopup::OnKeyDown(WPARAM key)
|
||||
{
|
||||
if (!m_open)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (key == VK_ESCAPE)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ColorPickerPopup::Paint(gd::Graphics& g)
|
||||
{
|
||||
if (!m_open || m_theme == nullptr || m_fonts == nullptr || m_rect.Width <= 0.0f)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// 投影。
|
||||
UiFillRoundRect(g, gd::RectF(m_rect.X + 1.0f * m_scale, m_rect.Y + 2.0f * m_scale, m_rect.Width,
|
||||
m_rect.Height),
|
||||
kCorner * m_scale, 0x14000000u);
|
||||
UiFillRoundRect(g, gd::RectF(m_rect.X + 2.0f * m_scale, m_rect.Y + 4.0f * m_scale, m_rect.Width,
|
||||
m_rect.Height),
|
||||
kCorner * m_scale, 0x10000000u);
|
||||
|
||||
UiFillRoundRect(g, m_rect, kCorner * m_scale, m_theme->cardBg);
|
||||
UiDrawRoundRect(g, m_rect, kCorner * m_scale, m_theme->borderStrong, 1.0f);
|
||||
|
||||
UiText(g, L"自定义颜色", m_fonts->uiSmallBold, m_titleRect, m_theme->textMuted, TextAlign::LEFT);
|
||||
|
||||
for (int index = 0; index < 3; ++index)
|
||||
{
|
||||
const std::size_t slot = static_cast<std::size_t>(index);
|
||||
const gd::RectF& track = m_tracks[slot];
|
||||
|
||||
const gd::RectF labelRect(m_rect.X + kPadH * m_scale, track.Y - 9.0f * m_scale,
|
||||
kLabelWidth * m_scale, kRowHeight * m_scale);
|
||||
UiText(g, kChannelNames[index], m_fonts->uiSmall, labelRect, m_theme->textMuted, TextAlign::LEFT);
|
||||
|
||||
const bool active = (m_draggingSlider == index) || (m_hoverSlider == index);
|
||||
DrawChannelSlider(g, track, m_channels[slot], kChannelColors[index], active, m_scale);
|
||||
|
||||
UiText(g, std::to_wstring(ToByte(m_channels[slot])), m_fonts->monoSmall, m_values[slot],
|
||||
m_theme->text, TextAlign::RIGHT);
|
||||
}
|
||||
|
||||
// 预览与十六进制值。
|
||||
const std::uint32_t color = CurrentColor();
|
||||
UiFillRoundRect(g, m_previewRect, 3.0f * m_scale, color);
|
||||
UiDrawRoundRect(g, m_previewRect, 3.0f * m_scale, m_theme->borderStrong, 1.0f);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
} // namespace jdi
|
||||
@@ -37,44 +37,9 @@ namespace jdi
|
||||
return ContainsInsensitive(text, L"time") || ContainsInsensitive(text, L"时间");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 剥离列名中的 "[n]" 序号前缀,得到显示名称。
|
||||
* @param [IN] header 原始列名。
|
||||
* @return 显示名称。
|
||||
*/
|
||||
std::wstring MakeDisplayName(const std::wstring& header)
|
||||
{
|
||||
const std::wstring text = Trim(header);
|
||||
if (text.size() >= 3 && text[0] == L'[')
|
||||
{
|
||||
const std::size_t close = text.find(L']');
|
||||
if (close != std::wstring::npos && close > 1 && (close + 1) < text.size())
|
||||
{
|
||||
bool numeric = true;
|
||||
for (std::size_t i = 1; i < close; ++i)
|
||||
{
|
||||
if (!iswdigit(text[i]))
|
||||
{
|
||||
numeric = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (numeric)
|
||||
{
|
||||
const std::wstring rest = Trim(text.substr(close + 1));
|
||||
if (!rest.empty())
|
||||
{
|
||||
return rest;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return text.empty() ? header : text;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 从名称末尾的括号中提取单位(仅接受形如 mA / V / deg/s 的短标记)。
|
||||
* @param [IN] text 已剥离 "[n]" 前缀的名称。
|
||||
* @param [IN] text 列名(已去除首尾空白)。
|
||||
* @return 单位文本,无法识别时返回空字符串。
|
||||
*/
|
||||
std::wstring ExtractUnit(const std::wstring& text)
|
||||
@@ -109,46 +74,6 @@ namespace jdi
|
||||
return inner;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 从名称末尾移除已被识别为单位(或描述)的括号片段。
|
||||
* @param [IN] name 已剥离 "[n]" 前缀的名称。
|
||||
* @return 移除尾部括号后的名称(括号片段非单位时原样返回)。
|
||||
*/
|
||||
std::wstring StripBracketSuffix(const std::wstring& name)
|
||||
{
|
||||
if (name.size() < 3 || name.back() != L')')
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
const std::size_t open = name.rfind(L'(');
|
||||
if (open == std::wstring::npos || open == 0 || open + 2 >= name.size())
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
const std::wstring inner = Trim(name.substr(open + 1, name.size() - open - 2));
|
||||
if (inner.empty() || inner.size() > 10)
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
// 仅当括号内容为短单位标记时才剥离,避免误伤 "(5 Points)" 这类描述。
|
||||
for (const wchar_t c : inner)
|
||||
{
|
||||
const bool allowed = iswalpha(c) || iswdigit(c) || c == L'%' || c == L'/' || c == L'^' ||
|
||||
c == L'-' || c == L'.' || c == L'\u00B0' || c == L'\u00B5' ||
|
||||
c == L'\u03A9' || c == L'\u00B2' || c == L'\u00B3' || c == L'\u00B7';
|
||||
if (!allowed)
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
const std::wstring head = Trim(name.substr(0, open));
|
||||
return head.empty() ? name : head;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 依据全局信号序号从调色板取色,保证跨标签页配色一致。
|
||||
* @param [IN] globalIndex 全局信号序号。
|
||||
@@ -421,10 +346,9 @@ namespace jdi
|
||||
SignalData signal;
|
||||
signal.rawHeader = table.headers[column];
|
||||
{
|
||||
// 名称与单位分开保存:名称不再保留尾部单位括号,避免重复显示。
|
||||
const std::wstring baseName = MakeDisplayName(signal.rawHeader);
|
||||
signal.unit = ExtractUnit(baseName);
|
||||
signal.name = StripBracketSuffix(baseName);
|
||||
// 名称完整保留文件内的列名(含 "[n]" 序号与括号描述),仅用于展示不做改写。
|
||||
signal.name = Trim(signal.rawHeader);
|
||||
signal.unit = ExtractUnit(signal.name);
|
||||
}
|
||||
|
||||
signal.values.resize(rowCount);
|
||||
|
||||
Reference in new issue
Block a user