Skip to content
Snippets Groups Projects
Commit 26e3404d authored by Andrew Winget (Standard)'s avatar Andrew Winget (Standard)
Browse files

add bounding box function

parent 397eb358
No related branches found
No related tags found
No related merge requests found
...@@ -15,11 +15,13 @@ class WorkspaceElastic extends React.Component { ...@@ -15,11 +15,13 @@ class WorkspaceElastic extends React.Component {
render() { render() {
const { const {
workspace, workspace,
boundingBox,
windows, windows,
setWorkspaceViewportPosition, setWorkspaceViewportPosition,
updateWindowPosition, updateWindowPosition,
setWindowSize, setWindowSize,
} = this.props; } = this.props;
console.log(boundingBox);
return ( return (
<Rnd <Rnd
default={{ default={{
...@@ -77,6 +79,7 @@ WorkspaceElastic.propTypes = { ...@@ -77,6 +79,7 @@ WorkspaceElastic.propTypes = {
setWorkspaceViewportPosition: PropTypes.func.isRequired, setWorkspaceViewportPosition: PropTypes.func.isRequired,
windows: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types windows: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
workspace: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types workspace: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
boundingBox: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
updateWindowPosition: PropTypes.func.isRequired, updateWindowPosition: PropTypes.func.isRequired,
setWindowSize: PropTypes.func.isRequired, setWindowSize: PropTypes.func.isRequired,
}; };
......
...@@ -18,7 +18,7 @@ export default { ...@@ -18,7 +18,7 @@ export default {
height: 150, height: 150,
}, },
workspace: { workspace: {
type: 'freeform', type: 'elastic',
}, },
workspaceControlPanel: { workspaceControlPanel: {
enabled: true, enabled: true,
......
import { compose } from 'redux'; import { compose } from 'redux';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import * as actions from '../state/actions'; import * as actions from '../state/actions';
import { getWorkspaceBoundingBox } from '../state/selectors';
import WorkspaceElastic from '../components/WorkspaceElastic'; import WorkspaceElastic from '../components/WorkspaceElastic';
/** /**
...@@ -10,6 +11,7 @@ import WorkspaceElastic from '../components/WorkspaceElastic'; ...@@ -10,6 +11,7 @@ import WorkspaceElastic from '../components/WorkspaceElastic';
*/ */
const mapStateToProps = state => ( const mapStateToProps = state => (
{ {
boundingBox: getWorkspaceBoundingBox(state.windows),
workspace: state.workspace, workspace: state.workspace,
windows: state.windows, windows: state.windows,
} }
......
...@@ -9,7 +9,7 @@ export const workspaceReducer = ( ...@@ -9,7 +9,7 @@ export const workspaceReducer = (
x: -2500, x: -2500,
y: -2500, y: -2500,
}, },
exposedModeOn: false, exposeModeOn: false,
}, },
action, action,
) => { ) => {
...@@ -27,7 +27,7 @@ export const workspaceReducer = ( ...@@ -27,7 +27,7 @@ export const workspaceReducer = (
case ActionTypes.SET_WORKSPACE_VIEWPORT_POSITION: case ActionTypes.SET_WORKSPACE_VIEWPORT_POSITION:
return { ...state, viewportPosition: action.payload.position }; return { ...state, viewportPosition: action.payload.position };
case ActionTypes.TOGGLE_WORKSPACE_EXPOSE_MODE: case ActionTypes.TOGGLE_WORKSPACE_EXPOSE_MODE:
return { ...state, exposeModeOn: !state.exposedModeOn }; return { ...state, exposeModeOn: !state.exposeModeOn };
default: default:
return state; return state;
} }
......
...@@ -189,3 +189,23 @@ export function getCompanionWindowForPosition(state, windowId, position) { ...@@ -189,3 +189,23 @@ export function getCompanionWindowForPosition(state, windowId, position) {
&& state.windows[windowId].companionWindows && state.windows[windowId].companionWindows
&& state.windows[windowId].companionWindows[position]; && state.windows[windowId].companionWindows[position];
} }
/**
* Return the bounding box for all open windows in the elastic workspace
* in workspace coordinates
* @param {object} state
* @return {object}
*/
export function getWorkspaceBoundingBox(windows) {
const windowObjects = Object.values(windows);
const minX = Math.min(...windowObjects.map(win => win.x));
const minY = Math.min(...windowObjects.map(win => win.y));
const maxX = Math.max(...windowObjects.map(win => win.x + win.width));
const maxY = Math.max(...windowObjects.map(win => win.y + win.height));
return {
x: minX,
y: minY,
width: maxX - minX,
height: maxY - minY,
};
}
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
right: 0; right: 0;
bottom: 0; bottom: 0;
left: 0; left: 0;
overflow: hidden;
} }
&-workspace-viewport { &-workspace-viewport {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment