Files
Just-DataInspector/Components/Shared/Inc/Theme.hpp
T
DeepSeek V4.1 Flash 1e50494c41 修复列表内联编辑(组名/信号名)看不到插入符与选区;把 UI 基础层迁入 Components/Shared
1) 行位图缓存键漏了插入符与选区:信号列表整行走 PaintRowCached,RowCacheKey
   在编辑态只混合“是否编辑 + 文本” ⇒ 左右方向键与鼠标框选虽然改变了 TextEdit
   状态(caret/anchor),键却不变 ⇒ 贴回旧位图。表现就是“无法部分选择、
   鼠标框选无反应、光标不动”,而绘图区的光标时间输入(无行缓存)一直正常。
   修法:GROUP_TITLE / SIGNAL_NAME 两个分支编辑态把 Caret / SelectionBegin /
   SelectionEnd 一并 mix 进键;新增 SignalPanel::EditFieldFont() 统一
   绘制(uiSmall / ui)与鼠标命中、插入符换算所用字体。

2) Theme / PaintUtil / TextEdit / PopupMenu / ColorPickerPopup 由
   Utilities/{Inc,Src} git mv 到 Components/Shared/{Inc,Src}:
   Utilities 只保留纯数据/逻辑模块(DataModel、DataTable、各 *Loader、MatH5、
   Utf8Util),Shared 成为自洽的 UI 基础层(Theme → PaintUtil → UiControls →
   PopupMenu / ColorPickerPopup)。依赖方向仍是 Components → Shared → Utilities;
   PaintUtil 一并迁移是因为它依赖 Theme(否则构成 Utilities → Shared 反向依赖)。
   Makefile 无需改动(include 平铺,两个目录都已在搜索路径),但需清理 Build/*
   里对应的旧 .o/.d。

验证(全部离屏,不占用鼠标/键盘/屏幕):
- 新增 .preflight/editcheck 20/20;A/B 修复前 6 项如实失败(键不变 + 屏幕不重绘);
- 既有 .preflight/check 137/137;
- make release / make debug 零警告。
2026-10-19 11:11:31 +08:00

127 lines
3.9 KiB
C++

#ifndef __THEME_HPP__
#define __THEME_HPP__
#include <windows.h>
#include <objidl.h>
#include <gdiplus.h>
#include <cstdint>
/// @brief GDI+ 命名空间短别名,便于在界面代码中引用绘图类型。
namespace gd = Gdiplus;
namespace jdi
{
/**
* @brief 将 0xAARRGGBB 颜色值转换为 GDI+ 颜色对象。
* @param [IN] argb 颜色值。
* @return GDI+ 颜色对象。
*/
inline gd::Color ToGdiColor(std::uint32_t argb)
{
return gd::Color(static_cast<BYTE>((argb >> 24) & 0xFFu), static_cast<BYTE>((argb >> 16) & 0xFFu),
static_cast<BYTE>((argb >> 8) & 0xFFu), static_cast<BYTE>(argb & 0xFFu));
}
/**
* @brief 由 0xRRGGBB 构造不透明的 0xAARRGGBB 颜色值。
* @param [IN] rgb RGB 颜色值。
* @return 不透明颜色值。
*/
inline std::uint32_t MakeArgb(std::uint32_t rgb)
{
return 0xFF000000u | (rgb & 0x00FFFFFFu);
}
/**
* @brief 替换颜色值的 Alpha 通道。
* @param [IN] argb 原颜色值。
* @param [IN] alpha 新的 Alpha 值(0-255)。
* @return 新的颜色值。
*/
inline std::uint32_t WithAlpha(std::uint32_t argb, unsigned int alpha)
{
return (argb & 0x00FFFFFFu) | ((static_cast<std::uint32_t>(alpha) & 0xFFu) << 24);
}
/**
* @brief 在两个颜色之间做线性插值。
* @param [IN] fromColor 起始颜色。
* @param [IN] toColor 结束颜色。
* @param [IN] ratio 插值比例,0 返回起始色,1 返回结束色。
* @return 插值后的颜色值。
*/
inline std::uint32_t MixColor(std::uint32_t fromColor, std::uint32_t toColor, double ratio)
{
if (ratio < 0.0)
{
ratio = 0.0;
}
if (ratio > 1.0)
{
ratio = 1.0;
}
std::uint32_t result = 0;
for (int shift = 0; shift <= 24; shift += 8)
{
const double a = static_cast<double>((fromColor >> shift) & 0xFFu);
const double b = static_cast<double>((toColor >> shift) & 0xFFu);
const std::uint32_t mixed = static_cast<std::uint32_t>(a + (b - a) * ratio + 0.5);
result |= ((mixed & 0xFFu) << shift);
}
return result;
}
/**
* @brief 界面主题色板(Solarised Light 派生)。
*/
struct Theme
{
std::uint32_t windowBg = 0; /**< 窗口底色。 */
std::uint32_t toolbarBg = 0; /**< 顶部工具栏底色。 */
std::uint32_t panelBg = 0; /**< 侧边面板底色。 */
std::uint32_t cardBg = 0; /**< 面板内卡片底色。 */
std::uint32_t statusBg = 0; /**< 底部状态栏底色。 */
std::uint32_t plotBg = 0; /**< 绘图区底色。 */
std::uint32_t border = 0; /**< 常规描边色。 */
std::uint32_t borderStrong = 0; /**< 强调描边色。 */
std::uint32_t text = 0; /**< 正文文字色。 */
std::uint32_t textStrong = 0; /**< 强调文字色。 */
std::uint32_t textMuted = 0; /**< 次要文字色。 */
std::uint32_t textOnAccent = 0; /**< 强调色之上的文字色。 */
std::uint32_t accent = 0; /**< 主题强调色。 */
std::uint32_t accentSoft = 0; /**< 强调色的浅色版本。 */
std::uint32_t hover = 0; /**< 悬停底色。 */
std::uint32_t pressed = 0; /**< 按下底色。 */
std::uint32_t selection = 0; /**< 选中底色。 */
std::uint32_t gridWeak = 0; /**< 次级网格线颜色。 */
std::uint32_t gridStrong = 0; /**< 主要网格线颜色。 */
std::uint32_t axisLine = 0; /**< 坐标轴线颜色。 */
std::uint32_t cursor = 0; /**< 时间光标颜色(单/双光标共用同一样式)。 */
std::uint32_t readoutBg = 0; /**< 数值读数底色。 */
std::uint32_t danger = 0; /**< 警示色。 */
std::uint32_t warning = 0; /**< 提示色。 */
};
/**
* @brief 获取当前使用的主题(Solarised Light)。
* @return 主题常引用。
*/
const Theme& SolarizedLight();
/**
* @brief 获取波形默认配色表。
* @param [OUT] count 配色数量输出。
* @return 颜色数组首地址。
*/
const std::uint32_t* SignalPalette(int& count);
} // namespace jdi
#endif // __THEME_HPP__