Browse Source

Properly handle clicks on tabs in ElementTabSet (hopefully fixes #46).

Michael Ragazzon 6 years ago
parent
commit
91f5231e3d
2 changed files with 8 additions and 20 deletions
  1. 4 5
      Include/RmlUi/Controls/ElementTabSet.h
  2. 4 15
      Source/Controls/ElementTabSet.cpp

+ 4 - 5
Include/RmlUi/Controls/ElementTabSet.h

@@ -42,7 +42,7 @@ namespace Controls {
 	@author Lloyd Weehuizen
 	@author Lloyd Weehuizen
  */
  */
 
 
-class RMLUICONTROLS_API ElementTabSet : public Core::Element, public Core::EventListener
+class RMLUICONTROLS_API ElementTabSet : public Core::Element
 {
 {
 public:
 public:
 	ElementTabSet(const Rml::Core::String& tag);
 	ElementTabSet(const Rml::Core::String& tag);
@@ -82,13 +82,12 @@ public:
 	/// @return The index of the active tab.
 	/// @return The index of the active tab.
 	int GetActiveTab() const;
 	int GetActiveTab() const;
 
 
-	/// Process the incoming event.
-	void ProcessEvent(Core::Event& event) override;
+	/// Capture clicks on our tabs.
+	void ProcessDefaultAction(Core::Event& event) override;
 
 
 protected:
 protected:
-	// Catch child add/removes so we can correctly set up their events.
+	// Catch child add so we can correctly set up its properties.
 	void OnChildAdd(Core::Element* child) override;
 	void OnChildAdd(Core::Element* child) override;
-	void OnChildRemove(Core::Element* child) override;
 
 
 private:
 private:
 	Core::Element* GetChildByTag(const Rml::Core::String& tag);
 	Core::Element* GetChildByTag(const Rml::Core::String& tag);

+ 4 - 15
Source/Controls/ElementTabSet.cpp

@@ -140,10 +140,11 @@ int ElementTabSet::GetActiveTab() const
 	return active_tab;
 	return active_tab;
 }
 }
 
 
-// Process the incoming event.
-void ElementTabSet::ProcessEvent(Core::Event& event)
+void ElementTabSet::ProcessDefaultAction(Core::Event& event)
 {
 {
-	if (event.GetCurrentElement() == this && event == Core::EventId::Click)
+	Element::ProcessDefaultAction(event);
+
+	if (event == Core::EventId::Click)
 	{
 	{
 		// Find the tab that this click occured on
 		// Find the tab that this click occured on
 		Core::Element* tabs = GetChildByTag("tabs");
 		Core::Element* tabs = GetChildByTag("tabs");
@@ -178,7 +179,6 @@ void ElementTabSet::OnChildAdd(Core::Element* child)
 	{
 	{
 		// Set up the new button and append it
 		// Set up the new button and append it
 		child->SetProperty(Core::PropertyId::Display, Core::Property(Core::Style::Display::InlineBlock));
 		child->SetProperty(Core::PropertyId::Display, Core::Property(Core::Style::Display::InlineBlock));
-		child->AddEventListener(Core::EventId::Click, this);
 
 
 		if (child->GetParentNode()->GetChild(active_tab) == child)
 		if (child->GetParentNode()->GetChild(active_tab) == child)
 			child->SetPseudoClass("selected", true);
 			child->SetPseudoClass("selected", true);
@@ -195,17 +195,6 @@ void ElementTabSet::OnChildAdd(Core::Element* child)
 	}
 	}
 }
 }
 
 
-void ElementTabSet::OnChildRemove(Core::Element* child)
-{
-	Core::Element::OnChildRemove(child);
-
-	// If its a tab, remove its event listener
-	if (child->GetParentNode() == GetChildByTag("tabs"))
-	{
-		child->RemoveEventListener(Core::EventId::Click, this);
-	}
-}
-
 Core::Element* ElementTabSet::GetChildByTag(const Rml::Core::String& tag)
 Core::Element* ElementTabSet::GetChildByTag(const Rml::Core::String& tag)
 {
 {
 	// Look for the existing child
 	// Look for the existing child