1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/web/ synced 2025-03-09 00:00:01 +01:00

Snap widget on grid while adding

This commit is contained in:
Markus Grigull 2017-07-28 16:42:41 +02:00
parent 8b0854c49f
commit fcc809092a

View file

@ -155,6 +155,12 @@ class Visualization extends Component {
});
}
snapToGrid(value) {
if (this.state.visualization.grid === 1) return value;
return Math.round(value / this.state.visualization.grid) * this.state.visualization.grid;
}
handleDrop(item, position) {
let widget = null;
@ -166,6 +172,10 @@ class Visualization extends Component {
defaultSimulator = this.state.simulation.models[0].simulator;
}
// snap position to grid
position.x = this.snapToGrid(position.x);
position.y = this.snapToGrid(position.y);
// create new widget
widget = WidgetFactory.createWidgetOfType(item.name, position, defaultSimulator);