feat(UI): 布局边界改为四角粗/四边细包角 + 全元素覆盖 + 几何同源(RowRect O(1))
## 1. 边界观感:四角粗、四边细 用户反馈"边框就是实心矩形、粗细不一,效果不佳"。旧实现是四条等宽实心矩形 (层级 0 用 2px、其余 1px),同一元素的角与边粗细不一致,父子矩形共边时还会叠成更粗的一条。 新规则: - 四条边固定 1 设备像素(四条独立实心矩形;不用 DrawRectangle,笔宽奇偶会偏半像素); - 四个角额外加粗:层级 0 = 4px、其余 3px,沿水平/垂直各延伸 cornerLen(≤14px 且 ≤ 短边一半); - 层级 > 0 整体内缩 1px,父子矩形共边不再叠粗; - 绝不填充(几十层嵌套填充会把内容糊住); - 整像素对齐 + PixelOffsetModeNone + 关抗锯齿。 四角粗不只是观感:多条边重合时靠角的形状分辨层次(父=青蓝大包角、子=同位置品红小包角)。 ## 2. 协议:组件"收集 box",宿主统一绘制 UiComponent::CollectDebugBoxes(UiDebugBoxList&) 默认只登记 Area() UiWidget::CollectDebugBoxes(boxes, depth) 递归整棵控件树 Application::PaintLayoutBounds 收集后按 depth 升序一次性描边 刻意保持 box 为**值类型**而不是让它继承控件基类:PlotView 的 4 层位图缓存、 SignalPanel 的 192 槽行位图缓存都要求"绘制由组件自己负责",几何进继承体系会与 缓存键/失效体系打架。box 不参与绘制,因此能让绘制/命中/调试共用同一份几何。 ## 3. 覆盖补齐(此前大量元素被裹在外层单位里) - Toolbar:区域 / 每个按钮 / **按钮内容(文字或齿轮图标,新增 UiButtonWidget::ContentRect())** - TabBar:区域 / 标签条 / 新建按钮 / 每个 ✕ - SignalPanel:4 分区 + 筛选输入框/清空✕/全部显示 + 滚动轨道与滑块 + 样式区 5 行及其 12 色块/自定义/3 模式/3 调整/线宽与透明度轨道和数值 + 目标行/名称/GX 徽标 + **每个可见行**的折起三角/复选框/色块/名称/GX 徽标/✕ (组行另有组名/计数)+ 内联编辑框 - PlotView:区域 / 每个网格 / GX 徽标 / 装饰层矩形 / 图例托底+色块+文本 / **5 类浮动面板全部 20+ 字段**(标题/✕/折起三角/徽标/编辑行/按钮/内容区/滚动轨道与滑块 /透明度轨道与数值/两个开关/各行复选框与数值与滑轨与复位与名称与✕/分组栏/表头/固定点行) - PopupMenu:浮层 / 每个条目 / 可滚动可视区 / 轨道 / 滑块 / 二级子菜单与条目 - ColorPickerPopup:面板 / 标题 / 预览 / 色号 / 色域 / 色相条 / 3 条滑轨与数值 / 输入框 标签增加**尺寸门槛**(< 56×16 逻辑像素不画):复选框/色块/✕ 紧邻,逐个小框贴字会糊成一片。 ## 4. 设置按钮配色 + 齿轮图标 - ToolbarAction::SETTINGS 改为 primary = true,与「导入文件」同为强调色主按钮。 - 齿轮几何重做:齿占最外一圈(0.66R→1.0R)、外环中心线 0.54R/笔宽 0.24R、轴孔 0.17R。 旧版让齿从环中心线伸出,齿被环的描边吃掉 ⇒ 看起来只剩一个"甜甜圈"。 ## 5. 几何同源与性能 - RowRect(row) 原本每次调用都从头累加行高(O(row)),而画一行要调它 **5 次** (✕/徽标/名称/组计数/折起三角各一次)⇒ 200 行只见 30 行时每帧上万次加法, 命中测试(每次鼠标移动)同样走这条路。 新增 m_rowTop 前缀和(由 UpdateAnimGeometry() 统一重建)⇒ **O(1)**; 长度与行集合不一致时自动退回逐行累加(正确性优先)。 - ContentOffsetBeforeRow 同样改用前缀和。 - PanelBounds() 收敛 6 处重复的 (m_clientBounds.Width > 1.0f) ? m_clientBounds : m_area。 ## 6. 验证 - make release / make debug 零 error 零 warning;TargetCheck.exe 910,336 B(889 KiB < 900 KiB)。 - .preflight/lbcheck:21 / 21 PASS(含 bounds-off-restores-pixels:关闭后逐像素回到开启前)。 - Tools/rendercheck:「工具栏带以下」区域哈希 8/8 与上一轮**逐一相同** (证明本轮改动只落在工具栏带内);FUNC 断言 7/7 PASS。 - Tools/uicheck:69 passed / 0 failed。 ## 7. 文档 Documents/UI_Refactor_Plan.md / UI_Refactor_Progress.md / UI_Refactor_Report.md 追加第七阶段; Documents/agent_mem.md 同步变更日志与「2026-10-28 第九轮」硬规则与踩坑记录。
This commit is contained in:
1 parent
ab19a6e72e
commit
24706c906a
26 files changed
+1003
-163
No files matched your search
@@ -1,6 +1,7 @@
|
||||
#include "ColorPickerPopup.hpp"
|
||||
|
||||
#include "UiControls.hpp"
|
||||
#include "UiDebugBounds.hpp"
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
@@ -1093,4 +1094,33 @@ namespace jdi
|
||||
}
|
||||
}
|
||||
|
||||
void ColorPickerPopup::CollectDebugBoxes(UiDebugBoxList& boxes) const
|
||||
{
|
||||
if (!m_open)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// 层级 0:面板浮层整体。
|
||||
boxes.Add(m_rect, 0, L"picker");
|
||||
|
||||
// 层级 1:面板内部的固定控件。
|
||||
boxes.Add(m_titleRect, 1, L"title");
|
||||
boxes.Add(m_previewRect, 1);
|
||||
boxes.Add(m_hexRect, 1, L"hex");
|
||||
boxes.Add(m_gamutRect, 1, L"gamut");
|
||||
boxes.Add(m_hueRect, 1, L"hue");
|
||||
|
||||
// 层级 2:三条分量滑块的轨道与数值。
|
||||
for (const gd::RectF& track : m_tracks)
|
||||
{
|
||||
boxes.Add(track, 2, L"track");
|
||||
}
|
||||
for (const gd::RectF& value : m_values)
|
||||
{
|
||||
boxes.Add(value, 2);
|
||||
}
|
||||
|
||||
boxes.Add(EditFieldRect(), 2, L"edit");
|
||||
}
|
||||
} // namespace jdi
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "PopupMenuInternal.hpp"
|
||||
#include "UiControls.hpp"
|
||||
#include "UiDebugBounds.hpp"
|
||||
|
||||
namespace jdi
|
||||
{
|
||||
@@ -704,4 +705,32 @@ namespace jdi
|
||||
}
|
||||
|
||||
|
||||
void PopupMenu::CollectDebugBoxes(UiDebugBoxList& boxes) const
|
||||
{
|
||||
if (!m_open)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// 层级 0:菜单浮层整体。
|
||||
boxes.Add(m_rect, 0, L"menu");
|
||||
|
||||
// 层级 1:每个条目(含标题 / 分隔线 / 色块行,它们的矩形都已算好)。
|
||||
for (const gd::RectF& item : m_itemRects)
|
||||
{
|
||||
boxes.Add(item, 1);
|
||||
}
|
||||
|
||||
// 层级 1/2:可滚动菜单的可视区、轨道与滑块。
|
||||
boxes.Add(m_scrollViewport, 1, L"view");
|
||||
boxes.Add(m_scrollBarRect, 2, L"track");
|
||||
boxes.Add(ScrollBarThumbRect(), 2);
|
||||
|
||||
// 层级 0/1:二级子菜单。
|
||||
boxes.Add(m_subRect, 0, L"sub");
|
||||
for (const gd::RectF& item : m_subItemRects)
|
||||
{
|
||||
boxes.Add(item, 1);
|
||||
}
|
||||
}
|
||||
} // namespace jdi
|
||||
@@ -15,7 +15,7 @@ namespace jdi
|
||||
/** @brief 图标按钮的宽度(逻辑像素):与其他按钮同高、略窄。 */
|
||||
const float kIconButtonWidth = 40.0f;
|
||||
/** @brief 图标自身占用的边长(逻辑像素)。 */
|
||||
const float kIconSize = 18.0f;
|
||||
const float kIconSize = 20.0f;
|
||||
|
||||
/** @brief 按比例把一个颜色向目标色混合(与旧 Toolbar 的写法保持一致)。 */
|
||||
std::uint32_t BlendToward(std::uint32_t base, std::uint32_t target, double ratio)
|
||||
@@ -24,38 +24,42 @@ namespace jdi
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 画一个齿轮图标(矢量:8 个齿 + 外环 + 轴孔环)。
|
||||
* @brief 画一个齿轮图标(矢量:8 个齿 + 外环 + 轴孔)。
|
||||
*
|
||||
* 走 GDI+ 矢量而不是字体符号 `⚙`:该字符在不同回退字体里的大小与基线不一致,
|
||||
* 会出现"图标忽大忽小、垂直不居中"。抗锯齿保持开启(圆环/斜齿需要它才不难看)。
|
||||
*
|
||||
* 几何全部按「半径占 `half` 的比例」推导,因此任意 DPI 下形状一致:
|
||||
* 齿从环中心线(0.70)伸到最外圈(1.0),环描边宽度(0.30)刚好与齿根相接。
|
||||
* * 齿占**最外一圈**(0.66R → 1.0R),宽 0.30R —— 必须与外环外缘明显错开,
|
||||
* 否则齿会被环的描边吃掉,看起来只剩一个"甜甜圈";
|
||||
* * 外环中心线 0.54R、笔宽 0.24R(覆盖 0.42R~0.66R),与齿根恰好相接;
|
||||
* * 轴孔中心线 0.17R、笔宽 0.20R。
|
||||
*/
|
||||
void PaintGearIcon(gd::Graphics& g, const gd::RectF& rect, std::uint32_t argb)
|
||||
{
|
||||
const float cx = rect.X + rect.Width * 0.5f;
|
||||
const float cy = rect.Y + rect.Height * 0.5f;
|
||||
const float half = std::min(rect.Width, rect.Height) * 0.5f;
|
||||
if (half < 4.0f)
|
||||
if (half < 5.0f)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const float ringRadius = half * 0.70f; // 外环的中心线半径
|
||||
const float ringWidth = half * 0.30f; // 外环描边宽度(与齿根相接)
|
||||
const float toothWidth = half * 0.32f; // 齿宽
|
||||
const float hubRadius = half * 0.28f; // 轴孔中心线半径
|
||||
const float hubWidth = std::max(1.0f, half * 0.22f);
|
||||
const float toothInner = half * 0.66f; // 齿根半径(= 外环外缘)
|
||||
const float toothWidth = std::max(2.0f, half * 0.30f);
|
||||
const float ringRadius = half * 0.54f; // 外环中心线半径
|
||||
const float ringWidth = std::max(1.6f, half * 0.24f);
|
||||
const float hubRadius = half * 0.17f;
|
||||
const float hubWidth = std::max(1.4f, half * 0.20f);
|
||||
const gd::Color color(argb);
|
||||
|
||||
const gd::GraphicsState state = g.Save();
|
||||
g.SetSmoothingMode(gd::SmoothingModeAntiAlias);
|
||||
g.TranslateTransform(cx, cy);
|
||||
|
||||
// 齿:从环中心线向外伸到最外圈(`-half` 到 `-ringRadius`)。
|
||||
// 齿:从外环外缘一直伸到最外圈。
|
||||
gd::SolidBrush brush(color);
|
||||
const gd::RectF tooth(-toothWidth * 0.5f, -half, toothWidth, half - ringRadius);
|
||||
const gd::RectF tooth(-toothWidth * 0.5f, -half, toothWidth, half - toothInner);
|
||||
for (int index = 0; index < 8; ++index)
|
||||
{
|
||||
g.FillRectangle(&brush, tooth);
|
||||
@@ -63,8 +67,8 @@ namespace jdi
|
||||
}
|
||||
g.ResetTransform();
|
||||
|
||||
gd::Pen pen(color, ringWidth);
|
||||
g.DrawEllipse(&pen, cx - ringRadius, cy - ringRadius, ringRadius * 2.0f,
|
||||
gd::Pen ringPen(color, ringWidth);
|
||||
g.DrawEllipse(&ringPen, cx - ringRadius, cy - ringRadius, ringRadius * 2.0f,
|
||||
ringRadius * 2.0f);
|
||||
|
||||
gd::Pen hubPen(color, hubWidth);
|
||||
@@ -145,6 +149,30 @@ namespace jdi
|
||||
Invalidate(Bounds());
|
||||
}
|
||||
|
||||
gd::RectF UiButtonWidget::ContentRect() const
|
||||
{
|
||||
const gd::RectF& rect = Bounds();
|
||||
if (!(rect.Width > 0.0f) || !(rect.Height > 0.0f))
|
||||
{
|
||||
return gd::RectF();
|
||||
}
|
||||
|
||||
if (m_icon != UiButtonIcon::NONE)
|
||||
{
|
||||
const float side = kIconSize * m_scale;
|
||||
return gd::RectF(rect.X + (rect.Width - side) * 0.5f,
|
||||
rect.Y + (rect.Height - side) * 0.5f, side, side);
|
||||
}
|
||||
|
||||
if (m_label.empty() || m_fonts == nullptr || m_fonts->ui == nullptr)
|
||||
{
|
||||
return gd::RectF();
|
||||
}
|
||||
const float textWidth = UiMeasureTextWidth(m_fonts->ui, m_label);
|
||||
return gd::RectF(rect.X + (rect.Width - textWidth) * 0.5f, rect.Y, textWidth,
|
||||
rect.Height);
|
||||
}
|
||||
|
||||
gd::SizeF UiButtonWidget::OnMeasure(const UiMeasureContext& ctx)
|
||||
{
|
||||
const float scale = (ctx.scale > 0.1f) ? ctx.scale : m_scale;
|
||||
|
||||
@@ -6,10 +6,10 @@ namespace jdi
|
||||
{
|
||||
|
||||
// 默认实现放在 .cpp 而不是头文件内联:`UiComponent.hpp` 是四个大组件都要包含的
|
||||
// 公共头,不应把 `UiDebugBounds.hpp`(GDI+ 绘制辅助)也拉进它们的编译单元。
|
||||
void UiComponent::PaintDebugBounds(gd::Graphics& g, float scale)
|
||||
// 公共头,不应把 `UiDebugBounds.hpp`(box 收集器)也拉进它们的编译单元。
|
||||
void UiComponent::CollectDebugBoxes(UiDebugBoxList& boxes)
|
||||
{
|
||||
UiDebugPaintBounds(g, Area(), 0, scale);
|
||||
boxes.Add(Area(), 0);
|
||||
}
|
||||
|
||||
} // namespace jdi
|
||||
@@ -1,22 +1,36 @@
|
||||
#include "UiDebugBounds.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
#include "PaintUtil.hpp"
|
||||
|
||||
namespace jdi
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
/** @brief 顶层组件区域的描边宽度(设备像素)。 */
|
||||
const int kAreaStroke = 2;
|
||||
/** @brief 内部控件 / 子块的描边宽度(设备像素)。 */
|
||||
const int kNodeStroke = 1;
|
||||
/** @brief 四条边的描边宽度(设备像素)。 */
|
||||
constexpr int kEdgeStroke = 1;
|
||||
/** @brief 层级 0 的包角粗细(设备像素)。 */
|
||||
constexpr int kAreaCornerThick = 4;
|
||||
/** @brief 层级 ≥1 的包角粗细(设备像素)。 */
|
||||
constexpr int kNodeCornerThick = 3;
|
||||
/** @brief 包角沿边延伸的长度上限(设备像素;小矩形按比例收缩)。 */
|
||||
constexpr int kCornerLenMax = 14;
|
||||
/** @brief 层级 > 0 的矩形内缩量(设备像素):避免与父矩形共边时叠成粗线。 */
|
||||
constexpr int kNestedInset = 1;
|
||||
|
||||
/** @brief 标签底衬的不透明度(保证文字在任何内容上都可读)。 */
|
||||
constexpr std::uint32_t kTagBackdrop = 0xD9101014u;
|
||||
/** @brief 标签文字颜色。 */
|
||||
constexpr std::uint32_t kTagInk = 0xFFFFFFFFu;
|
||||
|
||||
/**
|
||||
* @brief 用整数像素矩形填充(要求调用方已把像素偏移模式设为 `None`)。
|
||||
*
|
||||
* 走 GDI+ 而不是 `UiFillRect`:这里需要**精确的 1px 覆盖**,而 `UiFillRect` 的快
|
||||
* 路径按 `floor/ceil` 取整并可能转交 GDI,混进调试层会带来额外的状态切换开销。
|
||||
* 路径按 `floor/ceil` 取整并可能转交 GDI,混进调试层会带来额外状态切换开销。
|
||||
*/
|
||||
void FillPixels(gd::Graphics& g, int x, int y, int width, int height, std::uint32_t argb)
|
||||
{
|
||||
@@ -27,8 +41,70 @@ namespace jdi
|
||||
gd::SolidBrush brush{gd::Color(argb)};
|
||||
g.FillRectangle(&brush, x, y, width, height);
|
||||
}
|
||||
|
||||
/** @brief 一个已对齐到整像素、可直接填充的矩形。 */
|
||||
struct PixelRect
|
||||
{
|
||||
int left = 0;
|
||||
int top = 0;
|
||||
int right = -1;
|
||||
int bottom = -1;
|
||||
int Width() const { return right - left + 1; }
|
||||
int Height() const { return bottom - top + 1; }
|
||||
bool Valid() const { return right >= left && bottom >= top; }
|
||||
};
|
||||
|
||||
/** @brief 把逻辑矩形对齐到整像素(`inset` 先内缩,用于避免父子共边)。 */
|
||||
PixelRect AlignToPixels(const gd::RectF& rect, int inset)
|
||||
{
|
||||
const float shrink = static_cast<float>(inset);
|
||||
const float x = rect.X + shrink;
|
||||
const float y = rect.Y + shrink;
|
||||
const float width = rect.Width - shrink * 2.0f;
|
||||
const float height = rect.Height - shrink * 2.0f;
|
||||
if (!(width > 0.0f) || !(height > 0.0f))
|
||||
{
|
||||
return PixelRect();
|
||||
}
|
||||
|
||||
PixelRect out;
|
||||
out.left = static_cast<int>(std::lround(x));
|
||||
out.top = static_cast<int>(std::lround(y));
|
||||
out.right = static_cast<int>(std::lround(x + width)) - 1;
|
||||
out.bottom = static_cast<int>(std::lround(y + height)) - 1;
|
||||
if (out.right < out.left)
|
||||
{
|
||||
out.right = out.left;
|
||||
}
|
||||
if (out.bottom < out.top)
|
||||
{
|
||||
out.bottom = out.top;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void UiDebugBoxList::Add(const gd::RectF& rect, int depth, std::wstring tag)
|
||||
{
|
||||
if (!(rect.Width > 0.0f) || !(rect.Height > 0.0f))
|
||||
{
|
||||
return; // 空矩形(未布局 / 该元素当前不显示)不登记。
|
||||
}
|
||||
UiDebugBox box;
|
||||
box.rect = rect;
|
||||
box.depth = (depth < 0) ? 0 : depth;
|
||||
box.tag = std::move(tag);
|
||||
m_boxes.push_back(std::move(box));
|
||||
}
|
||||
|
||||
void UiDebugBoxList::AddAll(const std::vector<gd::RectF>& rects, int depth)
|
||||
{
|
||||
for (const gd::RectF& rect : rects)
|
||||
{
|
||||
Add(rect, depth);
|
||||
}
|
||||
}
|
||||
|
||||
std::uint32_t UiDebugBoundsColor(int depth)
|
||||
{
|
||||
// 与主题无关的固定配色:调试层必须"永远显眼",不能跟随用户主题变成接近底色。
|
||||
@@ -37,60 +113,116 @@ namespace jdi
|
||||
case 0:
|
||||
return 0xFF29B6F6u; // 青蓝:顶层组件区域
|
||||
case 1:
|
||||
return 0xFFE040FBu; // 品红:控件节点
|
||||
return 0xFFE040FBu; // 品红:组件内部的功能分区
|
||||
case 2:
|
||||
return 0xFFFFB300u; // 琥珀:内部子块
|
||||
return 0xFFFFB300u; // 琥珀:具体控件 / 行
|
||||
default:
|
||||
return 0xFF66BB6Au; // 绿:更深的子块
|
||||
return 0xFF66BB6Au; // 绿:更深的子块(复选框、文本、✕ …)
|
||||
}
|
||||
}
|
||||
|
||||
void UiDebugPaintBounds(gd::Graphics& g, const gd::RectF& rect, int depth, float scale)
|
||||
void UiDebugPaintBounds(gd::Graphics& g, const gd::RectF& rect, int depth)
|
||||
{
|
||||
(void)scale; // 线宽刻意不随 DPI 变化(见头文件说明),此参数保留以便将来做对齐细分。
|
||||
|
||||
if (!(rect.Width > 0.0f) || !(rect.Height > 0.0f))
|
||||
const int level = (depth < 0) ? 0 : depth;
|
||||
const int inset = (level > 0) ? kNestedInset : 0;
|
||||
const PixelRect pixels = AlignToPixels(rect, inset);
|
||||
if (!pixels.Valid())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// 对齐到整像素:把矩形四边四舍五入,保证 1px 描边正好压住一格像素。
|
||||
const int left = static_cast<int>(std::lround(rect.X));
|
||||
const int top = static_cast<int>(std::lround(rect.Y));
|
||||
int right = static_cast<int>(std::lround(rect.X + rect.Width)) - 1;
|
||||
int bottom = static_cast<int>(std::lround(rect.Y + rect.Height)) - 1;
|
||||
if (right < left)
|
||||
{
|
||||
right = left;
|
||||
}
|
||||
if (bottom < top)
|
||||
{
|
||||
bottom = top;
|
||||
}
|
||||
|
||||
const int width = right - left + 1;
|
||||
const int height = bottom - top + 1;
|
||||
const int level = (depth < 0) ? 0 : depth;
|
||||
const int width = pixels.Width();
|
||||
const int height = pixels.Height();
|
||||
const std::uint32_t color = UiDebugBoundsColor(level);
|
||||
const int stroke = (level == 0) ? kAreaStroke : kNodeStroke;
|
||||
const int cornerThick = std::min((level == 0) ? kAreaCornerThick : kNodeCornerThick,
|
||||
std::max(1, std::min(width, height)));
|
||||
// 包角沿边延伸的长度:默认 14px,但不超过短边的一半(否则四角会连成实线框)。
|
||||
const int cornerLen = std::max(cornerThick + 1,
|
||||
std::min(kCornerLenMax, std::max(1, std::min(width, height) / 2)));
|
||||
|
||||
const gd::GraphicsState state = g.Save();
|
||||
// 描边必须锐利:关抗锯齿 + 关半像素偏移,矩形已对齐整像素 ⇒ 1px 就是 1px。
|
||||
g.SetSmoothingMode(gd::SmoothingModeNone);
|
||||
g.SetPixelOffsetMode(gd::PixelOffsetModeNone);
|
||||
|
||||
// ⚠️ **只描边、不填充**(与 Android「Show layout bounds」一致):
|
||||
// 填充会在几十个嵌套矩形上层层叠加,把内容糊成一片,反而看不出真实边界。
|
||||
// (1) 四边:统一 1px,用实心矩形而不是 `DrawRectangle`
|
||||
// (后者会因笔宽奇偶而偏移半像素,且抗锯齿会糊成 2px)。
|
||||
FillPixels(g, pixels.left, pixels.top, width, kEdgeStroke, color); // 上
|
||||
FillPixels(g, pixels.left, pixels.bottom, width, kEdgeStroke, color); // 下
|
||||
FillPixels(g, pixels.left, pixels.top, kEdgeStroke, height, color); // 左
|
||||
FillPixels(g, pixels.right, pixels.top, kEdgeStroke, height, color); // 右
|
||||
|
||||
// 四条边(用实心矩形而不是 `DrawRectangle`:后者会因笔宽奇偶而偏移半像素)。
|
||||
const int thick = (stroke * 2 <= width) ? stroke : 1;
|
||||
const int thickY = (stroke * 2 <= height) ? stroke : 1;
|
||||
FillPixels(g, left, top, width, thickY, color); // 上
|
||||
FillPixels(g, left, bottom - thickY + 1, width, thickY, color); // 下
|
||||
FillPixels(g, left, top, thick, height, color); // 左
|
||||
FillPixels(g, right - thick + 1, top, thick, height, color); // 右
|
||||
// (2) 四个角:加粗成 ⌜ ⌝ ⌞ ⌟ 包角 —— 这是"一眼定位元素边界"的关键,
|
||||
// 即使多个矩形共边也能靠角的形状分辨层次。
|
||||
const int len = std::max(1, std::min(cornerLen, std::max(1, std::min(width, height))));
|
||||
const int thick = std::min(cornerThick, std::max(1, std::min(width, height)));
|
||||
// 左上
|
||||
FillPixels(g, pixels.left, pixels.top, len, thick, color);
|
||||
FillPixels(g, pixels.left, pixels.top, thick, len, color);
|
||||
// 右上
|
||||
FillPixels(g, pixels.right - len + 1, pixels.top, len, thick, color);
|
||||
FillPixels(g, pixels.right - thick + 1, pixels.top, thick, len, color);
|
||||
// 左下
|
||||
FillPixels(g, pixels.left, pixels.bottom - thick + 1, len, thick, color);
|
||||
FillPixels(g, pixels.left, pixels.bottom - len + 1, thick, len, color);
|
||||
// 右下
|
||||
FillPixels(g, pixels.right - len + 1, pixels.bottom - thick + 1, len, thick, color);
|
||||
FillPixels(g, pixels.right - thick + 1, pixels.bottom - len + 1, thick, len, color);
|
||||
|
||||
g.Restore(state);
|
||||
}
|
||||
|
||||
void UiDebugPaintBoxList(gd::Graphics& g, const UiDebugBoxList& boxes,
|
||||
const UiDebugPaintStyle& style)
|
||||
{
|
||||
if (boxes.Empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// 浅层先画、深层后画:深层的包角不会被父级的边盖住。
|
||||
std::vector<const UiDebugBox*> ordered;
|
||||
ordered.reserve(boxes.Count());
|
||||
for (const UiDebugBox& box : boxes.Items())
|
||||
{
|
||||
ordered.push_back(&box);
|
||||
}
|
||||
std::stable_sort(ordered.begin(), ordered.end(),
|
||||
[](const UiDebugBox* lhs, const UiDebugBox* rhs)
|
||||
{ return lhs->depth < rhs->depth; });
|
||||
|
||||
for (const UiDebugBox* box : ordered)
|
||||
{
|
||||
UiDebugPaintBounds(g, box->rect, box->depth);
|
||||
|
||||
if (box->tag.empty() || style.font == nullptr)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// ⚠️ **尺寸门槛**:只在"装得下标签"的矩形上画标签。
|
||||
// 复选框、色块、✕ 这类小方框彼此紧邻,每个都贴一条文字会连成一片糊字,
|
||||
// 反而看不出边界 —— 它们的归属靠包角形状与颜色层级就能分辨。
|
||||
const float scale = (style.scale > 0.1f) ? style.scale : 1.0f;
|
||||
if (box->rect.Width < 56.0f * scale || box->rect.Height < 16.0f * scale)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// 标签贴在**左上角内侧**,带深色底衬(内容可能很亮,白字直接压上去会看不清)。
|
||||
// ⚠️ GDI 文本不受 GDI+ 裁剪约束 ⇒ 用 `UiTextClipped` 明确给出裁剪矩形。
|
||||
const float textWidth = UiMeasureTextWidth(style.font, box->tag);
|
||||
const float padX = 3.0f * scale;
|
||||
const float padY = 1.0f * scale;
|
||||
const float height = std::round(15.0f * scale);
|
||||
const gd::RectF backdrop(box->rect.X + 2.0f * scale, box->rect.Y + 2.0f * scale,
|
||||
textWidth + padX * 2.0f, height);
|
||||
UiFillRect(g, backdrop, kTagBackdrop);
|
||||
|
||||
const gd::RectF text(backdrop.X + padX, backdrop.Y, textWidth,
|
||||
std::max(1.0f, backdrop.Height - padY * 2.0f));
|
||||
UiTextClipped(g, box->tag, style.font, text, kTagInk, TextAlign::LEFT, backdrop);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace jdi
|
||||
@@ -255,7 +255,7 @@ namespace jdi
|
||||
return UiRectHasArea(TakeDirty());
|
||||
}
|
||||
|
||||
void UiWidget::PaintDebugBounds(gd::Graphics& g, float scale, int depth) const
|
||||
void UiWidget::CollectDebugBoxes(UiDebugBoxList& boxes, int depth) const
|
||||
{
|
||||
if (!m_visible || !UiRectHasArea(m_bounds))
|
||||
{
|
||||
@@ -263,14 +263,14 @@ namespace jdi
|
||||
return;
|
||||
}
|
||||
|
||||
UiDebugPaintBounds(g, m_bounds, depth, scale);
|
||||
boxes.Add(m_bounds, depth);
|
||||
|
||||
// 子节点按 z 序递归(末尾最上层)—— 与 `Paint` 的顺序一致,重叠时上层压住下层。
|
||||
for (const std::unique_ptr<UiWidget>& child : m_children)
|
||||
{
|
||||
if (child != nullptr)
|
||||
{
|
||||
child->PaintDebugBounds(g, scale, depth + 1);
|
||||
child->CollectDebugBoxes(boxes, depth + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user