Let canvas boxes go left of the canvas edge
The canvas is centred, so on wide screens there is margin to its left that boxes could not be dragged into: x was clamped to 0 in the drag geometry, the arrow-key nudge and validateBox. Only y stays clamped. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -48,7 +48,6 @@ func validateBox(box *models.Box) error {
|
|||||||
if err := validateShadow(&box.Shadow); err != nil {
|
if err := validateShadow(&box.Shadow); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
box.X = max(box.X, 0)
|
|
||||||
box.Y = max(box.Y, 0)
|
box.Y = max(box.Y, 0)
|
||||||
box.W = max(box.W, minBoxSize)
|
box.W = max(box.W, minBoxSize)
|
||||||
box.H = max(box.H, minBoxSize)
|
box.H = max(box.H, minBoxSize)
|
||||||
|
|||||||
@@ -35,13 +35,14 @@ func TestValidateBox(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Geometry is clamped, not rejected: a drag past the canvas edge lands
|
// Geometry is clamped, not rejected: x may go negative, into the margin
|
||||||
// at the edge, and a box can never shrink below a grabbable size.
|
// left of a centred canvas, but nothing goes above the top or below a
|
||||||
|
// grabbable size.
|
||||||
box := models.Box{Page: "stp", Kind: "widget", Widget: str("Chat"), X: -30, Y: -1, W: 5, H: 0}
|
box := models.Box{Page: "stp", Kind: "widget", Widget: str("Chat"), X: -30, Y: -1, W: 5, H: 0}
|
||||||
if err := validateBox(&box); err != nil {
|
if err := validateBox(&box); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if box.X != 0 || box.Y != 0 || box.W != minBoxSize || box.H != minBoxSize {
|
if box.X != -30 || box.Y != 0 || box.W != minBoxSize || box.H != minBoxSize {
|
||||||
t.Fatalf("clamped to %d,%d %dx%d; want 0,0 %dx%d", box.X, box.Y, box.W, box.H, minBoxSize, minBoxSize)
|
t.Fatalf("clamped to %d,%d %dx%d; want -30,0 %dx%d", box.X, box.Y, box.W, box.H, minBoxSize, minBoxSize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,6 @@ function nudge(mode, event) {
|
|||||||
if (mode.includes("s") && event.key === "ArrowDown") next.h += step;
|
if (mode.includes("s") && event.key === "ArrowDown") next.h += step;
|
||||||
if (mode.includes("s") && event.key === "ArrowUp") next.h = Math.max(40, next.h - step);
|
if (mode.includes("s") && event.key === "ArrowUp") next.h = Math.max(40, next.h - step);
|
||||||
}
|
}
|
||||||
next.x = Math.max(0, next.x);
|
|
||||||
next.y = Math.max(0, next.y);
|
next.y = Math.max(0, next.y);
|
||||||
emit("commit", next);
|
emit("commit", next);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,10 +60,10 @@ function nearest(moving, targets, threshold) {
|
|||||||
// `lo`/`hi`: whether the gesture moves this axis's start/end edge.
|
// `lo`/`hi`: whether the gesture moves this axis's start/end edge.
|
||||||
function resolve(start, size, delta, lo, hi, shift) {
|
function resolve(start, size, delta, lo, hi, shift) {
|
||||||
const fit = (n) => (shift === null ? grid(n) : Math.round(n + shift));
|
const fit = (n) => (shift === null ? grid(n) : Math.round(n + shift));
|
||||||
if (lo && hi) return [Math.max(0, fit(start + delta)), size];
|
if (lo && hi) return [fit(start + delta), size];
|
||||||
if (hi) return [start, Math.max(MIN_SIZE, fit(size + delta))];
|
if (hi) return [start, Math.max(MIN_SIZE, fit(size + delta))];
|
||||||
if (lo) {
|
if (lo) {
|
||||||
const s = Math.max(0, Math.min(fit(start + delta), start + size - MIN_SIZE));
|
const s = Math.min(fit(start + delta), start + size - MIN_SIZE);
|
||||||
return [s, start + size - s];
|
return [s, start + size - s];
|
||||||
}
|
}
|
||||||
return [start, size];
|
return [start, size];
|
||||||
|
|||||||
Reference in New Issue
Block a user