Fix OnMouseLeave not firing

This commit is contained in:
Magnus Norddahl 2023-12-29 01:06:40 +01:00 committed by Christoph Oelckers
parent 945317ed64
commit 0b3d3966a6
2 changed files with 22 additions and 0 deletions

View file

@ -175,6 +175,7 @@ private:
std::unique_ptr<Canvas> DispCanvas;
Widget* FocusWidget = nullptr;
Widget* CaptureWidget = nullptr;
Widget* HoverWidget = nullptr;
Widget(const Widget&) = delete;
Widget& operator=(const Widget&) = delete;

View file

@ -75,6 +75,19 @@ void Widget::MoveBefore(Widget* sibling)
void Widget::DetachFromParent()
{
for (Widget* cur = ParentObj; cur; cur = cur->ParentObj)
{
if (cur->FocusWidget == this)
cur->FocusWidget = nullptr;
if (cur->CaptureWidget == this)
cur->CaptureWidget = nullptr;
if (cur->HoverWidget == this)
cur->HoverWidget = nullptr;
if (cur->DispWindow)
break;
}
if (PrevSiblingObj)
PrevSiblingObj->NextSiblingObj = NextSiblingObj;
if (NextSiblingObj)
@ -474,6 +487,14 @@ void Widget::OnWindowMouseMove(const Point& pos)
Widget* widget = ChildAt(pos);
if (!widget)
widget = this;
if (HoverWidget != widget)
{
if (HoverWidget)
HoverWidget->OnMouseLeave();
HoverWidget = widget;
}
widget->OnMouseMove(widget->MapFrom(this, pos));
}
}