module Graphics.UI.Threepenny.Events (
valueChange, selectionChange, checkedChange,
click, contextmenu, mousemove, mousedown, mouseup,
hover, leave,
focus, blur,
KeyCode, keyup, keydown, keypress,
roundCoordinates
) where
import Graphics.UI.Threepenny.Attributes
import Graphics.UI.Threepenny.Core
silence :: Event a -> Event ()
silence = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a b. a -> b -> a
const ())
valueChange :: Element -> Event String
valueChange :: Element -> Event String
valueChange Element
el = forall {t} {b}. Element -> (t -> UI b) -> Event t -> Event b
unsafeMapUI Element
el (forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ forall x i o. ReadWriteAttr x i o -> x -> UI o
get Attr Element String
value Element
el) (String -> Element -> Event EventData
domEvent String
"keydown" Element
el)
unsafeMapUI :: Element -> (t -> UI b) -> Event t -> Event b
unsafeMapUI Element
el t -> UI b
f = forall a b. (a -> IO b) -> Event a -> Event b
unsafeMapIO (\t
a -> Element -> IO Window
getWindow Element
el forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Window
w -> forall a. Window -> UI a -> IO a
runUI Window
w (t -> UI b
f t
a))
selectionChange :: Element -> Event (Maybe Int)
selectionChange :: Element -> Event (Maybe Int)
selectionChange Element
el = forall {t} {b}. Element -> (t -> UI b) -> Event t -> Event b
unsafeMapUI Element
el (forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ forall x i o. ReadWriteAttr x i o -> x -> UI o
get Attr Element (Maybe Int)
selection Element
el) (Element -> Event ()
click Element
el)
checkedChange :: Element -> Event Bool
checkedChange :: Element -> Event Bool
checkedChange Element
el = forall {t} {b}. Element -> (t -> UI b) -> Event t -> Event b
unsafeMapUI Element
el (forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ forall x i o. ReadWriteAttr x i o -> x -> UI o
get Attr Element Bool
checked Element
el) (Element -> Event ()
click Element
el)
click :: Element -> Event ()
click :: Element -> Event ()
click = forall {a}. Event a -> Event ()
silence forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Element -> Event EventData
domEvent String
"click"
contextmenu :: Element -> Event (Double,Double)
= forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap EventData -> (Double, Double)
readCoordinates forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Element -> Event EventData
domEvent String
"contextmenu"
hover :: Element -> Event ()
hover :: Element -> Event ()
hover = forall {a}. Event a -> Event ()
silence forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Element -> Event EventData
domEvent String
"mouseenter"
mousemove :: Element -> Event (Double,Double)
mousemove :: Element -> Event (Double, Double)
mousemove = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap EventData -> (Double, Double)
readCoordinates forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Element -> Event EventData
domEvent String
"mousemove"
readCoordinates :: EventData -> (Double,Double)
readCoordinates :: EventData -> (Double, Double)
readCoordinates EventData
json = (Double
x,Double
y)
where [Double
x,Double
y] = forall a. FromJSON a => EventData -> a
unsafeFromJSON EventData
json
roundCoordinates :: (Double,Double) -> (Int,Int)
roundCoordinates :: (Double, Double) -> (Int, Int)
roundCoordinates (Double
x,Double
y) = (forall a b. (RealFrac a, Integral b) => a -> b
round Double
x, forall a b. (RealFrac a, Integral b) => a -> b
round Double
y)
mousedown :: Element -> Event (Double,Double)
mousedown :: Element -> Event (Double, Double)
mousedown = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap EventData -> (Double, Double)
readCoordinates forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Element -> Event EventData
domEvent String
"mousedown"
mouseup :: Element -> Event (Double,Double)
mouseup :: Element -> Event (Double, Double)
mouseup = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap EventData -> (Double, Double)
readCoordinates forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Element -> Event EventData
domEvent String
"mouseup"
leave :: Element -> Event ()
leave :: Element -> Event ()
leave = forall {a}. Event a -> Event ()
silence forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Element -> Event EventData
domEvent String
"mouseleave"
focus :: Element -> Event ()
focus :: Element -> Event ()
focus = forall {a}. Event a -> Event ()
silence forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Element -> Event EventData
domEvent String
"focus"
blur :: Element -> Event ()
blur :: Element -> Event ()
blur = forall {a}. Event a -> Event ()
silence forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Element -> Event EventData
domEvent String
"blur"
type KeyCode = Int
keydown :: Element -> Event KeyCode
keydown :: Element -> Event Int
keydown = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. FromJSON a => EventData -> a
unsafeFromJSON forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Element -> Event EventData
domEvent String
"keydown"
keyup :: Element -> Event KeyCode
keyup :: Element -> Event Int
keyup = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. FromJSON a => EventData -> a
unsafeFromJSON forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Element -> Event EventData
domEvent String
"keyup"
keypress :: Element -> Event Char
keypress :: Element -> Event Char
keypress = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a. Enum a => Int -> a
toEnum forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Read a => String -> a
read forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [a] -> a
head forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. FromJSON a => EventData -> a
unsafeFromJSON) forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Element -> Event EventData
domEvent String
"keypress"