GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: the action bar keeps clear of the selection guide badges under t… · u8array/ZPLab@6cb2201

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • e2e
    • selectionGuides.spec.ts
  • src/components/Canvas
    • LabelCanvas.tsx
    • SelectionGuides.tsx
    • hooks
      • useSelectionActionBar.test.ts
      • useSelectionActionBar.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎e2e/selectionGuides.spec.ts‎

Copy file name to clipboardExpand all lines: e2e/selectionGuides.spec.ts
+62Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ async function nearBadges(page: Page) {
8585
});
8686
}
8787

88+
const RULER = 20;
89+
const BAR_GAP = 22;
90+
const BADGE_ROW_BOTTOM = 38;
91+
8892
/** Adds a Box and waits until the guides sit on it. */
8993
async function addBox(page: Page) {
9094
const before = (await guides(page))?.frame;
@@ -274,3 +278,61 @@ test('the action bar covers the guides that run behind it', async ({ page }) =>
274278
await expect.poll(covered).toEqual({ guidePixels: 0, inside: true });
275279
expect(pageErrors, pageErrors.map((e) => e.message).join('\n')).toHaveLength(0);
276280
});
281+
282+
test('the action bar stays out of the badge row under the top ruler', async ({ page }) => {
283+
const origin = await open(page);
284+
await addBox(page);
285+
const { frame } = (await guides(page)) as Guides;
286+
const midY = origin.y + (frame.minY + frame.maxY) / 2;
287+
await page.mouse.move(origin.x + frame.maxX, midY);
288+
await page.mouse.down();
289+
await page.mouse.move(origin.x + frame.minX + 24, midY, { steps: 6 });
290+
await page.mouse.up();
291+
await expect.poll(async () => ((await guides(page))?.frame.maxX ?? Infinity) - frame.minX).toBeLessThan(40);
292+
293+
// Drag up to where the bar still sits above the box and would reach into the badge row.
294+
const barHeight = await page.evaluate(() => {
295+
interface Node {
296+
findOne: (s: string) => { getClientRect: () => { height: number } } | undefined;
297+
}
298+
return (window as unknown as { Konva: { stages: Node[] } }).Konva.stages[0].findOne('.action-bar')?.getClientRect().height ?? 0;
299+
});
300+
const reach = { from: RULER + BAR_GAP + barHeight, to: BADGE_ROW_BOTTOM + BAR_GAP + barHeight };
301+
const grabX = origin.x + frame.minX + 12;
302+
await page.mouse.move(grabX, midY);
303+
await page.mouse.down();
304+
// Ctrl suspends smart snapping so the box stays in reach.
305+
await page.keyboard.down('Control');
306+
await page.mouse.move(grabX, midY - (frame.minY - (reach.from + reach.to) / 2), { steps: 8 });
307+
await page.mouse.up();
308+
await page.keyboard.up('Control');
309+
await expect.poll(async () => (await guides(page))?.frame.minY ?? Infinity).toBeLessThan(reach.to - 1);
310+
expect((await guides(page))?.frame.minY).toBeGreaterThan(reach.from + 1);
311+
312+
const overlaps = () =>
313+
page.evaluate(() => {
314+
interface Rect {
315+
x: number;
316+
y: number;
317+
width: number;
318+
height: number;
319+
}
320+
interface Node {
321+
find: (s: string) => Node[];
322+
findOne: (s: string) => Node | undefined;
323+
isVisible: () => boolean;
324+
getClientRect: () => Rect;
325+
}
326+
const stage = (window as unknown as { Konva: { stages: Node[] } }).Konva.stages[0];
327+
const bar = stage.findOne('.action-bar')?.getClientRect();
328+
if (!bar) return null;
329+
const badges = ['x-near', 'x-far', 'y-near', 'y-far'].flatMap((name) => stage.find(`.badge-${name}`));
330+
return badges
331+
.filter((badge) => badge.isVisible())
332+
.map((badge) => badge.getClientRect())
333+
.filter((b) => b.x < bar.x + bar.width && bar.x < b.x + b.width && b.y < bar.y + bar.height && bar.y < b.y + b.height)
334+
.length;
335+
});
336+
await expect.poll(overlaps).toBe(0);
337+
expect(pageErrors, pageErrors.map((e) => e.message).join('\n')).toHaveLength(0);
338+
});
Collapse file

‎src/components/Canvas/LabelCanvas.tsx‎

Copy file name to clipboardExpand all lines: src/components/Canvas/LabelCanvas.tsx
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import { RfidPositionGuide } from "./RfidPositionGuide";
4646
import { Grid } from "./Grid";
4747
import { GuideLines } from "./GuideLines";
4848
import { Ruler, RULER_SIZE, type RulerProps } from "./Ruler";
49-
import { SelectionGuideLines, SelectionGuides, type SelectionGuidesHandle } from "./SelectionGuides";
49+
import { BADGE_ROW_PX, SelectionGuideLines, SelectionGuides, type SelectionGuidesHandle } from "./SelectionGuides";
5050
import { SHAPE_PRIMITIVE_TYPES } from "@zplab/core/registry";
5151
import type { LeafObject } from "@zplab/core/registry";
5252
import { isImageRotatable, type ImageProps } from "@zplab/core/registry/image";
@@ -733,6 +733,8 @@ export const LabelCanvas = forwardRef<LabelCanvasHandle, Props>(function LabelCa
733733
: null;
734734
// The resize proxy frames the full boxes, while the other selection frames sit on the bars.
735735
const frameOnBars = !multiResizeBboxDots;
736+
// Reserves the badge row under the top ruler, see BADGE_ROW_PX.
737+
const barTopInset = selectionGuidesEnabled ? BADGE_ROW_PX : 0;
736738
const movableBoxBase = toFramePx(movableUnionDots);
737739
const staticBoxBase = hasSelection ? toFramePx(selectionUnionDots(objects, staticSelIds, frameCtx)) : null;
738740
// The bar-box pair keeps the frame on the bars mid-drag as well.
@@ -905,6 +907,7 @@ export const LabelCanvas = forwardRef<LabelCanvasHandle, Props>(function LabelCa
905907
barHalfRef.current.h,
906908
stage.width(),
907909
stage.height(),
910+
barTopInset,
908911
),
909912
);
910913
}
@@ -1047,6 +1050,7 @@ export const LabelCanvas = forwardRef<LabelCanvasHandle, Props>(function LabelCa
10471050
actionBarRef,
10481051
lockedFrameRef,
10491052
getBarBounds: () => selectionBoundsStage(),
1053+
topInset: barTopInset,
10501054
});
10511055
useSelectionGuides({
10521056
linesRef: selectionGuideLinesRef,
Collapse file

‎src/components/Canvas/SelectionGuides.tsx‎

Copy file name to clipboardExpand all lines: src/components/Canvas/SelectionGuides.tsx
+6-3Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import type { Bounds } from "./nodeRect";
66
import { axisGuides, badgeOffsets, type AxisGuides, type GuideAxis, type GuideReadout } from "./selectionGuideGeometry";
77

88
const BADGE_GAP = 3;
9+
const BADGE_FONT_SIZE = 9;
10+
const BADGE_PADDING = 3;
11+
/** Height of the badge row under the top ruler, gaps included. */
12+
export const BADGE_ROW_PX = 2 * BADGE_GAP + BADGE_FONT_SIZE + 2 * BADGE_PADDING;
913
const AXES = ["x", "y"] as const;
1014
const SIDES = ["near", "far"] as const;
1115
type Axis = (typeof AXES)[number];
@@ -97,8 +101,7 @@ export function SelectionGuides({
97101
return edge && badge ? { edgePx: edge.px, size: badge[extent]() } : null;
98102
};
99103
// The x badges sit in the row under the top ruler. The y badges start below it.
100-
const rowHeight = (badges.near ?? badges.far)?.height() ?? 0;
101-
const lead = key === "y" ? rowHeight + BADGE_GAP : 0;
104+
const lead = key === "y" ? BADGE_ROW_PX - BADGE_GAP : 0;
102105
const at = badgeOffsets(span("near"), span("far"), { ...axes[key], fromPx: axes[key].fromPx + lead }, BADGE_GAP);
103106
for (const side of SIDES) {
104107
const offset = at[side];
@@ -138,7 +141,7 @@ export function SelectionGuides({
138141
SIDES.map((side) => (
139142
<Label key={`${key}-${side}`} name={`badge-${key}-${side}`}>
140143
<Tag fill={colors.selection} cornerRadius={3} />
141-
<Text fill="#ffffff" fontSize={9} fontFamily={RULER_FONT} padding={3} />
144+
<Text fill="#ffffff" fontSize={BADGE_FONT_SIZE} fontFamily={RULER_FONT} padding={BADGE_PADDING} />
142145
</Label>
143146
)),
144147
)}
Collapse file

‎src/components/Canvas/hooks/useSelectionActionBar.test.ts‎

Copy file name to clipboard
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { describe, it, expect } from "vitest";
2+
import { ACTION_BAR_GAP_PX, actionBarPosition } from "./useSelectionActionBar";
3+
import { RULER_SIZE } from "../Ruler";
4+
5+
const HALF = { w: 75, h: 19 };
6+
const STAGE = { width: 800, height: 600 };
7+
const at = (minY: number, maxY: number, topInset = 0) =>
8+
actionBarPosition({ minX: 300, maxX: 340, minY, maxY }, HALF.w, HALF.h, STAGE.width, STAGE.height, topInset);
9+
10+
describe("actionBarPosition", () => {
11+
it("sits above the selection when the bar clears the ruler and below when it does not", () => {
12+
const fits = RULER_SIZE + ACTION_BAR_GAP_PX + 2 * HALF.h;
13+
expect(at(fits, fits + 40).y).toBe(fits - ACTION_BAR_GAP_PX - HALF.h);
14+
expect(at(fits - 1, fits + 39).y).toBe(fits + 39 + ACTION_BAR_GAP_PX + HALF.h);
15+
});
16+
17+
it("leaves the top inset free above the selection and when neither side fits", () => {
18+
const inset = 21;
19+
const fits = RULER_SIZE + inset + ACTION_BAR_GAP_PX + 2 * HALF.h;
20+
expect(at(fits, fits + 40, inset).y).toBe(fits - ACTION_BAR_GAP_PX - HALF.h);
21+
expect(at(fits - 1, fits + 39, inset).y).toBe(fits + 39 + ACTION_BAR_GAP_PX + HALF.h);
22+
expect(at(30, STAGE.height - 10, inset).y).toBe(RULER_SIZE + inset + HALF.h);
23+
});
24+
});
Collapse file

‎src/components/Canvas/hooks/useSelectionActionBar.ts‎

Copy file name to clipboardExpand all lines: src/components/Canvas/hooks/useSelectionActionBar.ts
+15-11Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,27 @@ import type { Bounds } from "../nodeRect";
55

66
export const ACTION_BAR_GAP_PX = 22;
77

8-
/** Shared action-bar placement: centered over the selection, clamped to the
9-
* canvas, flipped below when it would clip the ruler. */
8+
/** Places the bar over the selection, clamped to the canvas. It flips below the selection
9+
* when it would clip the ruler, and `topInset` keeps a strip under the ruler free. */
1010
export function actionBarPosition(
1111
sel: Bounds,
1212
halfW: number,
1313
halfH: number,
1414
stageWidth: number,
1515
stageHeight: number,
16+
topInset: number,
1617
): { x: number; y: number } {
18+
const top = RULER_SIZE + topInset;
1719
const minCx = RULER_SIZE + halfW;
1820
const maxCx = Math.max(minCx, stageWidth - halfW);
1921
const x = Math.min(Math.max((sel.minX + sel.maxX) / 2, minCx), maxCx);
2022
const aboveY = sel.minY - ACTION_BAR_GAP_PX - halfH;
2123
const belowY = sel.maxY + ACTION_BAR_GAP_PX + halfH;
2224
const y =
23-
aboveY - halfH < RULER_SIZE
25+
aboveY - halfH < top
2426
? belowY + halfH <= stageHeight
2527
? belowY
26-
: RULER_SIZE + halfH
28+
: top + halfH
2729
: aboveY;
2830
return { x, y };
2931
}
@@ -43,14 +45,15 @@ interface Options {
4345
/** Selection bounds in stage px from objectBoundsDots (the optical box, incl.
4446
* the ^GD diagonal overhang) so the rest position matches the drag center. */
4547
getBarBounds: () => Bounds | null;
48+
/** Inset under the top ruler that the bar leaves free, in px. */
49+
topInset: number;
4650
}
4751

4852
/**
49-
* Positions the floating selection action bar (centred above the selection,
50-
* flipped below when it would clip past the ruler, clamped horizontally) and an
51-
* amber outline per locked leaf (the transformer skips locked nodes). Imperative
52-
* via beforeDraw so the chrome tracks live node positions during drags, the same
53-
* timing useKonvaTransformer relies on.
53+
* Positions the floating selection action bar through actionBarPosition and draws an amber
54+
* outline per locked leaf, since the transformer skips locked nodes. Runs in beforeDraw so
55+
* the chrome tracks live node positions during drags, the same timing useKonvaTransformer
56+
* relies on.
5457
*/
5558
export function useSelectionActionBar({
5659
stageRef,
@@ -61,6 +64,7 @@ export function useSelectionActionBar({
6164
actionBarRef,
6265
lockedFrameRef,
6366
getBarBounds,
67+
topInset,
6468
}: Options) {
6569
useLayoutEffect(() => {
6670
if (editorFrozen || attachableIds.length === 0) return;
@@ -84,7 +88,7 @@ export function useSelectionActionBar({
8488
if (bar) {
8589
const barRect = bar.getClientRect({ relativeTo: stage, skipShadow: true });
8690
bar.position(
87-
actionBarPosition(sel, barRect.width / 2, barRect.height / 2, stage.width(), stage.height()),
91+
actionBarPosition(sel, barRect.width / 2, barRect.height / 2, stage.width(), stage.height(), topInset),
8892
);
8993
}
9094

@@ -106,5 +110,5 @@ export function useSelectionActionBar({
106110
return () => {
107111
layer?.off(".actionbar");
108112
};
109-
}, [stageRef, attachableIds, lockedLeafIds, editorFrozen, dragActiveRef, actionBarRef, lockedFrameRef, getBarBounds]);
113+
}, [stageRef, attachableIds, lockedLeafIds, editorFrozen, dragActiveRef, actionBarRef, lockedFrameRef, getBarBounds, topInset]);
110114
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.