Skip to content

Commit

Permalink
emscripten : fix right-click
Browse files Browse the repository at this point in the history
  • Loading branch information
ggerganov committed Nov 8, 2021
1 parent 2b7733e commit aa55479
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 11 additions & 1 deletion examples/emscripten0/index-tmpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@
event.preventDefault();
}

function oncontextmenu(event) {
if (event.pointerId == 1) {
onpointerdown(event);
} else {
onpointerup(event);
}

event.preventDefault();
}

function onwheel(event) {
let scale = 1.0;
switch (event.deltaMode) {
Expand Down Expand Up @@ -162,7 +172,7 @@
screen.addEventListener('pointerup', onpointerup);
screen.addEventListener('mouseup', onpointerup);

screen.addEventListener('contextmenu', function(event) { event.preventDefault(); });
screen.addEventListener('contextmenu', function(event) { oncontextmenu(event); });
screen.addEventListener('wheel', onwheel, false);

screen.addEventListener('touchstart', ontouch);
Expand Down
4 changes: 2 additions & 2 deletions src/imtui-impl-emscripten.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ void ImTui_ImplEmscripten_NewFrame() {
ImGui::GetIO().MouseWheelH = lastMouseWheelH;
ImGui::GetIO().MouseWheel = lastMouseWheel;
ImGui::GetIO().MouseDown[0] = lastMouseDown[0];
ImGui::GetIO().MouseDown[1] = lastMouseDown[1];
ImGui::GetIO().MouseDown[2] = lastMouseDown[2];
ImGui::GetIO().MouseDown[1] = lastMouseDown[2]; // right-click in browser is 2
ImGui::GetIO().MouseDown[2] = lastMouseDown[1]; // scroll-click in browser is 1
ImGui::GetIO().MouseDown[3] = lastMouseDown[3];
ImGui::GetIO().MouseDown[4] = lastMouseDown[4];

Expand Down

0 comments on commit aa55479

Please sign in to comment.