Browse Source

Debugger: Update hovered element when moving the mouse to an ancestor element

Michael Ragazzon 3 years ago
parent
commit
a9f016b5e0
2 changed files with 16 additions and 6 deletions
  1. 2 0
      Source/Debugger/DebuggerPlugin.cpp
  2. 14 6
      Source/Debugger/ElementInfo.cpp

+ 2 - 0
Source/Debugger/DebuggerPlugin.cpp

@@ -131,12 +131,14 @@ bool DebuggerPlugin::SetContext(Context* context)
 		{
 			debug_context->RemoveEventListener("click", info_element, true);
 			debug_context->RemoveEventListener("mouseover", info_element, true);
+			debug_context->RemoveEventListener("mouseout", info_element, true);
 		}
 
 		if (context)
 		{
 			context->AddEventListener("click", info_element, true);
 			context->AddEventListener("mouseover", info_element, true);
+			context->AddEventListener("mouseout", info_element, true);
 		}
 
 		info_element->Reset();

+ 14 - 6
Source/Debugger/ElementInfo.cpp

@@ -27,18 +27,19 @@
  */
 
 #include "ElementInfo.h"
+#include "../../Include/RmlUi/Core/Context.h"
 #include "../../Include/RmlUi/Core/Core.h"
-#include "../../Include/RmlUi/Core/ElementUtilities.h"
 #include "../../Include/RmlUi/Core/ElementText.h"
+#include "../../Include/RmlUi/Core/ElementUtilities.h"
 #include "../../Include/RmlUi/Core/Factory.h"
-#include "../../Include/RmlUi/Core/Property.h"
 #include "../../Include/RmlUi/Core/PropertiesIteratorView.h"
+#include "../../Include/RmlUi/Core/Property.h"
+#include "../../Include/RmlUi/Core/PropertyDefinition.h"
 #include "../../Include/RmlUi/Core/StyleSheet.h"
 #include "../../Include/RmlUi/Core/StyleSheetSpecification.h"
 #include "../../Include/RmlUi/Core/SystemInterface.h"
-#include "../../Include/RmlUi/Core/PropertyDefinition.h"
-#include "Geometry.h"
 #include "CommonSource.h"
+#include "Geometry.h"
 #include "InfoSource.h"
 #include <algorithm>
 
@@ -325,9 +326,10 @@ void ElementInfo::ProcessEvent(Event& event)
 				}
 			}
 			// Otherwise we just want to focus on the clicked element (unless it's on a debug element)
-			else if (enable_element_select && owner_document != nullptr && owner_document->GetId().find("rmlui-debug-") != 0)
+			else if (enable_element_select && owner_document && owner_document->GetId().find("rmlui-debug-") != 0)
 			{
-				hover_element = target_element;
+				if (Context* context = owner_document->GetContext())
+					hover_element = context->GetHoverElement();
 			}
 		}
 		else if (event == EventId::Mouseout)
@@ -349,6 +351,12 @@ void ElementInfo::ProcessEvent(Event& event)
 					title_dirty = true;
 				}
 			}
+			else if (enable_element_select && owner_document && owner_document->GetId().find("rmlui-debug-") != 0)
+			{
+				// Update hover element also on MouseOut as we may not get a MouseOver event when moving the mouse to a parent element.
+				if (Context* context = owner_document->GetContext())
+					hover_element = context->GetHoverElement();
+			}
 		}
 	}
 }