Skip to content

Commit 03ba0c7

Browse files
authored
[DevTools] Include some sub-pixel precision in rects (#34873)
Currently the sub-pixel precision is lost which can lead to things not lining up properly and being slightly off or overlapping. We need some sub-pixel precision. Ideally we'd just keep the floating point as is. I'm not sure why the operations is limited to integers. We don't send it as a typed array anyway it seems which would ideally be more optimal. Even if we did, we haven't defined a precision for the protocol. Is it 32bit integer? 64bit? If it's 64bit we can fit a float anyway. Ideally it would be more variable precision like just pushing into a typed array directly with the option to write whatever precision we want.
1 parent 4e00747 commit 03ba0c7

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

packages/react-devtools-shared/src/backend/fiber/renderer.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2693,10 +2693,10 @@ export function attach(
26932693
pushOperation(rects.length);
26942694
for (let i = 0; i < rects.length; ++i) {
26952695
const rect = rects[i];
2696-
pushOperation(Math.round(rect.x));
2697-
pushOperation(Math.round(rect.y));
2698-
pushOperation(Math.round(rect.width));
2699-
pushOperation(Math.round(rect.height));
2696+
pushOperation(Math.round(rect.x * 1000));
2697+
pushOperation(Math.round(rect.y * 1000));
2698+
pushOperation(Math.round(rect.width * 1000));
2699+
pushOperation(Math.round(rect.height * 1000));
27002700
}
27012701
}
27022702
}
@@ -2765,10 +2765,10 @@ export function attach(
27652765
pushOperation(rects.length);
27662766
for (let i = 0; i < rects.length; ++i) {
27672767
const rect = rects[i];
2768-
pushOperation(Math.round(rect.x));
2769-
pushOperation(Math.round(rect.y));
2770-
pushOperation(Math.round(rect.width));
2771-
pushOperation(Math.round(rect.height));
2768+
pushOperation(Math.round(rect.x * 1000));
2769+
pushOperation(Math.round(rect.y * 1000));
2770+
pushOperation(Math.round(rect.width * 1000));
2771+
pushOperation(Math.round(rect.height * 1000));
27722772
}
27732773
}
27742774
}

packages/react-devtools-shared/src/devtools/store.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,10 +1587,10 @@ export default class Store extends EventEmitter<{
15871587
} else {
15881588
rects = [];
15891589
for (let rectIndex = 0; rectIndex < numRects; rectIndex++) {
1590-
const x = operations[i + 0];
1591-
const y = operations[i + 1];
1592-
const width = operations[i + 2];
1593-
const height = operations[i + 3];
1590+
const x = operations[i + 0] / 1000;
1591+
const y = operations[i + 1] / 1000;
1592+
const width = operations[i + 2] / 1000;
1593+
const height = operations[i + 3] / 1000;
15941594
rects.push({x, y, width, height});
15951595
i += 4;
15961596
}
@@ -1763,10 +1763,10 @@ export default class Store extends EventEmitter<{
17631763
} else {
17641764
nextRects = [];
17651765
for (let rectIndex = 0; rectIndex < numRects; rectIndex++) {
1766-
const x = operations[i + 0];
1767-
const y = operations[i + 1];
1768-
const width = operations[i + 2];
1769-
const height = operations[i + 3];
1766+
const x = operations[i + 0] / 1000;
1767+
const y = operations[i + 1] / 1000;
1768+
const width = operations[i + 2] / 1000;
1769+
const height = operations[i + 3] / 1000;
17701770

17711771
nextRects.push({x, y, width, height});
17721772

0 commit comments

Comments
 (0)