-
Notifications
You must be signed in to change notification settings - Fork 5
Events
Zaffre uses Clojure's core.async pub-sub metaphor for event handling. A terminal's publication is available through the Terminal
protocol's (pub [terminal])
method.
Typically, an application will use zaffre.events/add-event-listener
to add event listeners.
(zevents/add-event-listener terminal :keypress
(fn [ev] ...))
However there may be cases when working directly with core.async/sub
is preferred.
(let [term-pub (pub terminal)
key-chan (core.async/chan)]
(core.async/sub :keypress key-chan)
(core.async/go-loop []
(let [new-key (core.async/<! key-chan)]
; Do something with new-key
Keypress messages are simply characters.
Mouse down messages are maps.
Example:
{:type :mouse-down
:button :left ; :left/:right/:middle
:col 21
:row 44
:group-id :app}
One :mouse-down
message will be received for each layer group intersecting the mouse cursor. If using pub/sub you may find clojure.core.async/filter<
useful to filter messages of a certain :group-id
. Otherwise, be careful and remember to check the :group-id
in the event handler if necessary.
Mouse up messages are maps.
Example:
{:type :mouse-up
:button :left ; :left/:right/:middle
:col 21
:row 44
:group-id :app}
Like :mouse-down
, one :mouse-up
message will be received for each layer group intersecting the mouse cursor. If using pub/sub you may find clojure.core.async/filter<
useful to filter messages of a certain :group-id
. Otherwise, be careful and remember to check the :group-id
in the event handler if necessary.
Click messages are maps.
Example:
{:type :click
:button :left ; :left/:right/:middle
:col 21
:row 44
:group-id :app}
Click messages are generated on mouse up for every (group,col,row) that matches to the corresponding mouse down. Ie: the mouse cursor may drag a bit, but as long as the cursor is inside the same grid cell when the button is release, a click message will be generated.
Like :mouse-down
and :mouse-up
, one :click
message will be received for each layer group intersecting the mouse cursor. If using pub/sub you may find clojure.core.async/filter<
useful to filter messages of a certain :group-id
. Otherwise, be careful and remember to check the :group-id
in the event handler if necessary.
Mouse leave messages are maps.
Example:
{:type :mouse-leave
:col 21
:row 44
:group-id :app}
Mouse enter messages are maps.
Example:
{:type :mouse-enter
:col 21
:row 44
:group-id :app}
The close message value is the keyword :close
. Close messages are generated when the window is dismissed or destroy!
is called on the terminal.