Giter Club home page Giter Club logo

elm-drag's Introduction

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.)

elm-drag's People

Contributors

jvoigtlaender avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

elm-drag's Issues

MoveFromTo's output values are identical

Hi! I'm playing around with elm-drag's low level interface and, perhaps I'm misunderstanding something about its use, but upon inspecting the output of the mouseEvents signal with a simple main = Signal.map show mouseEvents, the two tuples from MoveFromTo are nearly identical no matter where I drag from/to. Is that by design?

movefromto

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.