Skip to content

Commit

Permalink
feat(imgui): add key handling for radialMenu()
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Aug 15, 2019
1 parent 0333fa6 commit 99c2987
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion packages/imgui/src/components/radial-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import {
vertices
} from "@thi.ng/geom";
import { triFan } from "@thi.ng/geom-tessellate";
import { fmod } from "@thi.ng/math";
import { mapIndexed } from "@thi.ng/transducers";
import { add2, hash } from "@thi.ng/vectors";
import { Key } from "../api";
import { IMGUI } from "../gui";
import { buttonRaw } from "./button";
import { textLabelRaw } from "./textlabel";
Expand Down Expand Up @@ -41,10 +43,25 @@ export const radialMenu = (
}, triFan(vertices(circle([x, y], r), n)))
]);
let res: number | undefined;
let sel = -1;
for (let i = 0; i < n; i++) {
const cell = cells[i];
buttonRaw(gui, id + i, cell[0], cell[1], cell[2], cell[3], info[i]) &&
const _id = id + i;
buttonRaw(gui, _id, cell[0], cell[1], cell[2], cell[3], info[i]) &&
(res = i);
gui.focusID === _id && (sel = i);
}
if (sel !== -1) {
switch (gui.key) {
case Key.UP:
case Key.RIGHT:
gui.focusID = id + fmod(sel + 1, n);
break;
case Key.DOWN:
case Key.LEFT:
gui.focusID = id + fmod(sel - 1, n);
default:
}
}
return res;
};

0 comments on commit 99c2987

Please sign in to comment.