@thi.ng/imgui
Version:
Immediate mode GUI with flexible state handling & data only shape output
31 lines (30 loc) • 751 B
JavaScript
import { pointInside } from "@thi.ng/geom/point-inside";
import { Key } from "../api.js";
import { tooltipRaw } from "../components/tooltip.js";
const hoverButton = (gui, id, shape, info) => {
if (gui.disabled) return false;
const aid = gui.activeID;
const hover = (aid === "" || aid === id) && pointInside(shape, gui.mouse);
if (hover) {
gui.setCursor("pointer");
gui.hotID = id;
gui.isMouseDown() && (gui.activeID = id);
info && gui.draw && tooltipRaw(gui, info);
}
return hover;
};
const handleButtonKeys = (gui) => {
switch (gui.key) {
case Key.TAB:
gui.switchFocus();
break;
case Key.ENTER:
case Key.SPACE:
return true;
default:
}
};
export {
handleButtonKeys,
hoverButton
};