Fixed getVisualCenter to take into account the label

This commit is contained in:
Daniel Maya 2019-07-02 17:32:46 +02:00
parent c6057037dd
commit dffe03aaa8
1 changed files with 38 additions and 8 deletions

View File

@ -578,14 +578,44 @@ export default class VisualConsole {
position: Position,
element: Item<ItemProps>
): Position {
// TODO: Perform a better calculation taking into account the lablel
// position of the element.
const x = position.x + element.elementRef.clientWidth / 2;
const y =
position.y +
(element.elementRef.clientHeight - element.labelElementRef.clientHeight) /
2;
let x = position.x + element.elementRef.clientWidth / 2;
let y = position.y + element.elementRef.clientHeight / 2;
if (
typeof element.props.label !== "undefined" ||
element.props.label !== "" ||
element.props.label !== null
) {
switch (element.props.labelPosition) {
case "up":
y =
position.y +
(element.elementRef.clientHeight +
element.labelElementRef.clientHeight) /
2;
break;
case "down":
y =
position.y +
(element.elementRef.clientHeight -
element.labelElementRef.clientHeight) /
2;
break;
case "right":
x =
position.x +
(element.elementRef.clientWidth -
element.labelElementRef.clientWidth) /
2;
break;
case "left":
x =
position.x +
(element.elementRef.clientWidth +
element.labelElementRef.clientWidth) /
2;
break;
}
}
return { x, y };
}