Is there a way to detect if a user stopped slyding? Maybe bij mouse input check or something. I tried mouse isButton0Release and hasFocus in the onSliderChange event to check if the user stopped sliding, but this doesn't work.
What i got so far
@NiftyEventSubscriber(id = "speedSlider")
public void onSliderChange(String id, SliderChangedEvent event)
{ boolean test2 = event.getSlider().hasFocus();
boolean test = nifty.getMouseInputEventQueue().getLastMouseDownEvent().isButton0Release();
System.out.println("before " + test2);
int speed = (int)event.getValue();
speedTextField.getRenderer(TextRenderer.class).setText(speed + "");
if(test2){
System.out.println("after " + test2);
main.setSimSpeed(speed);
}
}
And the slider in xml
<panel id="speed_up_down_panel" height="30px" width="180px" childLayout="center">
<control id="speedSlider" name="horizontalSlider" width="150px" min="1" initial="1" buttonStepSize="1">
<image id="#position" filename="Interface/sliderbutton.png" visibleToMouse="true" width="40px" height="40px"></image>
</control>
</panel>
The code is a bit messy now becuase i testing.
The easiest way I can think of is to define your own control that adds an
onReleaseevent handler:Note: I just copied the original definition of the SliderControl and added
onReleaseto the<interact>tag. See: https://github.com/nifty-gui/nifty-gui/blob/1.4/nifty-controls/src/main/resources/nifty-controls/nifty-slider.xmlNow load this new control using this line in your XML:
(insert it after the line which loads
nifty-default-controls.xml)And then add a method
public void onRelease()to your Controller.