Skip to content

Commit

Permalink
fix(cursor): optimize cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
ThornWalli committed May 21, 2020
1 parent 2122e40 commit 8b5e649
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/components/environments/atoms/Cursor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ export default {
}[this.cursor.name];
},
style () {
return Object.assign(this.cursor.getVars().reduce((result, name) => { result[`--${name}`] = this.cursor[String(name)]; return result; }, {}), {
'--position-x': `${Math.round(this.position.x)}px`,
'--position-y': `${Math.round(this.position.y)}px`
return Object.assign(this.cursor.toCSSVars(), {
'--position-x': `${this.position.x}px`,
'--position-y': `${this.position.y}px`
});
},
styleClasses () {
Expand All @@ -85,7 +85,7 @@ export default {
touchEvent(e);
global.cancelAnimationFrame(this.animationFrame);
this.animationFrame = global.requestAnimationFrame(() => {
this.position = ipoint(() => Math.min(Math.max(ipoint(e) - this.parentLayout.position - this.offset, 0), this.parentLayout.size));
this.position = ipoint(() => Math.round(Math.min(Math.max(ipoint(e) - this.parentLayout.position - this.offset, 0), this.parentLayout.size)));
});
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/web-workbench/classes/Cursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ class Cursor {
getVars () {
return [];
}

toCSSVars () {
return this.getVars().reduce((result, name) => { result[`--${name}`] = this.cursor[String(name)]; return result; }, {});
}
}

export const CURSOR_TYPES = {
Expand Down

0 comments on commit 8b5e649

Please sign in to comment.