From c8044fe17da7d800213ca4e73cfa8aaa3c8aa4d1 Mon Sep 17 00:00:00 2001 From: superGeometry Date: Thu, 19 Nov 2026 17:04:27 +0200 Subject: [PATCH] Custom transparency takes whole percents from 0 to 95: the numpad greys its point and minus keys, a keyboard's are left out, a drag stops at 0 and 95, and a value past either end is set to it Co-Authored-By: Claude Opus 5.5 --- src/style.css | 5 +++++ src/tools/select.ts | 2 +- src/ui/numpad.ts | 11 ++++++++++- src/ui/ui.ts | 2 +- src/ui/wheel.ts | 15 ++++++++++++--- 5 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/style.css b/src/style.css index 36dc931..c326ae6 100644 --- a/src/style.css +++ b/src/style.css @@ -3040,6 +3040,11 @@ form.dialog { .numpad button:active { background: #3d8bff; } +/* A key the box can't take (a point in a whole number, a minus where it can't go below 0). */ +.numpad button:disabled { + opacity: 0.3; + pointer-events: none; +} .numpad .np-enter { grid-row: span 2; height: auto; diff --git a/src/tools/select.ts b/src/tools/select.ts index 412caba..e996d4c 100644 --- a/src/tools/select.ts +++ b/src/tools/select.ts @@ -1078,7 +1078,7 @@ export class SelectTool implements Tool { icon: "numpad", ...(custom ? { sub: seeThrough(now) } : {}), active: custom, - value: { now: typed, put, int: true }, + value: { now: typed, put, int: true, min: 0, max: 95 }, run: async () => { const r = await app.ui.dialog("Custom transparency", [{ key: "pct", label: "Transparency (%)", value: typed }]); const v = r ? parseFloat(r.pct) : NaN; diff --git a/src/ui/numpad.ts b/src/ui/numpad.ts index a8d5d7c..2cfb723 100644 --- a/src/ui/numpad.ts +++ b/src/ui/numpad.ts @@ -58,6 +58,10 @@ class Numpad { private selEnd = 0; /** Just opened on a box: the first key typed replaces what's in it. */ private fresh = false; + /** The keys, to grey the ones a box can't take (no point for whole numbers, no minus where it can't go below 0). */ + private keys = new Map(); + private off = (k: string, t: HTMLInputElement | null) => + !!t && ((k === "." && t.dataset.kind === "int") || (k === "−" && t.dataset.min !== undefined && Number(t.dataset.min) >= 0)); /** The first key was − (the sign flipped): digits next type a new negative number. */ private minusFirst = false; /** ƒx on: operators and the variables' names to type formulas with. */ @@ -133,7 +137,7 @@ class Numpad { host.append(b); return b; }; - for (const k of KEYS) key(k, this.el); + for (const k of KEYS) this.keys.set(k, key(k, this.el)); this.fxRow.className = "np-fx-row"; for (const k of FX_KEYS) key(k, this.fxRow, k === "abc" ? "np-abc" : "np-op"); this.chips.className = "np-chips"; @@ -201,6 +205,7 @@ class Numpad { const at = stay ? { left: this.el.style.left, top: this.el.style.top } : null; this.target?.classList.remove("np-all"); this.target = input; + for (const [k, b] of this.keys) b.disabled = this.off(k, input); this.fresh = true; this.minusFirst = false; // A formula in the box already: ƒx is on. @@ -310,6 +315,7 @@ class Numpad { private press(k: string): void { const t = this.target; + if (this.off(k, t)) return; // The box went away (its tool finished): nothing to type into. if (!t || !t.isConnected) return this.close(); let v = t.value; @@ -499,6 +505,9 @@ function scrubbable(input: HTMLInputElement): void { const n = Math.round(dx / 4); let nv = start.v + n * start.step; if (start.kind === "int") nv = Math.round(nv); + // (A box with a least or a most: the drag stops there.) + if (input.dataset.min !== undefined) nv = Math.max(Number(input.dataset.min), nv); + if (input.dataset.max !== undefined) nv = Math.min(Number(input.dataset.max), nv); const dec = Math.max(0, -Math.floor(Math.log10(start.step) + 1e-9)); const text = String(Number(nv.toFixed(dec))); if (text !== input.value) { diff --git a/src/ui/ui.ts b/src/ui/ui.ts index 5c7f593..82a266f 100644 --- a/src/ui/ui.ts +++ b/src/ui/ui.ts @@ -44,7 +44,7 @@ export interface ToolItem { /** Still being tried out: a BETA tag on it. */ beta?: boolean; /** On the wheel, a tap opens a box by it to type a number into (`run` is what a column or menu does instead). */ - value?: { now: string; put(v: number): void; /** Whole numbers only (a drag steps by 1). */ int?: boolean }; + value?: { now: string; put(v: number): void; /** Whole numbers only (a drag steps by 1). */ int?: boolean; /** The least and most it can be. */ min?: number; max?: number }; /** Its kinds go round the wheel in the order listed (Solid, 25%, 50%, 75%), not most used first. */ inOrder?: boolean; run?(): void; diff --git a/src/ui/wheel.ts b/src/ui/wheel.ts index 4822a0b..bb851b5 100644 --- a/src/ui/wheel.ts +++ b/src/ui/wheel.ts @@ -908,7 +908,7 @@ export class Wheel implements WheelHandle { * Type a value right on the wheel: a small box by the pointer, the value * in it selected. Enter (or tapping away) sets it, Esc leaves it as it was. */ - private typeValue(label: string, now: string, kind: "length" | "angle" | "number" | "int", put: (v: number) => void, follows = false): void { + private typeValue(label: string, now: string, kind: "length" | "angle" | "number" | "int", put: (v: number) => void, follows = false, range: { min?: number; max?: number } = {}): void { this.typerEnd?.(false); const box = el("div", "wheel-type"); box.append(el("span", "wheel-type-label", label)); @@ -920,6 +920,15 @@ export class Wheel implements WheelHandle { input.value = now; input.dataset.kind = kind; if (follows) input.dataset.follows = "1"; + if (range.min !== undefined) input.dataset.min = String(range.min); + if (range.max !== undefined) input.dataset.max = String(range.max); + // (Typed on a keyboard: no point in a whole number, no minus where it can't go below 0.) + input.addEventListener("input", () => { + let t = input.value; + if (kind === "int") t = t.replace(/[.,]/g, ""); + if (range.min !== undefined && range.min >= 0) t = t.replace(/-/g, ""); + if (t !== input.value) input.value = t; + }); numpadInput(input); box.append(input); const unit = kind === "length" ? UNIT_LABEL[units()] : kind === "angle" ? "°" : ""; @@ -934,7 +943,7 @@ export class Wheel implements WheelHandle { over = true; if (keep) { const v = evaluate(input.value, kind === "int" ? "number" : kind); - if (v !== null) put(kind === "int" ? Math.round(v) : v); + if (v !== null) put(Math.min(range.max ?? Infinity, Math.max(range.min ?? -Infinity, kind === "int" ? Math.round(v) : v))); } box.remove(); if (this.typer === box) (this.typer = null), (this.typerEnd = null); @@ -1705,7 +1714,7 @@ export class Wheel implements WheelHandle { private run(item: ToolItem): void { // A number to type (a custom transparency): its box comes up by the wheel. - if (item.value) return this.typeValue(item.label.replace(/…$/, ""), item.value.now, item.value.int ? "int" : "number", item.value.put); + if (item.value) return this.typeValue(item.label.replace(/…$/, ""), item.value.now, item.value.int ? "int" : "number", item.value.put, false, item.value); // A switch or a choice on the Settings wheel is set right there: the fan stays, showing it set. if (item.id.startsWith("opt-") && !item.id.endsWith("-more")) { item.run?.();