[SOLVED] Lemur Spinner resolution issue

Hi

I have an issue with numeric Spinner in Lemur in which the resolution is not applied properly. Sometimes it goes beyond the configured resolution.

Test case:

public class Main extends SimpleApplication {

    public static void main( String... args ) {
        Main main = new Main();
        main.setShowSettings(false);
        main.setDisplayStatView(false);
        main.start();
    }
    
    public void simpleInitApp() {

        GuiGlobals.initialize(this);
        GuiGlobals globals = GuiGlobals.getInstance();
        BaseStyles.loadGlassStyle();
        Styles styles = globals.getStyles();
        styles.setDefaultStyle("glass");
        
        // Create a Spinner with values is in [0, 1] with step of 0.1 and resolution 0.1
        Spinner<Double> doubleSpinner = new Spinner<>(SequenceModels.rangedSequence(new DefaultRangedValueModel(0, 1, 1), 0.1, 0.1));
        doubleSpinner.setLocalTranslation(200, 200, 0);
        guiNode.attachChild(doubleSpinner);

        getInputManager().setCursorVisible(true);

    }

}

Am I doing something wrong or it’s a Spinner bug?

It’s a general floating point issue. Not spinner specific and not much I can do about it, either.

If you want to clamp the visuals to a certain number of decimal places then you need to give it a format.

Here is an example I have from some of my code:

    this.model = SequenceModels.rangedSequence(new DefaultRangedValueModel(0, 1, 0), 0.05, 0.01);
    this.valueRef = model.createReference();
    DefaultValueRenderer<Double> renderer = ValueRenderers.formattedRenderer("%.2f", "error");
            
    this.editor = new Spinner<>(model, renderer);
    editor.setValueEditor(ValueEditors.doubleEditor("%.2f"));   

Edit: note that if you don’t allow direct editing of the value then the renderer part should be enough.

2 Likes

Thanks, using the formatted renderer solved it. :slightly_smiling_face:

2 Likes