Browse Source

Adjust drag method in Dragger

drag-rules
Artur Arseniev 8 years ago
parent
commit
adc93ffa23
  1. 1
      src/commands/view/ComponentDrag.js
  2. 17
      src/utils/Dragger.js

1
src/commands/view/ComponentDrag.js

@ -113,6 +113,7 @@ module.exports = {
case 'l': case 'l':
return (item.x = left); return (item.x = left);
case 'r': case 'r':
console.log('left', left, 'width', width, 'x: ', left + width);
return (item.x = left + width); return (item.x = left + width);
case 'x': case 'x':
return (item.x = left + width / 2); return (item.x = left + width / 2);

17
src/utils/Dragger.js

@ -127,24 +127,31 @@ export default class Dragger {
} }
let { trgX, trgY } = this; let { trgX, trgY } = this;
const offset = 20;
this.guidesTarget.forEach(trg => { this.guidesTarget.forEach(trg => {
trg.active = 0;
// Skip the guide if its locked axis already exists // Skip the guide if its locked axis already exists
// TODO: allow near axis change (using diff) // TODO: allow near axis change (using diff)
if ((trg.x && this.trgX) || (trg.y && this.trgY)) return; if ((trg.x && this.trgX) || (trg.y && this.trgY)) return;
trg.active = 0;
this.guidesStatic.forEach(stat => { this.guidesStatic.forEach(stat => {
if ((trg.y && stat.x) || (trg.x && stat.y)) return; if ((trg.y && stat.x) || (trg.x && stat.y)) return;
const isY = trg.y && stat.y; const isY = trg.y && stat.y;
const trgPoint = isY ? trg.y : trg.x; const axs = isY ? 'y' : 'x';
const dirX = this.delta ? (delta[axs] < this.delta[axs] ? -1 : 1) : 0;
const trgPoint = isY ? trg.y : trg.x + dirX;
const statPoint = isY ? stat.y : stat.x; const statPoint = isY ? stat.y : stat.x;
const deltaPoint = isY ? delta.y : delta.x; const deltaPoint = isY ? delta.y : delta.x;
const trgGuide = isY ? trgY : trgX; const trgGuide = isY ? trgY : trgX;
if (this.isPointIn(trgPoint, statPoint)) { if (this.isPointIn(trgPoint, statPoint)) {
if (isUndefined(trgGuide)) { if (isUndefined(trgGuide)) {
console.log(
`LOCK ${
isY ? 'Y' : 'X'
} trgPoint: ${trgPoint} statPoint ${statPoint} diff: ${trgPoint -
statPoint} delta.x: ${delta.x}`
);
const trgValue = deltaPoint - (trgPoint - statPoint); const trgValue = deltaPoint - (trgPoint - statPoint);
this.setGuideLock(trg, trgValue); this.setGuideLock(trg, trgValue);
} }
@ -165,6 +172,7 @@ export default class Dragger {
} }
if (trg && !isUndefined(trg.lock)) { if (trg && !isUndefined(trg.lock)) {
const offset = 20;
console.log( console.log(
`locked ${axis} at: ${trg.lock}`, `locked ${axis} at: ${trg.lock}`,
`(type: ${trg.type})`, `(type: ${trg.type})`,
@ -175,6 +183,7 @@ export default class Dragger {
} }
}); });
const deltaPre = { ...delta };
['x', 'y'].forEach(co => (delta[co] = delta[co] * result(opts, 'scale'))); ['x', 'y'].forEach(co => (delta[co] = delta[co] * result(opts, 'scale')));
this.lockedAxis = lockedAxis; this.lockedAxis = lockedAxis;
this.delta = delta; this.delta = delta;

Loading…
Cancel
Save