@thi.ng/imgui
Version:
Immediate mode GUI with flexible state handling & data only shape output
49 lines (48 loc) • 880 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.gapX,
layout.gapY
) : gridLayout(
layout.x,
layout.y,
layout.w,
1,
layout.ch,
layout.gapX,
layout.gapY
);
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
};