Files
supergeometry.app/src/tools/patternBox.ts
T
superGeometry 6a6ef8753e Top bar History, cube double tap fits, Snapshot on the wheel; no autofill bar in any typing box
- History is in the top bar (lit while open). On a phone or tablet Enter AR
  goes under More. A headset keeps Enter VR in the top bar.
- No Fit button: a double tap (or double-click) on the view cube fits
  everything, keeping the view the cube had before the first tap.
- Snapshot is on the Settings wheel. With the wheel there is no right column.
- Every keyboard typing box is editable text now (ui/textField.ts): dialogs,
  the Text tool, colour code, grid size, command search, feedback, the BIM
  boxes. A phone shows no autofill bar over them, and a finger never gets the
  whole text selected (that brought up the Cut / Copy bar). The Text tool
  shows the last text as its placeholder on touch: Enter keeps it, typing
  starts afresh.
- Number boxes with the numpad: on touch the value to type over is lit, not
  selected; the first key still replaces it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 00:34:52 +02:00

90 lines
3.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// A small floating box beside a pattern's drag arrow: how many copies, and how
// far apart (between neighbours, or the whole run from the first to the last).
import { Vector3 } from "three";
import type { Vec3 } from "../doc/types";
import { el } from "../ui/ui";
import { numpadInput } from "../ui/numpad";
import { selectAll } from "../ui/textField";
import { evaluate, toDisplay, trim, UNIT_LABEL, units } from "../units";
import type { Viewport } from "../view/viewport";
export interface PatternBoxOptions {
count: number;
spacing: number;
/** "between": spacing is from one copy to the next; "total": from the first to the last. */
measure: "between" | "total";
onChange(v: { count: number; spacing: number; measure: "between" | "total" }): void;
onCommit(): void;
}
export class PatternBox {
private box = el("div", "dim-widget pattern-box");
private count = document.createElement("input");
private dist = document.createElement("input");
private sel = document.createElement("select");
private at = new Vector3();
private hook = () => this.layout();
constructor(
private view: Viewport,
opts: PatternBoxOptions,
) {
for (const [id, label] of [["between", "Between"], ["total", "Total"]]) {
const o = document.createElement("option");
o.value = id;
o.textContent = label;
this.sel.append(o);
}
this.sel.value = opts.measure;
this.count.inputMode = "numeric";
this.count.value = String(opts.count);
this.count.title = "Count (the original included)";
this.dist.inputMode = "decimal";
numpadInput(this.count);
numpadInput(this.dist);
this.dist.value = trim(toDisplay(opts.spacing), 3);
const changed = () => {
const n = Math.round(Number(this.count.value));
const d = evaluate(this.dist.value, "length");
const ok = Number.isFinite(n) && n >= 2 && d !== null;
this.box.classList.toggle("invalid", !ok);
if (ok) opts.onChange({ count: n, spacing: d!, measure: this.sel.value as "between" | "total" });
};
for (const i of [this.count, this.dist]) {
i.spellcheck = false;
i.addEventListener("input", changed);
i.addEventListener("keydown", (e) => {
e.stopPropagation();
if (e.key === "Enter") opts.onCommit();
if (e.key === "Escape") i.blur();
});
}
this.sel.addEventListener("change", changed);
this.box.append(el("span", "dim-unit", "×"), this.count, this.sel, this.dist, el("span", "dim-unit", UNIT_LABEL[units()]));
this.box.addEventListener("pointerdown", (e) => e.stopPropagation());
document.body.append(this.box);
view.frameHooks.add(this.hook);
view.helpers.add(this);
setTimeout(() => (this.count.focus(), selectAll(this.count)), 0);
}
/** Where the box sits (a world point, e.g. the arrow's tip). */
place(p: Vec3): void {
this.at.set(...p);
this.layout();
}
private layout(): void {
const s = this.view.toScreen(this.at);
this.box.hidden = !s;
if (s) this.box.style.transform = `translate(${Math.round(s[0] + 24)}px, ${Math.round(s[1] - 24)}px) translate(0, -50%)`;
}
dispose(): void {
this.view.helpers.delete(this);
this.view.frameHooks.delete(this.hook);
this.box.remove();
}
}