Skip to content

Commit 6583129

Browse files
committed
Added emscripten_remove_callback to doc
1 parent b7b7240 commit 6583129

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

site/source/docs/api_reference/html5.h.rst

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,50 @@ The ``useCapture`` parameter maps to ``useCapture`` in `EventTarget.addEventLis
9090

9191
Most functions return the result using the type :c:data:`EMSCRIPTEN_RESULT`. Zero and positive values denote success. Negative values signal failure. None of the functions fail or abort by throwing a JavaScript or C++ exception. If a particular browser does not support the given feature, the value :c:data:`EMSCRIPTEN_RESULT_NOT_SUPPORTED` will be returned at the time the callback is registered.
9292

93+
Remove callback function
94+
------------------------
95+
96+
In order to remove a callback, previously set via a ``emscripten_set_some_callback`` call, there is a dedicated and generic function for this purpose:
97+
98+
.. code-block:: cpp
99+
100+
EMSCRIPTEN_RESULT emscripten_remove_callback(
101+
const char *target, // ID of the target HTML element.
102+
void *userData, // User-defined data (passed to the callback).
103+
int eventTypeId, // The event type ID (EMSCRIPTEN_EVENT_XXX).
104+
void *callback // Callback function.
105+
);
106+
107+
108+
The ``target``, ``userData`` and ``callback`` parameters are the same parameters provided in ``emscripten_set_some_callback`` with the only difference being that, since this function applies to all types of callbacks, the type of ``callback`` is ``void *``.
109+
110+
The ``eventTypeId`` represents the event type, the same Id received in the callback functions.
111+
112+
.. code-block:: cpp
113+
114+
// Example
115+
116+
bool my_mouse_callback_1(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData) {
117+
// ...
118+
}
119+
120+
bool my_mouse_callback_2(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData) {
121+
// ...
122+
}
123+
124+
void main() {
125+
126+
// 1. set callbacks for mouse down and mouse move
127+
emscripten_set_mousedown_callback("#mydiv", 0, my_mouse_callback_1);
128+
emscripten_set_mousedown_callback("#mydiv", (void *) 34, my_mouse_callback_2);
129+
emscripten_set_mousemove_callback("#mydiv", 0, my_mouse_callback_1);
130+
131+
// 2. remove these callbacks
132+
emscripten_remove_callback("#mydiv", 0, EMSCRIPTEN_EVENT_MOUSEDOWN, my_mouse_callback_1);
133+
emscripten_remove_callback("#mydiv", (void *) 34, EMSCRIPTEN_EVENT_MOUSEDOWN, my_mouse_callback_2);
134+
emscripten_remove_callback("#mydiv", 0, EMSCRIPTEN_EVENT_MOUSEMOVE, my_mouse_callback_1);
135+
}
136+
93137
94138
Callback functions
95139
------------------

0 commit comments

Comments
 (0)