From 66ccc254f0d6690429ecb7a86a0b51eec409eac3 Mon Sep 17 00:00:00 2001 From: Aakansha Doshi Date: Wed, 26 Apr 2023 18:01:49 +0530 Subject: [PATCH] feat: vertical align for labelled arrows --- src/element/linearElementEditor.ts | 16 +++++++++++++++- src/element/textElement.ts | 6 +++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/element/linearElementEditor.ts b/src/element/linearElementEditor.ts index aedc25974..b0178300a 100644 --- a/src/element/linearElementEditor.ts +++ b/src/element/linearElementEditor.ts @@ -40,7 +40,11 @@ import { isBindingElement } from "./typeChecks"; import { shouldRotateWithDiscreteAngle } from "../keys"; import { getBoundTextElement, handleBindTextResize } from "./textElement"; import { getShapeForElement } from "../renderer/renderElement"; -import { DRAGGING_THRESHOLD } from "../constants"; +import { + BOUND_TEXT_PADDING, + DRAGGING_THRESHOLD, + VERTICAL_ALIGN, +} from "../constants"; import { Mutable } from "../utility-types"; const editorMidPointsCache: { @@ -1304,6 +1308,16 @@ export class LinearElementEditor { } x = midSegmentMidpoint[0] - boundTextElement.width / 2; y = midSegmentMidpoint[1] - boundTextElement.height / 2; + if (element.points.length === 2) { + if (boundTextElement.verticalAlign === VERTICAL_ALIGN.TOP) { + y = + midSegmentMidpoint[1] - + boundTextElement.height - + BOUND_TEXT_PADDING * 2; + } else if (boundTextElement.verticalAlign === VERTICAL_ALIGN.BOTTOM) { + y = midSegmentMidpoint[1] + BOUND_TEXT_PADDING * 2; + } + } } return { x, y }; }; diff --git a/src/element/textElement.ts b/src/element/textElement.ts index a6d0c3271..fb145d169 100644 --- a/src/element/textElement.ts +++ b/src/element/textElement.ts @@ -793,7 +793,11 @@ export const shouldAllowVerticalAlign = ( const hasBoundContainer = isBoundToContainer(element); if (hasBoundContainer) { const container = getContainerElement(element); - if (isTextElement(element) && isArrowElement(container)) { + if ( + isTextElement(element) && + isArrowElement(container) && + container.points.length > 2 + ) { return false; } return true;