Browse Source

Merge pull request #73 from andreasschultes/fix_range_slider_value_event

Only fire event change if value is changed and pass it value instead …
Michael R. P. Ragazzon 6 years ago
parent
commit
caf9eb521e

+ 0 - 4
Source/Controls/WidgetSlider.cpp

@@ -162,10 +162,6 @@ void WidgetSlider::SetBarPosition(float _bar_position)
 {
 	bar_position = Rml::Core::Math::Clamp(_bar_position, 0.0f, 1.0f);
 	PositionBar();
-
-	Rml::Core::Dictionary parameters;
-	parameters["value"] = bar_position;
-	parent->DispatchEvent(Core::EventId::Change, parameters);
 }
 
 // Returns the current position of the bar.

+ 2 - 2
Source/Controls/WidgetSlider.h

@@ -117,6 +117,8 @@ protected:
 	/// @return The new position of the bar.
 	virtual float OnPageDecrement(float click_position) = 0;
 
+protected:
+    ElementFormControl* parent;
 private:
 	/// Determine the normalized bar position given an absolute position coordinate.
 	/// @param[in] absolute_position Absolute position along the axis determined by 'orientation'.
@@ -125,8 +127,6 @@ private:
 
 	void PositionBar();
 
-	ElementFormControl* parent;
-
 	Orientation orientation;
 
 	// The background track element, across which the bar slides.

+ 5 - 0
Source/Controls/WidgetSliderInput.cpp

@@ -29,6 +29,7 @@
 #include "WidgetSliderInput.h"
 #include "../../Include/RmlUi/Core/Math.h"
 #include "../../Include/RmlUi/Core/Element.h"
+#include "../../Include/RmlUi/Controls/ElementFormControl.h"
 
 namespace Rml {
 namespace Controls {
@@ -139,6 +140,10 @@ float WidgetSliderInput::SetValueInternal(float new_value)
 		return 0;
 	}
 
+    Rml::Core::Dictionary parameters;
+    parameters["value"] = value;
+    parent->DispatchEvent(Core::EventId::Change, parameters);
+
 	return (value - min_value) / (max_value - min_value);
 }