Last active
August 29, 2015 14:05
-
-
Save jmuhlich/a3e66c8f3cf9e56c5bee to your computer and use it in GitHub Desktop.
elm slider test WIP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Mouse | |
import Graphics.Input (Input, input, hoverable) | |
type SliderInput = { mouseX:Int, mouseY:Int, mouseDown:Bool } | |
sliderInput = SliderInput <~ Mouse.x | |
~ Mouse.y | |
~ Mouse.isDown | |
type Slider = { value:Int, isMoving:Bool } | |
defaultSlider : Slider | |
defaultSlider = | |
{ value = 0 | |
, isMoving = False | |
} | |
stepSlider : SliderInput -> Slider -> Slider | |
stepSlider {mouseX, mouseY, mouseDown} | |
({value, isMoving} as slider) = | |
let isMoving' = mouseDown | |
value' = if isMoving' then mouseX else value | |
in | |
{ slider | isMoving <- isMoving' | |
, value <- value' } | |
sliderState : Signal Slider | |
sliderState = foldp stepSlider defaultSlider sliderInput | |
view : Slider -> Element | |
view {value,isMoving} = asText value | |
main = lift view sliderState |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment