From 8e985669ed42b1d82a712081a98935b7aff1561c Mon Sep 17 00:00:00 2001 From: casperlamboo Date: Mon, 13 Nov 2017 12:42:35 +0100 Subject: [PATCH] better resize handling --- example/index.js | 5 ++-- package-lock.json | 8 ++++++ package.json | 1 + src/interface/Settings.js | 12 +++----- src/interface/index.js | 60 +++++++++++++++++++++++---------------- src/interface/utils.js | 4 +-- 6 files changed, 53 insertions(+), 37 deletions(-) diff --git a/example/index.js b/example/index.js index 525bc1a..0bc3d8e 100644 --- a/example/index.js +++ b/example/index.js @@ -11,6 +11,9 @@ injectTapEventPlugin(); document.body.style.margin = 0; document.body.style.padding = 0; +document.body.style.height = '100%'; +document.documentElement.style.height = '100%' +document.getElementById('app').style.height = '100%'; const downloadGCode = gcode => { const file = new File([gcode], 'gcode.gcode', { type: 'text/plain' }); @@ -23,8 +26,6 @@ jsonLoader.load(fileURL, geometry => { diff --git a/package-lock.json b/package-lock.json index 741be63..1ffc9fe 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3362,6 +3362,14 @@ "theming": "1.1.0" } }, + "react-resize-detector": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/react-resize-detector/-/react-resize-detector-1.1.0.tgz", + "integrity": "sha512-68KVcQlhcWQGXMAie82YueCa4f4yqwEoiQbVyYlSgJEin1zMtNBLLeU/+6FLNf1TTgjwSfpbMTJTw/uU0HNgtQ==", + "requires": { + "prop-types": "15.6.0" + } + }, "react-transition-group": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/react-transition-group/-/react-transition-group-1.2.1.tgz", diff --git a/package.json b/package.json index 147bc09..a73afdb 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "react": "^16.1.0", "react-dom": "^16.1.0", "react-jss": "^7.2.0", + "react-resize-detector": "^1.1.0", "three": "^0.83.0" }, "devDependencies": { diff --git a/src/interface/Settings.js b/src/interface/Settings.js index 703cf30..edf99f0 100644 --- a/src/interface/Settings.js +++ b/src/interface/Settings.js @@ -10,10 +10,6 @@ import { grey500 } from 'material-ui/styles/colors'; const styles = { textFieldRow: { display: 'flex' - }, - content: { - maxHeight: '500px', - overflowY: 'auto' } }; @@ -59,8 +55,8 @@ class Settings extends React.Component { return ( - -
+ +
{Object.entries(printers).map(([value, { title }]) => ( @@ -78,8 +74,8 @@ class Settings extends React.Component {
- -
+ +
diff --git a/src/interface/index.js b/src/interface/index.js index 1ff206a..f7588b8 100644 --- a/src/interface/index.js +++ b/src/interface/index.js @@ -6,34 +6,40 @@ import { placeOnGround, createScene, createGcodeGeometry } from './utils.js'; import injectSheet from 'react-jss'; import { sliceGeometry } from '../slicer.js'; import RaisedButton from 'material-ui/RaisedButton'; -import Paper from 'material-ui/Paper'; import Slider from 'material-ui/Slider'; -import { grey50 } from 'material-ui/styles/colors'; +import { grey100, grey300 } from 'material-ui/styles/colors'; import Settings from './Settings.js'; import baseSettings from '../settings/default.yml'; import printerSettings from '../settings/printer.yml'; import materialSettings from '../settings/material.yml'; import qualitySettings from '../settings/quality.yml'; +import ReactResizeDetector from 'react-resize-detector'; const styles = { container: { position: 'relative', - backgroundColor: grey50 - }, - canvas: { - position: 'absolute', + display: 'flex', + height: '100%', + backgroundColor: grey100, + overflow: 'hidden' }, controlBar: { position: 'absolute', bottom: '10px', left: '10px' }, + d3View: { + flexGrow: 1 + }, + canvas: { + position: 'absolute' + }, sliceBar: { - position: 'absolute', - top: '10px', - right: '10px', - width: '380px', - padding: '10px 20px', + width: '240px', + padding: '0 10px', + overflowY: 'auto', + backgroundColor: 'white', + borderLeft: `1px solid ${grey300}` }, overlay: { position: 'absolute', @@ -164,24 +170,34 @@ class Interface extends React.Component { render(); } if (setSize && nextProps.width !== this.props.width || nextProps.height !== this.props.height || nextProps.pixelRatio !== this.props.pixelRatio) { - console.log('update pixel ratio'); setSize(nextProps.width, nextProps.height, nextProps.pixelRatio); } } + onResize = (width, height) => { + window.requestAnimationFrame(() => { + const { setSize } = this.state; + const { pixelRatio } = this.props; + setSize(width, height, pixelRatio); + }); + }; + render() { const { width, height, classes, onCompleteActions, defaultPrinter, defaultQuality, defaultMaterial } = this.props; const { sliced, isSlicing, progress, gcode, controlMode, settings } = this.state; return ( -
- - {!sliced &&
+
+
+ + + {!sliced &&
this.setState({ controlMode: 'translate' })} primary label="translate" /> this.setState({ controlMode: 'rotate' })} primary label="rotate" /> this.setState({ controlMode: 'scale' })} primary label="scale" /> -
} +
} +
{sliced &&
} - {!sliced && + {!sliced &&
- } - {sliced && +
} + {sliced &&
{onCompleteActions.map(({ title, callback }, i) => ( callback(gcode.gcode, settings)} primary label={title} /> ))} - } +
} {isSlicing &&

Slicing: {progress.percentage.toLocaleString(navigator.language, { style: 'percent' })}

    @@ -228,8 +244,6 @@ Interface.propTypes = { throw new Error('invalid prop, is not geometry'); } }, - width: PropTypes.number.isRequired, - height: PropTypes.number.isRequired, classes: PropTypes.objectOf(PropTypes.string), onCompleteActions: PropTypes.arrayOf(PropTypes.shape({ title: PropTypes.string, callback: PropTypes.func })).isRequired, defaultSettings: PropTypes.object.isRequired, @@ -249,8 +263,6 @@ Interface.defaultProps = { defaultQuality: 'medium', material: materialSettings, defaultMaterial: 'pla', - width: 720, - height: 480, pixelRatio: 1 }; diff --git a/src/interface/utils.js b/src/interface/utils.js index eed3915..f59f694 100644 --- a/src/interface/utils.js +++ b/src/interface/utils.js @@ -10,7 +10,7 @@ export function placeOnGround(mesh) { } export function createScene(canvas, props, state) { - const { width, height, geometry, pixelRatio } = props; + const { geometry, pixelRatio } = props; const { controlMode, settings } = state; // center geometry @@ -78,7 +78,5 @@ export function createScene(canvas, props, state) { const { dimensions } = settings; box.scale.set(dimensions.y, dimensions.z, dimensions.x); - setSize(width, height, pixelRatio); - return { control, editorControls, scene, mesh, camera, renderer, render, box, setSize }; }