Skip to content

jvoigtlaender/elm-drag

Repository files navigation

elm-drag

A low- and high-level interface to mouse drag actions in Elm. For documentation of the latest published version, see also http://package.elm-lang.org/packages/jvoigtlaender/elm-drag/latest/Drag.

For reporting any issues, see https://github.com/jvoigtlaender/elm-drag/issues.

The low-level interface is:

type MouseEvent
    = StartAt ( Int, Int )
    | MoveFromTo ( Int, Int ) ( Int, Int )
    | EndAt ( Int, Int )

mouseEvents : Signal MouseEvent

The recommended, high-level interface consists of the track-functions:

type Action
    = Lift
    | MoveBy ( Int, Int )
    | Release

track : Bool -> Signal Bool -> Signal (Maybe Action)

trackMany : Maybe a -> Signal (Maybe a) -> Signal (Maybe ( a, Action ))

In those track-functions, the Bool/Signal Bool or Maybe a/Signal (Maybe a) arguments are the initial value and input signal which tell whether the mouse is (currently) hovering over something draggable. See Example1.elm (demo), Example2.elm (demo), Example3.elm (demo), and Example3b.elm (demo).

The library also exposes an Automaton:

type Input a
    = Mouse MouseEvent
    | Hover (Maybe a)

automaton : Maybe a -> Automaton (Input a) (Maybe ( a, Action ))

This can be used in specific situations where the track-functions are not applicable. See Example4.elm (demo), where the automaton is used to realize accurate dragging of non-rectangular shapes.

(Said automaton is also used internally in the track-functions.)

About

A low- and high-level interface to mouse drag actions in Elm (up to version 0.16).

Resources

License

Stars

Watchers

Forks

Packages

No packages published