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:
parent
8b0854c49f
commit
fcc809092a
1 changed files with 10 additions and 0 deletions
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue