diff --git a/platform/features/layout/res/templates/layout.html b/platform/features/layout/res/templates/layout.html index 4899dcf3f2..4b13ae028d 100644 --- a/platform/features/layout/res/templates/layout.html +++ b/platform/features/layout/res/templates/layout.html @@ -11,6 +11,14 @@ + + + + + \ No newline at end of file diff --git a/platform/features/layout/src/LayoutController.js b/platform/features/layout/src/LayoutController.js index e0aa63f9c7..d5717224aa 100644 --- a/platform/features/layout/src/LayoutController.js +++ b/platform/features/layout/src/LayoutController.js @@ -1,15 +1,17 @@ /*global define*/ define( - [], - function () { + ['./LayoutDrag'], + function (LayoutDrag) { "use strict"; - var DEFAULT_DIMENSIONS = [ 4, 2 ]; + var DEFAULT_DIMENSIONS = [ 12, 8 ]; function LayoutController($scope) { - var width = 16, - height = 16, + var width = 32, + height = 32, + activeDrag, + activeDragId, rawPositions = {}, positions = {}; @@ -30,8 +32,10 @@ define( } function populatePosition(id, index) { - rawPositions[id] = rawPositions[id] || defaultPosition(index); - positions[id] = convertPosition(rawPositions[id]); + rawPositions[id] = + rawPositions[id] || defaultPosition(index || 0); + positions[id] = + convertPosition(rawPositions[id]); } function lookupPanels(model) { @@ -55,14 +59,24 @@ define( getFrameStyle: function (id) { return positions[id]; }, - startDrag: function (event) { - console.log("start", event); + startDrag: function (id, posFactor, dimFactor) { + activeDragId = id; + activeDrag = new LayoutDrag( + rawPositions[id], + posFactor, + dimFactor, + [ width, height ] + ); }, - continueDrag: function (event) { - console.log("continue", event); + continueDrag: function (delta) { + if (activeDrag) { + rawPositions[activeDragId] = + activeDrag.getAdjustedPosition(delta); + populatePosition(activeDragId); + } }, - endDrag: function (event) { - console.log("end", event); + endDrag: function () { + // TODO: Mutate, persist } }; diff --git a/platform/features/layout/src/LayoutDrag.js b/platform/features/layout/src/LayoutDrag.js new file mode 100644 index 0000000000..621956f324 --- /dev/null +++ b/platform/features/layout/src/LayoutDrag.js @@ -0,0 +1,56 @@ +/*global define*/ + +define( + [], + function () { + "use strict"; + + function LayoutDrag(rawPosition, posFactor, dimFactor, gridSize) { + function toGridDelta(pixelDelta) { + return pixelDelta.map(function (v, i) { + return Math.round(v / gridSize[i]); + }); + } + + function multiply(array, factors) { + return array.map(function (v, i) { + return v * factors[i]; + }); + } + + function add(array, other) { + return array.map(function (v, i) { + return v + other[i]; + }); + } + + function max(array, other) { + return array.map(function (v, i) { + return Math.max(v, other[i]); + }); + } + + function getAdjustedPosition(pixelDelta) { + var gridDelta = toGridDelta(pixelDelta); + return { + position: max(add( + rawPosition.position, + multiply(gridDelta, posFactor) + ), [0, 0]), + dimensions: max(add( + rawPosition.dimensions, + multiply(gridDelta, dimFactor) + ), [1, 1]) + }; + + } + + return { + getAdjustedPosition: getAdjustedPosition + }; + } + + return LayoutDrag; + + } +); \ No newline at end of file