Revert "Center windows correctly, even if the windows don't start at 0,0"

This reverts commit 777d482e73.
This commit is contained in:
Jordan Eldredge 2018-10-01 12:50:21 -07:00 committed by GitHub
parent da46fe1796
commit 73de91abc0
2 changed files with 12 additions and 19 deletions

View file

@ -64,15 +64,12 @@ class WindowManager extends React.Component {
const boxWidth = bounding.right - bounding.left;
const move = {
x: Math.ceil(offsetLeft - bounding.left + (width - boxWidth) / 2),
y: Math.ceil(offsetTop - bounding.top + (height - boxHeight) / 2)
x: Math.ceil(offsetLeft + (width - boxWidth) / 2),
y: Math.ceil(offsetTop + (height - boxHeight) / 2)
};
const newPositions = this.props.windowsInfo.reduce(
(pos, w) => ({
...pos,
[w.key]: { x: move.x + w.x, y: move.y + w.y }
}),
(pos, w) => ({ ...pos, [w.key]: { x: move.x + w.x, y: move.y + w.y } }),
{}
);

View file

@ -328,19 +328,15 @@ interface Window {
}
export const calculateBoundingBox = (windows: Window[]) =>
windows
.map(w => ({
left: w.x,
top: w.y,
bottom: w.y + w.height,
right: w.x + w.width
}))
.reduce((b, w) => ({
left: Math.min(b.left, w.left),
top: Math.min(b.top, w.top),
bottom: Math.max(b.bottom, w.bottom),
right: Math.max(b.right, w.right)
}));
windows.reduce(
(b, w) => ({
left: Math.min(b.left, w.x),
top: Math.min(b.top, w.y),
bottom: Math.max(b.bottom, w.y + w.height),
right: Math.max(b.right, w.x + w.width)
}),
{ top: 0, bottom: 0, left: 0, right: 0 }
);
export function findLastIndex<T>(arr: T[], cb: (val: T) => boolean) {
for (let i = arr.length - 1; i >= 0; i--) {