Repository: bulletphysics/bullet3

Issue:
Slider changed callback in ExampleBrowser does not work
I tried to use it with a matching function, but it never got called. I looked into the example browser and only found an example that uses the button callback. Older examples used the slider change not event based, but updated within stepSimulation(). If it is working, can someone provide a simple example how it works? If not, can we fix this?



Discussion:
I think I found the issue. In GwenParameterInterface.cpp in MySliderEventHandler, the sliderMoved() method does not call the user assigned callback whereas the MyButtonEventHandler calls:

  if (m_callback)
        {

```
        (*m_callback)(m_buttonId, true, m_userPointer);

    }
```

I will make a pull request soon which fixes the issue.


Patch:
diff --git a/examples/ExampleBrowser/GwenGUISupport/GwenParameterInterface.cpp b/examples/ExampleBrowser/GwenGUISupport/GwenParameterInterface.cpp
index 5032a1cdbe..fee07bc94f 100644
--- a/examples/ExampleBrowser/GwenGUISupport/GwenParameterInterface.cpp
+++ b/examples/ExampleBrowser/GwenGUISupport/GwenParameterInterface.cpp
@@ -27,17 +27,19 @@ struct MyButtonEventHandler : public Gwen::Event::Handler
 template<typename T>
 struct MySliderEventHandler : public Gwen::Event::Handler
 {
+	SliderParamChangedCallback m_callback;
 	Gwen::Controls::TextBox* m_label;
 	Gwen::Controls::Slider* m_pSlider;
 	char m_variableName[1024];
 	T* m_targetValue;
     bool m_showValue;
 
-	MySliderEventHandler(const char* varName, Gwen::Controls::TextBox* label, Gwen::Controls::Slider* pSlider,T* target)
+	MySliderEventHandler(const char* varName, Gwen::Controls::TextBox* label, Gwen::Controls::Slider* pSlider,T* target,SliderParamChangedCallback callback)
 		:m_label(label),
 		m_pSlider(pSlider),
 		m_targetValue(target),
-        m_showValue(true)
+        m_showValue(true),
+		m_callback(callback)
 	{
 		memcpy(m_variableName,varName,strlen(varName)+1);
 	}
@@ -51,6 +53,11 @@ struct MySliderEventHandler : public Gwen::Event::Handler
 		T v = T(bla);
 		SetValue(v);
 
+		if (m_callback)
+		{
+			(*m_callback)(v);
+		}
+
 	}
 
 	void	SetValue(T v)
@@ -219,7 +226,7 @@ void GwenParameterInterface::registerSliderFloatParameter(SliderParams& params)
 	pSlider->SetValue( *params.m_paramValuePointer);//dimensions[i] );
 	char labelName[1024];
 	sprintf(labelName,"%s",params.m_name);//axisNames[0]);
-	MySliderEventHandler<btScalar>* handler = new MySliderEventHandler<btScalar>(labelName,label,pSlider,params.m_paramValuePointer);
+	MySliderEventHandler<btScalar>* handler = new MySliderEventHandler<btScalar>(labelName,label,pSlider,params.m_paramValuePointer,params.m_callback);
     handler->m_showValue = params.m_showValues;
 	m_paramInternalData->m_sliderEventHandlers.push_back(handler);