Nez.Portable/UI/IMGUI.cs
/// <summary>
/// value should be between 0 and 1
/// </summary>
/// <param name="value">Value.</param>
value should be between 0 and 1
value should be between 0 and 1
public static float slider(float value, string name = "")
        {
            var workingWidth = _elementWidth - SHORT_ELEMENT_HEIGHT;
            var thumbPos = workingWidth * value;
            var color = SLIDER_THUMB_BG;
            if (isMouseOverElement())
            {
                if (Input.leftMouseButtonDown)
                {
                    var localMouseX = _mouseInWorldCoords.X - _elementX - SHORT_ELEMENT_HEIGHT * 0.5f;
                    value = MathHelper.Clamp(localMouseX / workingWidth, 0, 1);
                    thumbPos = workingWidth * value;
                    color = SLIDER_THUMB_BG_DOWN;
                }
                else
                {
                    color = SLIDER_THUMB_BG_ACTIVE;
                }
            }
            _spriteBatch.drawRect(_elementX, _lastY + ELEMENT_PADDING, _elementWidth, SHORT_ELEMENT_HEIGHT, SLIDER_BG);
            _spriteBatch.drawRect(
                _elementX + thumbPos,
                _lastY + ELEMENT_PADDING,
                SHORT_ELEMENT_HEIGHT,
                SHORT_ELEMENT_HEIGHT,
                color);
            drawString(name + value.ToString("F"), FONT_COLOR, TextAlign.Center, SHORT_ELEMENT_HEIGHT);
            endElement();
            return value;
        }
public static float slider ( float value , string name = " " ) { var workingWidth = _elementWidth - SHORT_ELEMENT_HEIGHT ; var thumbPos = workingWidth * value ; var color = SLIDER_THUMB_BG ; if ( isMouseOverElement ( ) ) { if ( Input . leftMouseButtonDown ) { var localMouseX = _mouseInWorldCoords . X - _elementX - SHORT_ELEMENT_HEIGHT * 0.5f ; value = MathHelper . Clamp ( localMouseX / workingWidth , 0 , 1 ) ; thumbPos = workingWidth * value ; color = SLIDER_THUMB_BG_DOWN ; } else { color = SLIDER_THUMB_BG_ACTIVE ; } } _spriteBatch . drawRect ( _elementX , _lastY + ELEMENT_PADDING , _elementWidth , SHORT_ELEMENT_HEIGHT , SLIDER_BG ) ; _spriteBatch . drawRect ( _elementX + thumbPos , _lastY + ELEMENT_PADDING , SHORT_ELEMENT_HEIGHT , SHORT_ELEMENT_HEIGHT , color ) ; drawString ( name + value . ToString ( " " ) , FONT_COLOR , TextAlign . Center , SHORT_ELEMENT_HEIGHT ) ; endElement ( ) ; return value ; }
value should be between 0 and 1
value should be between 0 and 1
value
float
None
name
string