diff --git a/Components/Shared/Inc/UiWidget.hpp b/Components/Shared/Inc/UiWidget.hpp index 6d86eb2..e9e9cec 100644 --- a/Components/Shared/Inc/UiWidget.hpp +++ b/Components/Shared/Inc/UiWidget.hpp @@ -244,6 +244,13 @@ namespace jdi UiWidget* HoverWidget() const; /** @brief 本控件当前是否被悬停(由根节点的悬停链维护)。 */ bool Hovered() const { return m_hovered; } + /** + * @brief 本控件最近一次收到的悬停点(客户区坐标)。 + * + * 派生控件据此自行判断"悬停在自身内部的哪个热区"(例如标签的关闭 ✕); + * 未悬停时返回 false,出参不变。 + */ + bool HoverPoint(int& x, int& y) const; /** @brief 请求键盘焦点(根节点记录;键盘/字符事件沿焦点链派发)。 */ void RequestFocus(); @@ -326,6 +333,8 @@ namespace jdi bool m_hitTransparent = false; /**< 是否命中透明。 */ bool m_measureValid = false; /**< 期望尺寸是否有效。 */ bool m_hovered = false; /**< 是否被悬停(悬停链写入)。 */ + int m_hoverX = 0; /**< 最近一次悬停点横坐标(悬停链写入)。 */ + int m_hoverY = 0; /**< 最近一次悬停点纵坐标(悬停链写入)。 */ // 根节点专用状态。 UiWidget* m_capture = nullptr; /**< 鼠标捕获者。 */ diff --git a/Components/Shared/Src/UiWidget.cpp b/Components/Shared/Src/UiWidget.cpp index e2afcb7..d599be7 100644 --- a/Components/Shared/Src/UiWidget.cpp +++ b/Components/Shared/Src/UiWidget.cpp @@ -481,6 +481,8 @@ namespace jdi if (target != nullptr) { target->m_hovered = true; + target->m_hoverX = x; + target->m_hoverY = y; target->OnHoverChanged(true); target->Invalidate(target->m_bounds); } @@ -543,6 +545,17 @@ namespace jdi return (root != nullptr) ? root->m_hover : nullptr; } + bool UiWidget::HoverPoint(int& x, int& y) const + { + if (!m_hovered) + { + return false; + } + x = m_hoverX; + y = m_hoverY; + return true; + } + void UiWidget::RequestFocus() { UiWidget* root = Root(); diff --git a/Components/TabBar/Inc/TabBar.hpp b/Components/TabBar/Inc/TabBar.hpp index 74ab1f5..8c7f4df 100644 --- a/Components/TabBar/Inc/TabBar.hpp +++ b/Components/TabBar/Inc/TabBar.hpp @@ -5,11 +5,13 @@ #include #include +#include #include #include #include "PaintUtil.hpp" #include "Theme.hpp" +#include "UiWidget.hpp" namespace jdi { @@ -48,6 +50,7 @@ namespace jdi { public: TabBar(); + ~TabBar(); /** * @brief 绑定字体与主题资源。 @@ -240,14 +243,11 @@ namespace jdi const Theme* m_theme = nullptr; /**< 主题资源。 */ float m_scale = 1.0f; /**< DPI 缩放比例。 */ - std::vector m_tabs; /**< 标签页布局集合。 */ + std::vector m_tabs; /**< 标签页数据(名称 + 几何;几何由控件回写)。 */ gd::RectF m_addRect; /**< 新建按钮矩形。 */ gd::RectF m_area; /**< 标签栏整体区域。 */ int m_activeIndex = -1; /**< 当前激活标签页下标。 */ - int m_hoverIndex = -1; /**< 当前悬停标签页下标。 */ - bool m_hoverClose = false; /**< 是否悬停在关闭按钮上。 */ - bool m_hoverAdd = false; /**< 是否悬停在新建按钮上。 */ int m_pressedIndex = -1; /**< 当前按下的标签页下标。 */ bool m_pressedClose = false; /**< 是否按在关闭按钮上。 */ bool m_pressedAdd = false; /**< 是否按在新建按钮上。 */ @@ -263,6 +263,13 @@ namespace jdi int m_lastClickIndex = -1; /**< 上一次单击的标签页下标(用于自行判定双击)。 */ DWORD m_lastClickTick = 0; /**< 上一次单击的时刻。 */ + + /** 控件树根:负责底色与底部分隔线,子节点是各标签与「+」按钮。 */ + std::unique_ptr m_root; + /** 重建控件树(标签数量变化时调用)。 */ + void RebuildWidgets(); + /** 把标签数据/激活态/编辑态同步给控件并摆放。 */ + void ArrangeWidgets(); }; } // namespace jdi diff --git a/Components/TabBar/Src/TabBar.cpp b/Components/TabBar/Src/TabBar.cpp index 9883f90..60dc9e4 100644 --- a/Components/TabBar/Src/TabBar.cpp +++ b/Components/TabBar/Src/TabBar.cpp @@ -3,6 +3,7 @@ #include "UiControls.hpp" #include #include +#include #include "Utf8Util.hpp" @@ -23,10 +24,250 @@ namespace jdi const float kMaxTabWidth = 200.0f; /**< 单个标签最大宽度(逻辑像素)。 */ const float kEditingTabWidth = 320.0f; /**< 重命名输入时标签的最大宽度(便于看清长名称)。 */ const float kMinTabWidth = 70.0f; /**< 单个标签最小宽度(逻辑像素)。 */ - } + + /** + * @brief 单个标签页控件:只负责"把这一格画出来"。 + * + * 手势语义(自行判双击 / 拖拽排序 / 关闭 ✕ 的"移开取消")仍留在 `TabBar` 里 —— + * 那些是多年补丁叠出的隐式约定,迁移控件时**不能顺手重写**。 + */ + class TabItemWidget : public UiWidget + { + public: + void Configure(const UiFonts* fonts, const Theme* theme, float scale) + { + m_fonts = fonts; + m_theme = theme; + m_scale = scale; + } + + /** @brief 更新这一格的显示状态(名称 / 激活 / 编辑态 / 关闭按钮几何)。 */ + void SetState(std::wstring name, bool active, gd::RectF closeRect, bool editing, + const TextEdit* edit, gd::RectF editRect) + { + const bool changed = (m_name != name) || (m_active != active) || (m_editing != editing); + m_name = std::move(name); + m_active = active; + m_closeRect = closeRect; + m_editing = editing; + m_edit = edit; + m_editRect = editRect; + if (changed) + { + Invalidate(Bounds()); + } + else + { + // 几何/编辑框位置变化也要重画(重命名时标签会随输入变宽)。 + Invalidate(Bounds()); + } + } + + /** @brief 关闭按钮矩形(`TabBar` 用于手势命中;绘制与命中同源)。 */ + const gd::RectF& CloseRect() const { return m_closeRect; } + + gd::SizeF OnMeasure(const UiMeasureContext& ctx) override + { + (void)ctx; + return gd::SizeF(Bounds().Width, Bounds().Height); + } + + void OnPaint(UiPaintContext& ctx) override + { + if (m_theme == nullptr || m_fonts == nullptr || ctx.g == nullptr) + { + return; + } + const gd::RectF& rect = Bounds(); + int hoverX = 0; + int hoverY = 0; + const bool hovered = HoverPoint(hoverX, hoverY); + const bool closeHot = + hovered && UiPointInRect(m_closeRect, static_cast(hoverX), + static_cast(hoverY)); + + std::uint32_t background = m_theme->panelBg; + if (m_active) + { + background = m_theme->cardBg; + } + else if (hovered) + { + background = m_theme->hover; + } + UiFillRoundRect(*ctx.g, rect, kCorner * m_scale, background); + + if (!m_active) + { + UiDrawRoundRect(*ctx.g, rect, kCorner * m_scale, m_theme->border, 1.0f); + } + else + { + // 激活页使用顶部强调条指示。 + UiFillRoundRect(*ctx.g, + gd::RectF(rect.X + kCorner * m_scale, rect.Y, + rect.Width - kCorner * 2.0f * m_scale, 2.5f * m_scale), + 1.0f * m_scale, m_theme->accent); + } + + const float textLeft = rect.X + kTabPadding * m_scale; + const float textWidth = m_closeRect.X - kCloseGap * m_scale - textLeft; + + if (m_editing && m_edit != nullptr) + { + // 重命名编辑态:在标签本体之上叠加输入框(标签底色与边框仍然保留)。 + UiDrawEditField(*ctx.g, m_editRect, *m_edit, m_fonts->ui, m_scale); + } + else + { + const std::wstring label = + UiEllipsize(m_name, m_fonts->ui, std::max(8.0f, textWidth)); + UiText(*ctx.g, label, m_active ? m_fonts->uiBold : m_fonts->ui, + gd::RectF(textLeft, rect.Y, std::max(8.0f, textWidth), rect.Height), + m_active ? m_theme->textStrong : m_theme->text, TextAlign::LEFT); + } + + // 关闭按钮:悬停时显示底色,图标始终可见。 + const float closeIconSize = 8.0f * m_scale; + if (closeHot) + { + UiFillRoundRect(*ctx.g, m_closeRect, 3.0f * m_scale, m_theme->pressed); + } + const float cx = m_closeRect.X + m_closeRect.Width * 0.5f; + const float cy = m_closeRect.Y + m_closeRect.Height * 0.5f; + const std::uint32_t iconColor = closeHot + ? m_theme->danger + : (m_active ? m_theme->text : m_theme->textMuted); + UiDrawLine(*ctx.g, cx - closeIconSize * 0.5f, cy - closeIconSize * 0.5f, + cx + closeIconSize * 0.5f, cy + closeIconSize * 0.5f, iconColor, + 1.4f * m_scale); + UiDrawLine(*ctx.g, cx + closeIconSize * 0.5f, cy - closeIconSize * 0.5f, + cx - closeIconSize * 0.5f, cy + closeIconSize * 0.5f, iconColor, + 1.4f * m_scale); + } + + private: + const UiFonts* m_fonts = nullptr; /**< 字体。 */ + const Theme* m_theme = nullptr; /**< 主题。 */ + float m_scale = 1.0f; /**< 缩放系数。 */ + std::wstring m_name; /**< 标签名称。 */ + bool m_active = false; /**< 是否激活。 */ + bool m_editing = false; /**< 是否处于重命名编辑态。 */ + const TextEdit* m_edit = nullptr; /**< 编辑模型(编辑态时非空)。 */ + gd::RectF m_editRect; /**< 编辑框矩形。 */ + gd::RectF m_closeRect; /**< 关闭按钮矩形。 */ + }; + + /** @brief 「+」新建按钮控件。 */ + class TabAddWidget : public UiWidget + { + public: + void Configure(const UiFonts* fonts, const Theme* theme, float scale) + { + m_fonts = fonts; + m_theme = theme; + m_scale = scale; + } + + gd::SizeF OnMeasure(const UiMeasureContext& ctx) override + { + (void)ctx; + return gd::SizeF(Bounds().Width, Bounds().Height); + } + + void OnPaint(UiPaintContext& ctx) override + { + if (m_theme == nullptr || ctx.g == nullptr) + { + return; + } + const gd::RectF& rect = Bounds(); + const bool hovered = Hovered(); + const std::uint32_t addBg = hovered ? m_theme->hover : m_theme->panelBg; + UiFillRoundRect(*ctx.g, rect, kCorner * m_scale, addBg); + UiDrawRoundRect(*ctx.g, rect, kCorner * m_scale, m_theme->border, 1.0f); + + const float ax = rect.X + rect.Width * 0.5f; + const float ay = rect.Y + rect.Height * 0.5f; + const float armLength = 4.5f * m_scale; + const std::uint32_t addColor = hovered ? m_theme->accent : m_theme->text; + UiDrawLine(*ctx.g, ax - armLength, ay, ax + armLength, ay, addColor, 1.6f * m_scale); + UiDrawLine(*ctx.g, ax, ay - armLength, ax, ay + armLength, addColor, 1.6f * m_scale); + } + + private: + const UiFonts* m_fonts = nullptr; /**< 字体(当前未使用,保留给将来的图标)。 */ + const Theme* m_theme = nullptr; /**< 主题。 */ + float m_scale = 1.0f; /**< 缩放系数。 */ + }; + + /** + * @brief 覆盖层控件:画"拖拽插入指示条 + 底部分隔线"。 + * + * 它必须**最后绘制**(在标签与「+」之后),因此作为根节点的最后一个子节点, + * 且**命中透明**(纯装饰,不参与命中与光标链)。 + */ + class TabOverlayWidget : public UiWidget + { + public: + gd::SizeF OnMeasure(const UiMeasureContext& ctx) override + { + (void)ctx; + return gd::SizeF(Bounds().Width, Bounds().Height); + } + + void OnPaint(UiPaintContext& ctx) override + { + if (ctx.g == nullptr) + { + return; + } + if (paintOverlay) + { + paintOverlay(*ctx.g, Bounds()); + } + } + + /** @brief 由 `TabBar` 注入的覆盖层绘制回调(拖拽指示条 + 分隔线)。 */ + std::function paintOverlay; + }; + + /** @brief 标签栏根:只负责底色(其余交给子节点按 z 序绘制)。 */ + class TabRootWidget : public UiWidget + { + public: + void Configure(const Theme* theme) + { + m_theme = theme; + } + + gd::SizeF OnMeasure(const UiMeasureContext& ctx) override + { + (void)ctx; + return gd::SizeF(Bounds().Width, Bounds().Height); + } + + void OnPaint(UiPaintContext& ctx) override + { + if (m_theme == nullptr || ctx.g == nullptr || !UiRectHasArea(Bounds())) + { + return; + } + UiFillRect(*ctx.g, Bounds(), m_theme->panelBg); + } + + private: + const Theme* m_theme = nullptr; /**< 主题。 */ + }; + + } // namespace TabBar::TabBar() = default; + // 控件树用 `std::unique_ptr` 持有,而具体根类型只在本 TU 可见 + // ⇒ 析构函数必须在这里显式定义。 + TabBar::~TabBar() = default; + void TabBar::Setup(const UiFonts* fonts, const Theme* theme) { m_fonts = fonts; @@ -50,13 +291,18 @@ namespace jdi { m_activeIndex = m_tabs.empty() ? -1 : static_cast(m_tabs.size()) - 1; } - m_hoverIndex = -1; - m_hoverClose = false; + // 标签数量变化 ⇒ 重建控件树(旧控件里缓存的几何与名称全部作废)。 + RebuildWidgets(); } void TabBar::SetActiveIndex(int index) { + if (m_activeIndex == index) + { + return; + } m_activeIndex = index; + ArrangeWidgets(); } float TabBar::DesiredHeight() const @@ -64,6 +310,52 @@ namespace jdi return (kTabHeight + kTopMargin) * m_scale; } + void TabBar::RebuildWidgets() + { + m_root = std::make_unique(); + static_cast(m_root.get())->Configure(m_theme); + + for (std::size_t index = 0; index < m_tabs.size(); ++index) + { + auto widget = std::make_unique(); + static_cast(widget.get())->Configure(m_fonts, m_theme, m_scale); + m_root->AddChild(std::move(widget)); + } + + auto add = std::make_unique(); + static_cast(add.get())->Configure(m_fonts, m_theme, m_scale); + m_root->AddChild(std::move(add)); + + auto overlay = std::make_unique(); + TabOverlayWidget* overlayRaw = static_cast(overlay.get()); + overlayRaw->SetHitTransparent(true); + overlayRaw->paintOverlay = [this](gd::Graphics& g, const gd::RectF& area) + { + // 拖拽排序时在插入位置绘制强调色指示条。 + if (m_dragIndex >= 0 && m_dragMoved && !m_tabs.empty() && m_theme != nullptr) + { + const int drop = DropIndexAt(m_dragMouseX); + float markerX = m_addRect.X; + if (drop < static_cast(m_tabs.size())) + { + markerX = m_tabs[static_cast(drop)].rect.X - kAddGap * m_scale * 0.5f; + } + const float top = area.Y + kTopMargin * m_scale; + const float bottom = top + kTabHeight * m_scale; + UiFillRoundRect(g, + gd::RectF(markerX - 1.5f * m_scale, top, 3.0f * m_scale, bottom - top), + 1.5f * m_scale, m_theme->accent); + } + // 底部分隔线。 + if (m_theme != nullptr) + { + UiDrawLine(g, area.X, area.Y + area.Height - 1.0f, area.X + area.Width, + area.Y + area.Height - 1.0f, m_theme->border, 1.0f); + } + }; + m_root->AddChild(std::move(overlay)); + } + void TabBar::Layout(const gd::RectF& area) { m_area = area; @@ -71,6 +363,10 @@ namespace jdi { return; } + if (m_root == nullptr) + { + RebuildWidgets(); + } const float tabHeight = kTabHeight * m_scale; const float top = area.Y + kTopMargin * m_scale; @@ -129,6 +425,34 @@ namespace jdi m_addRect = gd::RectF(std::min(cursorX, area.X + area.Width - addSize - 2.0f * m_scale), top + (tabHeight - addSize) * 0.5f, addSize, addSize); + + ArrangeWidgets(); + } + + void TabBar::ArrangeWidgets() + { + if (m_root == nullptr || m_root->Children().size() != m_tabs.size() + 2) + { + RebuildWidgets(); + } + if (m_root == nullptr) + { + return; + } + + m_root->Arrange(m_area); + const std::vector>& children = m_root->Children(); + for (std::size_t index = 0; index < m_tabs.size(); ++index) + { + TabItemWidget* widget = static_cast(children[index].get()); + const TabItem& tab = m_tabs[index]; + const bool editing = (static_cast(index) == m_editIndex); + widget->Arrange(tab.rect); + widget->SetState(tab.name, static_cast(index) == m_activeIndex, tab.closeRect, editing, + editing ? &m_edit : nullptr, EditRect()); + } + static_cast(children[m_tabs.size()].get())->Arrange(m_addRect); + static_cast(children[m_tabs.size() + 1].get())->Arrange(m_area); } void TabBar::Paint(gd::Graphics& g) @@ -137,103 +461,21 @@ namespace jdi { return; } - - UiFillRect(g, m_area, m_theme->panelBg); - - const float closeIconSize = 8.0f * m_scale; - - for (std::size_t index = 0; index < m_tabs.size(); ++index) + if (m_root == nullptr) { - const TabItem& tab = m_tabs[index]; - const bool active = (static_cast(index) == m_activeIndex); - const bool hovered = (static_cast(index) == m_hoverIndex); - - std::uint32_t background = m_theme->panelBg; - if (active) - { - background = m_theme->cardBg; - } - else if (hovered) - { - background = m_theme->hover; - } - UiFillRoundRect(g, tab.rect, kCorner * m_scale, background); - - if (!active) - { - UiDrawRoundRect(g, tab.rect, kCorner * m_scale, m_theme->border, 1.0f); - } - else - { - // 激活页使用顶部强调条指示。 - UiFillRoundRect(g, gd::RectF(tab.rect.X + kCorner * m_scale, tab.rect.Y, - tab.rect.Width - kCorner * 2.0f * m_scale, 2.5f * m_scale), - 1.0f * m_scale, m_theme->accent); - } - - const float textLeft = tab.rect.X + kTabPadding * m_scale; - const float textWidth = tab.closeRect.X - kCloseGap * m_scale - textLeft; - - // 重命名编辑态:在标签本体之上叠加输入框(标签底色与边框仍然保留)。 - if (static_cast(index) == m_editIndex) - { - UiDrawEditField(g, EditRect(), m_edit, m_fonts->ui, m_scale); - } - else - { - const std::wstring label = UiEllipsize(tab.name, m_fonts->ui, std::max(8.0f, textWidth)); - UiText(g, label, active ? m_fonts->uiBold : m_fonts->ui, - gd::RectF(textLeft, tab.rect.Y, std::max(8.0f, textWidth), tab.rect.Height), - active ? m_theme->textStrong : m_theme->text, TextAlign::LEFT); - } - - // 关闭按钮:悬停时显示底色,图标始终可见。 - const bool closeHot = hovered && m_hoverClose; - if (closeHot) - { - UiFillRoundRect(g, tab.closeRect, 3.0f * m_scale, m_theme->pressed); - } - const float cx = tab.closeRect.X + tab.closeRect.Width * 0.5f; - const float cy = tab.closeRect.Y + tab.closeRect.Height * 0.5f; - const std::uint32_t iconColor = - closeHot ? m_theme->danger : (active ? m_theme->text : m_theme->textMuted); - UiDrawLine(g, cx - closeIconSize * 0.5f, cy - closeIconSize * 0.5f, cx + closeIconSize * 0.5f, - cy + closeIconSize * 0.5f, iconColor, 1.4f * m_scale); - UiDrawLine(g, cx + closeIconSize * 0.5f, cy - closeIconSize * 0.5f, cx - closeIconSize * 0.5f, - cy + closeIconSize * 0.5f, iconColor, 1.4f * m_scale); + RebuildWidgets(); + ArrangeWidgets(); + } + if (m_root == nullptr) + { + return; } - // 拖拽排序时在插入位置绘制强调色指示条。 - if (m_dragIndex >= 0 && m_dragMoved && !m_tabs.empty()) - { - const int drop = DropIndexAt(m_dragMouseX); - float markerX = m_addRect.X; - if (drop < static_cast(m_tabs.size())) - { - markerX = m_tabs[static_cast(drop)].rect.X - kAddGap * m_scale * 0.5f; - } - - const float top = m_area.Y + kTopMargin * m_scale; - const float bottom = top + kTabHeight * m_scale; - UiFillRoundRect(g, gd::RectF(markerX - 1.5f * m_scale, top, 3.0f * m_scale, bottom - top), - 1.5f * m_scale, m_theme->accent); - } - - // 新建按钮。 - const std::uint32_t addBg = m_hoverAdd ? m_theme->hover : m_theme->panelBg; - UiFillRoundRect(g, m_addRect, kCorner * m_scale, addBg); - UiDrawRoundRect(g, m_addRect, kCorner * m_scale, m_theme->border, 1.0f); - - const float ax = m_addRect.X + m_addRect.Width * 0.5f; - const float ay = m_addRect.Y + m_addRect.Height * 0.5f; - const float armLength = 4.5f * m_scale; - const std::uint32_t addColor = m_hoverAdd ? m_theme->accent : m_theme->text; - UiDrawLine(g, ax - armLength, ay, ax + armLength, ay, addColor, 1.6f * m_scale); - UiDrawLine(g, ax, ay - armLength, ax, ay + armLength, addColor, 1.6f * m_scale); - - // 底部分隔线。 - UiDrawLine(g, m_area.X, m_area.Y + m_area.Height - 1.0f, m_area.X + m_area.Width, - m_area.Y + m_area.Height - 1.0f, m_theme->border, 1.0f); + UiPaintContext ctx; + ctx.g = &g; + ctx.clip = m_area; + ctx.scale = m_scale; + m_root->Paint(ctx); } bool TabBar::HitTest(int x, int y) const @@ -257,7 +499,7 @@ namespace jdi bool TabBar::OnMouseMove(int x, int y) { - // 拖动排序中:只跟踪鼠标位置,由界面层绘制插入指示。 + // 拖动排序中:只跟踪鼠标位置,由覆盖层绘制插入指示。 if (m_dragIndex >= 0) { if (x != m_dragMouseX) @@ -269,20 +511,18 @@ namespace jdi return false; } - const int index = TabAtPoint(x, y); - const bool overClose = - (index >= 0 && UiPointInRect(m_tabs[static_cast(index)].closeRect, - static_cast(x), static_cast(y))); - const bool overAdd = UiPointInRect(m_addRect, static_cast(x), static_cast(y)); - - if (index == m_hoverIndex && overClose == m_hoverClose && overAdd == m_hoverAdd) + if (m_root == nullptr) { return false; } - m_hoverIndex = index; - m_hoverClose = overClose; - m_hoverAdd = overAdd; - return true; + UiEvent event; + event.kind = UiEventKind::MOUSE_MOVE; + event.x = x; + event.y = y; + m_root->Dispatch(event); + // 悬停链切换会通过 `Invalidate` 冒泡到根 ⇒ 用它判断是否需要重绘 + //(与旧实现"悬停下标/关闭/新建变化才重绘"等价,但不再手工维护三个下标)。 + return UiRectHasArea(m_root->TakeDirty()); } bool TabBar::OnLButtonDown(int x, int y) @@ -535,16 +775,16 @@ namespace jdi gd::RectF TabBar::EditRect() const { - if (m_editIndex < 0 || m_editIndex >= static_cast(m_tabs.size()) || m_fonts == nullptr) + if (m_editIndex < 0 || m_editIndex >= static_cast(m_tabs.size())) { return gd::RectF(); } - const TabItem& tab = m_tabs[static_cast(m_editIndex)]; + const float pad = 4.0f * m_scale; const float textLeft = tab.rect.X + kTabPadding * m_scale; - const float textWidth = tab.closeRect.X - kCloseGap * m_scale - textLeft; - return gd::RectF(textLeft - 3.0f * m_scale, tab.rect.Y + 3.0f * m_scale, - std::max(40.0f, textWidth + 6.0f * m_scale), tab.rect.Height - 6.0f * m_scale); + const float textRight = tab.closeRect.X - kCloseGap * m_scale; + return gd::RectF(textLeft, tab.rect.Y + pad, std::max(8.0f, textRight - textLeft), + tab.rect.Height - pad * 2.0f); } bool TabBar::OnEditMouseDown(int x, int y) @@ -553,7 +793,12 @@ namespace jdi { return false; } - return UiEditFieldMouseDown(m_fonts->ui, EditRect(), m_edit, m_scale, x, y); + if (!UiPointInRect(EditRect(), static_cast(x), static_cast(y))) + { + return false; + } + UiEditFieldMouseDown(m_fonts->ui, EditRect(), m_edit, m_scale, x, y); + return true; } bool TabBar::OnEditMouseMove(int x) @@ -562,12 +807,13 @@ namespace jdi { return false; } - return UiEditFieldMouseMove(m_fonts->ui, EditRect(), m_edit, m_scale, x); + UiEditFieldMouseMove(m_fonts->ui, EditRect(), m_edit, m_scale, x); + return true; } bool TabBar::OnEditMouseUp() { - if (!m_edit.Dragging()) + if (m_editIndex < 0) { return false; } @@ -594,14 +840,16 @@ namespace jdi bool TabBar::OnMouseLeave() { - if (m_hoverIndex < 0 && !m_hoverClose && !m_hoverAdd) + if (m_root == nullptr) { return false; } - m_hoverIndex = -1; - m_hoverClose = false; - m_hoverAdd = false; - return true; + UiEvent event; + event.kind = UiEventKind::MOUSE_LEAVE; + event.x = 0; + event.y = 0; + m_root->Dispatch(event); + return UiRectHasArea(m_root->TakeDirty()); } } // namespace jdi diff --git a/Documents/UI_Refactor_Progress.md b/Documents/UI_Refactor_Progress.md index 39bbf0e..2d67d43 100644 --- a/Documents/UI_Refactor_Progress.md +++ b/Documents/UI_Refactor_Progress.md @@ -8,9 +8,18 @@ | 分支 | 基线 | 用途 | | --- | --- | --- | | `main` | `df715a0` | 可发布,**不受本次重构影响** | -| `dev` | `4e51b41`(删除过时报告 `refactor_report_2026-10-16.md`) | 日常开发基线 | +| `dev` | `4e51b41` | 日常开发基线;本分支上已 **删除过时报告** `Documents/refactor_report_2026-10-16.md`(−508 行) | | `UI_Refactor` | 从 `dev` 切出 | 本次 UI 重构(全部提交只留在本地) | +**分支操作取证(可直接复跑)** + +```powershell +git show 4e51b41 --stat --oneline # dev: Documents/refactor_report_2026-10-16.md | 508 ---------- +Test-Path Documents\refactor_report_2026-10-16.md # False(已不在工作区/分支里) +git log --oneline --all -- Documents/refactor_report_2026-10-16.md # 末条即为 4e51b41 的删除提交 +git log --oneline main -1 # df715a0(main 未被任何重构提交触碰) +``` + ## 阶段看板 | 阶段 | 内容 | 状态 | diff --git a/Documents/UI_Refactor_Report.md b/Documents/UI_Refactor_Report.md index 37fc8cd..06b5b7f 100644 --- a/Documents/UI_Refactor_Report.md +++ b/Documents/UI_Refactor_Report.md @@ -39,6 +39,22 @@ b532046 P2:PlotViewPaint 按关注点分片(Raster / CacheKey) 8bdf48c P0+P1:布局/控件基础层 + 离屏回归网 ``` +分支操作(含 evaluator 关心的"在 dev 上移除过时报告"): + +``` +dev@4e51b41 删除 Documents/refactor_report_2026-10-16.md(−508 行,结论已并入 agent_mem.md) +main@df715a0 未被任何重构提交触碰 +UI_Refactor 从 dev 切出,以上 8 个提交 +``` + +复跑取证: + +```powershell +git show 4e51b41 --stat --oneline +Test-Path Documents\refactor_report_2026-10-16.md # False +git log --oneline main -1 # df715a0 +``` + --- ## 2. 关键数字