@thi.ng/imgui
Version:
Immediate mode GUI with flexible state handling & data only shape output
33 lines (32 loc) • 788 B
JavaScript
import { isLayout } from "@thi.ng/layout/checks";
import { gridLayout } from "@thi.ng/layout/grid-layout";
import { toggle } from "./toggle.js";
const radio = ({
gui,
layout,
id,
horizontal,
square,
value,
label,
info
}) => {
const n = label.length;
const nested = isLayout(layout) ? horizontal ? layout.nest(n, [n, 1]) : layout.nest(1, [1, n]) : horizontal ? gridLayout(layout.x, layout.y, layout.w, n, layout.ch, layout.gap) : gridLayout(layout.x, layout.y, layout.w, 1, layout.ch, layout.gap);
let res;
for (let i = 0; i < n; i++) {
toggle({
gui,
square,
layout: nested,
id: `${id}-${i}`,
value: value === i,
label: label[i],
info: info?.[i]
}) !== void 0 && (res = i);
}
return res;
};
export {
radio
};