Skip to content
Snippets Groups Projects
Commit d40ad736 authored by chrisgarrity's avatar chrisgarrity
Browse files

Positioning custom-procedure blocks in RTL

parent a0d6d049
No related branches found
No related tags found
No related merge requests found
...@@ -19,6 +19,7 @@ class CustomProcedures extends React.Component { ...@@ -19,6 +19,7 @@ class CustomProcedures extends React.Component {
'setBlocks' 'setBlocks'
]); ]);
this.state = { this.state = {
rtlOffset: 0,
warp: false warp: false
}; };
} }
...@@ -55,11 +56,46 @@ class CustomProcedures extends React.Component { ...@@ -55,11 +56,46 @@ class CustomProcedures extends React.Component {
const metrics = this.workspace.getMetrics(); const metrics = this.workspace.getMetrics();
const {x, y} = this.mutationRoot.getRelativeToSurfaceXY(); const {x, y} = this.mutationRoot.getRelativeToSurfaceXY();
const dy = (metrics.viewHeight / 2) - (this.mutationRoot.height / 2) - y; const dy = (metrics.viewHeight / 2) - (this.mutationRoot.height / 2) - y;
let dx = (metrics.viewWidth / 2) - (this.mutationRoot.width / 2) - x; let dx;
// If the procedure declaration is wider than the view width, if (this.props.isRtl) {
// keep the right-hand side of the procedure in view. // HACK!! This is temporary until we can figure out what's going on width
if (this.mutationRoot.width > metrics.viewWidth) { // block positioning on the workspace for RTL.
dx = metrics.viewWidth - this.mutationRoot.width - x; // Workspace is always origin top-left, with x increasing to the right
// Calculate initial starting offset and save it, every other move
// has to take the original offset into account.
// Calculate a new left postion based on new width
// Convert current x position into LTR (mirror) x position (uses original offset)
// Use the difference between ltrX and mirrorX as the amount to move
const ltrX = ((metrics.viewWidth / 2) - (this.mutationRoot.width / 2) + 25);
const mirrorX = x - ((x - this.state.rtlOffset) * 2);
if (mirrorX === ltrX) {
return;
}
dx = mirrorX - ltrX;
const midPoint = metrics.viewWidth / 2;
if (x === 0) {
// if it's the first time positioning, it should always move right
if (this.mutationRoot.width < midPoint) {
dx = ltrX;
} else if (this.mutationRoot.width < metrics.viewWidth) {
dx = midPoint - ((metrics.viewWidth - this.mutationRoot.width) / 2);
} else {
dx = midPoint + (this.mutationRoot.width - metrics.viewWidth);
}
this.mutationRoot.moveBy(dx, dy);
this.setState({rtlOffset: this.mutationRoot.getRelativeToSurfaceXY().x});
return;
}
if (this.mutationRoot.width > metrics.viewWidth) {
dx = dx + this.mutationRoot.width - metrics.viewWidth;
}
} else {
dx = (metrics.viewWidth / 2) - (this.mutationRoot.width / 2) - x;
// If the procedure declaration is wider than the view width,
// keep the right-hand side of the procedure in view.
if (this.mutationRoot.width > metrics.viewWidth) {
dx = metrics.viewWidth - this.mutationRoot.width - x;
}
} }
this.mutationRoot.moveBy(dx, dy); this.mutationRoot.moveBy(dx, dy);
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment