From 23b2da2c6720c5dd37eb372200e39e7f9de2a827 Mon Sep 17 00:00:00 2001 From: lnd3 Date: Sat, 24 Aug 2024 01:42:04 +0200 Subject: [PATCH] Fix a scaling issue. --- .../rendering/source/common/ui/UIVisitors.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/rendering/source/common/ui/UIVisitors.cpp b/packages/rendering/source/common/ui/UIVisitors.cpp index c759fb00..77d200dd 100644 --- a/packages/rendering/source/common/ui/UIVisitors.cpp +++ b/packages/rendering/source/common/ui/UIVisitors.cpp @@ -178,22 +178,27 @@ namespace l::ui { splineThickness = container.HasNotification(UIContainer_LinkFlag) ? 2.0f * splineThickness : splineThickness; ImVec2 pLinkInput = container.GetParent()->GetPosition(); p1 = contentArea.Transform(ImVec2(), input.mRootPos); - p11 = contentArea.Transform(ImVec2(pLinkInput.x + 120.0f, pLinkInput.y), input.mRootPos); if (container.GetCoParent() != nullptr) { ImVec2 pLinkOutput = container.GetCoParent()->GetPosition(); auto& coContentArea = container.GetCoParent()->GetLayoutArea(); p2 = coContentArea.Transform(pLinkOutput, input.mRootPos); - p22 = coContentArea.Transform(ImVec2(pLinkOutput.x - 120.0f, pLinkOutput.y), input.mRootPos); + float d12 = sqrt(0.25f*((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y)) / (contentArea.mScale * contentArea.mScale)); + + p11 = contentArea.Transform(ImVec2(pLinkInput.x + d12, pLinkInput.y), input.mRootPos); + p22 = coContentArea.Transform(ImVec2(pLinkOutput.x - d12, pLinkOutput.y), input.mRootPos); } else { p2 = input.mCurPos; - p22 = ImVec2(p2.x - 120.0f, p2.y); + float d12 = sqrt(0.25f * ((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y)) / (contentArea.mScale * contentArea.mScale)); + p11 = contentArea.Transform(ImVec2(pLinkInput.x + d12, pLinkInput.y), input.mRootPos); + p22 = ImVec2(p2.x - d12 * contentArea.mScale, p2.y); } } else { - p11 = contentArea.Transform(ImVec2(pTopLeft.x + 120.0f, pTopLeft.y), input.mRootPos); - p22 = contentArea.Transform(ImVec2(pLowRight.x - 120.0f, pLowRight.y), input.mRootPos); + float d12 = sqrt(0.25f * ((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y))); + p11 = contentArea.Transform(ImVec2(pTopLeft.x + d12, pTopLeft.y), input.mRootPos); + p22 = contentArea.Transform(ImVec2(pLowRight.x - d12, pLowRight.y), input.mRootPos); } mDrawList->AddBezierCubic(p1, p11, p22, p2, color, splineThickness, 30); break;