1. #1
    Sencha Premium Member
    Join Date
    Jul 2012
    Posts
    20
    Vote Rating
    0
    strootman is on a distinguished road

      0  

    Default Answered: Is there any reason why Slider only supports Integer?

    Answered: Is there any reason why Slider only supports Integer?


    I figured it would be best to ask if there was any reason for this choice before I tried to roll my own SliderCell which extends FieldCell<Number> (or similar).

    After quickly looking at the current SliderCell implementation, it looks like it **might** be straight forward.

    Any thoughts?

  2. The main reason is probably to do with building the behavior is the doSnap method and keyboard control - without that, the functionality is nearly the same - continuous values (or nearly so).

    It could (and perhaps should) have been implemented like SpinnerField, with the ability to support either type of Number, and extra configuration options to manage the step sizes.

    As it would be an API-breaking change, the earliest it could be done would be 3.1.0 - we have a few other changes that would need to be made more generic that this would go nicely with. The one concern I have is that it would break existing code using SliderField as a editor in a form if we change it to SliderField<N extends Number> - for this reason we might have to add a superclass, AbstractSliderCell<N>, and make SliderField and a new DoubleSliderField extend that.

  3. #2
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,717
    Answers
    109
    Vote Rating
    88
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      0  

    Default


    The main reason is probably to do with building the behavior is the doSnap method and keyboard control - without that, the functionality is nearly the same - continuous values (or nearly so).

    It could (and perhaps should) have been implemented like SpinnerField, with the ability to support either type of Number, and extra configuration options to manage the step sizes.

    As it would be an API-breaking change, the earliest it could be done would be 3.1.0 - we have a few other changes that would need to be made more generic that this would go nicely with. The one concern I have is that it would break existing code using SliderField as a editor in a form if we change it to SliderField<N extends Number> - for this reason we might have to add a superclass, AbstractSliderCell<N>, and make SliderField and a new DoubleSliderField extend that.

  4. #3
    Sencha Premium Member
    Join Date
    Jul 2012
    Posts
    20
    Vote Rating
    0
    strootman is on a distinguished road

      0  

    Default


    Is there a link to your planned release dates? I poked around the main site and couldn't find anything.

  5. #4
    Sencha Premium Member
    Join Date
    Jul 2012
    Posts
    20
    Vote Rating
    0
    strootman is on a distinguished road

      0  

    Default


    And, of course, thank you

  6. #5
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,717
    Answers
    109
    Vote Rating
    88
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      0  

    Default


    I can't personally commit to any dates - after all, GXT 3.0.0 itself took significantly longer than we had anticipated. We're trying to get non-API-breaking changes into bugfix releases every 30-60 days or so, and folding bigger changes into minor releases. For 3.1, we initially expected to work on RTL and ARIA support - those are our primary goals, and we'll release when ready and stable. However, GWT 2.5.0 added a new set of ARIA tools, and we are evaluating if they are worthwhile enough to break compatibility with GWT 2.4.0 - one way we force projects to leave GWT 2.4.0 sooner than they had expected, and the other we end up re-inventing the wheel.

    Part of solving this will be seeing how 2.5.1 looks when it is released - there are a number of small regressions in 2.5.0 that make it very unattractive for some teams.

    We need to solve this before we can finalize an approach, then we can go after building in this feature.

    On the topic of a DoubleSlider, I'd welcome more discussion on this feature before we either a) break existing code using Slider/SliderCell or b) add an extra superclass and move (i.e. break) the appearance implementation.

    If this is something you need in your project in the near future, I'd encourage you to try either copying the Slider/SliderCell classes (though I suspect you can reuse the SliderAppearance interface and implementations), or perhaps try building a superclass to handle the heavy lifting of the slider itself. If you run into issues, discussion on the forums will allow us to help you, and for us to see what difficulties are encountered to smooth any future inclusion of this class into our own library. I'd also encourage you to join the ##gwt and #extgwt channels on irc.freenode.net - I am almost always there, and there are many GWT users present and a few GXT developers.

  7. #6
    Sencha Premium Member
    Join Date
    Jul 2012
    Posts
    20
    Vote Rating
    0
    strootman is on a distinguished road

      0  

    Default


    My plan is to clone-and-own the Slider/SliderCell classes. I hope that the SliderAppearance just works, but we'll see.
    I'll definitely post back to the discussion forums when I get something laid down (which will probably be after the holidays).

    I grabbed an IRC client and will start hanging around.

  8. #7
    Sencha Premium Member
    Join Date
    Feb 2012
    Posts
    70
    Vote Rating
    6
    mtraynham is on a distinguished road

      0  

    Default


    Just implemented this, basically using a precision variable that can be used to translate from float to int.

    Basically you just set the precision, but you have to update the min/max/increment after you do.

    FloatSliderCell.java
    Code:
    import com.sencha.gxt.cell.core.client.SliderCell;
    
    public class FloatSliderCell extends SliderCell {
        private int precision = 2;
    
    
        @Override
        protected String onFormatValue(int value) {
            return Float.toString((value/(float)Math.pow(10, this.precision)));
        }
    
    
        public int getPrecision() {
            return precision;
        }
    
    
        public void setPrecision(int precision) {
            this.precision = precision;
        }
    
    
        /**
         * How many units to change the slider when adjusting by drag and drop. Use
         * this option to enable 'snapping' (default to 10).
         * 
         * @param increment the increment
         */
        public void setIncrement(float increment) {
            super.setIncrement((int)(increment*Math.pow(10, this.precision)));
        }
    
    
        /**
         * Sets the max value (defaults to 100).
         * 
         * @param maxValue the max value
         */
        public void setMaxValue(float maxValue) {
            super.setMaxValue((int)(maxValue*Math.pow(10, this.precision)));
        }
    
    
        /**
         * Sets the minimum value (defaults to 0).
         * 
         * @param minValue the minimum value
         */
        public void setMinValue(float minValue) {
            super.setMinValue((int)(minValue*Math.pow(10, this.precision)));
        }
    }
    FloatSlider.java
    Code:
    import com.sencha.gxt.widget.core.client.form.Field;
    
    public class FloatSlider extends Field<Integer> {
    
    
        protected final FloatSliderCell cell;
    
    
        /**
         * Creates a slider with the default slider cell.
         */
        public FloatSlider() {
            super(new FloatSliderCell());
            cell = (FloatSliderCell) getCell();
            setAllowTextSelection(false);
            redraw();
        }
        
        public int getPrecision() {
            return cell.getPrecision();
        }
    
    
        public void setPrecision(int precision) {
            cell.setPrecision(precision);
        }
    
    
        /**
         * Returns the increment.
         * 
         * @return the increment
         */
        public int getIncrement() {
            return cell.getIncrement();
        }
    
    
        /**
         * Returns the max value (defaults to 100).
         * 
         * @return the max value
         */
        public int getMaxValue() {
            return cell.getMaxValue();
        }
    
    
        /**
         * Returns the tool tip message.
         * 
         * @return the tool tip message
         */
        public String getMessage() {
            return cell.getMessage();
        }
    
    
        /**
         * Returns the minimum value (defaults to 0).
         * 
         * @return the minimum value
         */
        public int getMinValue() {
            return cell.getMinValue();
        }
    
    
        /**
         * How many units to change the slider when adjusting by drag and drop. Use
         * this option to enable 'snapping' (default to 10).
         * 
         * @param increment the increment
         */
        public void setIncrement(float increment) {
            cell.setIncrement(increment);
        }
    
    
        /**
         * Sets the max value (defaults to 100).
         * 
         * @param maxValue the max value
         */
        public void setMaxValue(float maxValue) {
            cell.setMaxValue(maxValue);
        }
    
    
        /**
         * Sets the tool tip message (defaults to '{0}'). "{0} will be substituted
         * with the current slider value.
         * 
         * @param message the tool tip message
         */
        public void setMessage(String message) {
            cell.setMessage(message);
        }
    
    
        /**
         * Sets the minimum value (defaults to 0).
         * 
         * @param minValue the minimum value
         */
        public void setMinValue(float minValue) {
            cell.setMinValue(minValue);
        }
        
        /**
         * A way to cast the value retrieved from the int slider and cast as float.
         * @param value
         * @return
         */
        public Integer toInteger(Float value) {
            return (int)(value*Math.pow(10, cell.getPrecision()));
        }
        
        /**
         * A way to cast the value retrieved from the int slider and cast as float.
         * @param value
         * @return
         */
        public Float toFloat(Integer value) {
            return (value/(float)Math.pow(10, cell.getPrecision()));
        }
    }

  9. #8
    Sencha Premium Member
    Join Date
    Feb 2012
    Posts
    70
    Vote Rating
    6
    mtraynham is on a distinguished road

      0  

    Default


    One more thing, if you are trying to get the value afterwards, it will still return Integer and the integer will be scaled to the precision value (i.e. value * 10^precision). Just call slider.toFloat(Integer value) afterwards to get the value you expect.

Thread Participants: 2

Tags for this Thread