Skip to content
Snippets Groups Projects
Commit 9259650f authored by Chris Beer's avatar Chris Beer
Browse files

Reconcile window + workspace position coordinate systems in our state

parent 3e71fa16
Branches ci-setup
No related tags found
No related merge requests found
...@@ -18,8 +18,8 @@ describe('window actions', () => { ...@@ -18,8 +18,8 @@ describe('window actions', () => {
manifestId: null, manifestId: null,
maximized: false, maximized: false,
rangeId: null, rangeId: null,
x: 2700, x: 200,
y: 2700, y: 200,
sideBarPanel: 'info', sideBarPanel: 'info',
width: 400, width: 400,
height: 400, height: 400,
......
...@@ -13,6 +13,8 @@ function createWrapper(props) { ...@@ -13,6 +13,8 @@ function createWrapper(props) {
viewportPosition: { viewportPosition: {
x: 20, x: 20,
y: 20, y: 20,
width: 5000,
height: 5000,
}, },
}} }}
setWorkspaceViewportPosition={() => {}} setWorkspaceViewportPosition={() => {}}
...@@ -59,8 +61,8 @@ describe('WorkspaceElastic', () => { ...@@ -59,8 +61,8 @@ describe('WorkspaceElastic', () => {
.at(2) .at(2)
.props().position) .props().position)
.toEqual({ .toEqual({
x: 25, x: 2525,
y: 25, y: 2525,
}); });
expect(wrapper expect(wrapper
.find(Rnd) .find(Rnd)
...@@ -92,8 +94,8 @@ describe('WorkspaceElastic', () => { ...@@ -92,8 +94,8 @@ describe('WorkspaceElastic', () => {
y: 200, y: 200,
}); });
expect(mockDragStop).toHaveBeenCalledWith(1, { expect(mockDragStop).toHaveBeenCalledWith(1, {
x: 200, x: -2300,
y: 200, y: -2300,
}); });
}); });
it('when windows are resized', () => { it('when windows are resized', () => {
...@@ -111,10 +113,12 @@ describe('WorkspaceElastic', () => { ...@@ -111,10 +113,12 @@ describe('WorkspaceElastic', () => {
width: 400, width: 400,
height: 200, height: 200,
}, },
}); }, {}, { x: 0, y: 0 });
expect(mockOnResize).toHaveBeenCalledWith(1, { expect(mockOnResize).toHaveBeenCalledWith(1, {
width: 400, width: 400,
height: 200, height: 200,
x: -2500,
y: -2500,
}); });
}); });
}); });
...@@ -135,8 +139,8 @@ describe('WorkspaceElastic', () => { ...@@ -135,8 +139,8 @@ describe('WorkspaceElastic', () => {
y: 200, y: 200,
}); });
expect(mockDragStop).toHaveBeenCalledWith({ expect(mockDragStop).toHaveBeenCalledWith({
x: 200, x: 2700,
y: 200, y: 2700,
}); });
}); });
}); });
......
...@@ -20,13 +20,21 @@ class WorkspaceElastic extends React.Component { ...@@ -20,13 +20,21 @@ class WorkspaceElastic extends React.Component {
updateWindowPosition, updateWindowPosition,
setWindowSize, setWindowSize,
} = this.props; } = this.props;
const { viewportPosition } = workspace;
const offsetX = viewportPosition.width / 2;
const offsetY = viewportPosition.height / 2;
return ( return (
<div style={{ position: 'relative', width: '100%', height: '100%' }}>
<Rnd <Rnd
default={{ default={{
width: 5000, width: viewportPosition.width,
height: 5000, height: viewportPosition.height,
}}
position={{
x: viewportPosition.x - offsetX, y: viewportPosition.y - offsetY,
}} }}
position={{ x: workspace.viewportPosition.x, y: workspace.viewportPosition.y }}
enableResizing={{ enableResizing={{
top: false, top: false,
right: false, right: false,
...@@ -38,7 +46,7 @@ class WorkspaceElastic extends React.Component { ...@@ -38,7 +46,7 @@ class WorkspaceElastic extends React.Component {
topLeft: false, topLeft: false,
}} }}
onDragStop={(e, d) => { onDragStop={(e, d) => {
setWorkspaceViewportPosition({ x: d.x, y: d.y }); setWorkspaceViewportPosition({ x: d.x + offsetX, y: d.y + offsetY });
}} }}
cancel={`.${ns('window')}`} cancel={`.${ns('window')}`}
className={ns('workspace')} className={ns('workspace')}
...@@ -48,16 +56,17 @@ class WorkspaceElastic extends React.Component { ...@@ -48,16 +56,17 @@ class WorkspaceElastic extends React.Component {
<Rnd <Rnd
key={window.id} key={window.id}
size={{ width: window.width, height: window.height }} size={{ width: window.width, height: window.height }}
position={{ x: window.x, y: window.y }} position={{ x: window.x + offsetX, y: window.y + offsetY }}
bounds="parent" bounds="parent"
onDragStop={(e, d) => { onDragStop={(e, d) => {
updateWindowPosition(window.id, { x: d.x, y: d.y }); updateWindowPosition(window.id, { x: d.x - offsetX, y: d.y - offsetY });
}} }}
onResize={(e, direction, ref, delta, position) => { onResize={(e, direction, ref, delta, position) => {
setWindowSize(window.id, { setWindowSize(window.id, {
width: ref.style.width, width: ref.style.width,
height: ref.style.height, height: ref.style.height,
...position, x: position.x - offsetX,
y: position.y - offsetY,
}); });
}} }}
dragHandleClassName={ns('window-top-bar')} dragHandleClassName={ns('window-top-bar')}
...@@ -72,6 +81,7 @@ class WorkspaceElastic extends React.Component { ...@@ -72,6 +81,7 @@ class WorkspaceElastic extends React.Component {
)) ))
} }
</Rnd> </Rnd>
</div>
); );
} }
} }
......
...@@ -29,8 +29,8 @@ export function addWindow(options) { ...@@ -29,8 +29,8 @@ export function addWindow(options) {
thumbnailNavigationId: cwThumbs, thumbnailNavigationId: cwThumbs,
width: 400, width: 400,
height: 400, height: 400,
x: 2700, x: 200,
y: 2700, y: 200,
companionWindowIds: [cwDefault, cwThumbs], companionWindowIds: [cwDefault, cwThumbs],
sideBarPanel: 'info', sideBarPanel: 'info',
rotation: null, rotation: null,
......
...@@ -6,8 +6,10 @@ import ActionTypes from '../actions/action-types'; ...@@ -6,8 +6,10 @@ import ActionTypes from '../actions/action-types';
export const workspaceReducer = ( export const workspaceReducer = (
state = { // we'll need to abstract this more, methinks. state = { // we'll need to abstract this more, methinks.
viewportPosition: { viewportPosition: {
x: -2500, x: 0,
y: -2500, y: 0,
width: 5000,
height: 5000,
}, },
exposeModeOn: false, exposeModeOn: false,
}, },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment