diff --git a/frameworks/core/components_ng/pattern/bubble/bubble_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/bubble/bubble_layout_algorithm.cpp index 11e8d48ddefa00f8e65d0daa6e51caaf7155a3d8..7b5e233f22919869204038e6f41a9898b5a0838c 100644 --- a/frameworks/core/components_ng/pattern/bubble/bubble_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/bubble/bubble_layout_algorithm.cpp @@ -1616,11 +1616,11 @@ OffsetF BubbleLayoutAlgorithm::AvoidOrCoverParent(const SizeF& childSize, return position; } -Rect BubbleLayoutAlgorithm::GetBottomRect() +Rect BubbleLayoutAlgorithm::GetBottomRect(const Dimension& targetSpace) { Rect rect; float targetOffsetY = targetOffset_.GetY(); - targetOffsetY += (userSetTargetSpace_.ConvertToPx()); + targetOffsetY += (targetSpace.ConvertToPx()); auto y = std::max(targetOffsetY + targetSize_.Height(), marginTop_); auto height = std::min(wrapperSize_.Height() - marginBottom_ - targetOffsetY - targetSize_.Height(), wrapperSize_.Height() - marginBottom_ - marginTop_); @@ -1634,11 +1634,11 @@ Rect BubbleLayoutAlgorithm::GetBottomRect() return rect; } -Rect BubbleLayoutAlgorithm::GetTopRect() +Rect BubbleLayoutAlgorithm::GetTopRect(const Dimension& targetSpace) { Rect rect; float targetOffsetY = targetOffset_.GetY(); - targetOffsetY += (-userSetTargetSpace_.ConvertToPx()); + targetOffsetY += (-targetSpace.ConvertToPx()); auto height = std::min(targetOffsetY - marginTop_, wrapperSize_.Height() - marginTop_ - marginBottom_); rect.SetRect(marginStart_, marginTop_, wrapperSize_.Width() - marginEnd_ - marginStart_, height); if (isHalfFoldHover_) { @@ -1649,11 +1649,11 @@ Rect BubbleLayoutAlgorithm::GetTopRect() return rect; } -Rect BubbleLayoutAlgorithm::GetRightRect() +Rect BubbleLayoutAlgorithm::GetRightRect(const Dimension& targetSpace) { Rect rect; float targetOffsetX = targetOffset_.GetX(); - targetOffsetX += (userSetTargetSpace_.ConvertToPx()); + targetOffsetX += (targetSpace.ConvertToPx()); auto x = std::max(targetOffsetX + targetSize_.Width(), marginStart_); auto width = std::min(wrapperSize_.Width() - targetOffsetX - targetSize_.Width() - marginEnd_, wrapperSize_.Width() - marginStart_ - marginEnd_); @@ -1664,11 +1664,11 @@ Rect BubbleLayoutAlgorithm::GetRightRect() return rect; } -Rect BubbleLayoutAlgorithm::GetLeftRect() +Rect BubbleLayoutAlgorithm::GetLeftRect(const Dimension& targetSpace) { Rect rect; float targetOffsetX = targetOffset_.GetX(); - targetOffsetX += (-userSetTargetSpace_.ConvertToPx()); + targetOffsetX += (-targetSpace.ConvertToPx()); auto width = std::min(targetOffsetX - marginStart_, wrapperSize_.Width() - marginEnd_ - marginStart_); rect.SetRect(marginStart_, marginTop_, width, wrapperSize_.Height() - marginBottom_ - marginTop_); if (isHalfFoldHover_) { @@ -1686,21 +1686,21 @@ OffsetF BubbleLayoutAlgorithm::AvoidToTopOrBottomByWidth( BottomAndTopPosition(bottomPosition, topPosition, childSize); OffsetF resultPosition; auto topHeight = std::min( - targetOffset_.GetY() - userSetTargetSpace_.ConvertToPx() - marginTop_ - BUBBLE_ARROW_HEIGHT.ConvertToPx(), + targetOffset_.GetY() - targetSpace_.ConvertToPx() - marginTop_ - BUBBLE_ARROW_HEIGHT.ConvertToPx(), wrapperSize_.Height() - marginTop_ - marginBottom_); auto bottomHeight = std::min(wrapperSize_.Height() - marginBottom_ - targetOffset_.GetY() - - userSetTargetSpace_.ConvertToPx() - targetSize_.Height() - BUBBLE_ARROW_HEIGHT.ConvertToPx(), + targetSpace_.ConvertToPx() - targetSize_.Height() - BUBBLE_ARROW_HEIGHT.ConvertToPx(), wrapperSize_.Height() - marginBottom_ - marginTop_); if (GreatNotEqual(bottomHeight, topHeight)) { placement_ = Placement::BOTTOM; resultPosition = GetPositionWithPlacementBottom(childSize, topPosition, bottomPosition, arrowPosition); - Rect rect = GetBottomRect(); + Rect rect = GetBottomRect(targetSpace_); auto maxHeight = std::min(rect.Height() - BUBBLE_ARROW_HEIGHT.ConvertToPx(), childSize.Height()); auto maxWidth = std::min(rect.Width(), childSize.Width()); resultSize = SizeF(maxWidth, maxHeight); } else { placement_ = Placement::TOP; - Rect rect = GetTopRect(); + Rect rect = GetTopRect(targetSpace_); auto maxHeight = std::min(rect.Height() - BUBBLE_ARROW_HEIGHT.ConvertToPx(), childSize.Height()); auto maxWidth = std::min(rect.Width(), childSize.Width()); resultSize = SizeF(maxWidth, maxHeight); @@ -1768,7 +1768,7 @@ bool BubbleLayoutAlgorithm::AvoidToTargetBottom( resultPosition = beforePosition; float maxHeight = 0.0f; float maxWidth = 0.0f; - Rect rect = GetBottomRect(); + Rect rect = GetBottomRect(targetSpace_); maxHeight = std::min(rect.Height() - BUBBLE_ARROW_HEIGHT.ConvertToPx(), childSize.Height()); if (placement_ == Placement::BOTTOM_LEFT) { resultPosition = beforePosition; @@ -1807,7 +1807,7 @@ bool BubbleLayoutAlgorithm::AvoidToTargetTop( float bubbleSpacing = scaledBubbleSpacing_; float arrowHalfWidth = BUBBLE_ARROW_WIDTH.ConvertToPx() / BUBBLE_ARROW_HALF; float radius = borderRadius_.ConvertToPx(); - Rect rect = GetTopRect(); + Rect rect = GetTopRect(targetSpace_); float maxHeight = std::min(rect.Height() - BUBBLE_ARROW_HEIGHT.ConvertToPx(), childSize.Height()); if (placement_ == Placement::TOP_LEFT) { OffsetF newTopPosition = OffsetF( @@ -1852,7 +1852,7 @@ bool BubbleLayoutAlgorithm::AvoidToTargetTopMid( float bubbleSpacing = scaledBubbleSpacing_; float arrowHalfWidth = BUBBLE_ARROW_WIDTH.ConvertToPx() / BUBBLE_ARROW_HALF; float radius = borderRadius_.ConvertToPx(); - Rect rect = GetTopRect(); + Rect rect = GetTopRect(targetSpace_); float maxHeight = std::min(rect.Height() - BUBBLE_ARROW_HEIGHT.ConvertToPx(), childSize.Height()); OffsetF newTopPosition = OffsetF(targetOffset_.GetX() + (targetSize_.Width() - childSize.Width()) / HALF, targetOffset_.GetY() - maxHeight - targetSpace_.ConvertToPx() - bubbleSpacing); @@ -1884,7 +1884,7 @@ bool BubbleLayoutAlgorithm::AvoidToTargetRight( resultPosition = beforePosition; float maxHeight = 0.0f; float maxWidth = 0.0f; - Rect rect = GetRightRect(); + Rect rect = GetRightRect(targetSpace_); if (canCompress == false && GreatNotEqual(childSize.Width(), rect.Width() - BUBBLE_ARROW_HEIGHT.ConvertToPx())) { return false; } @@ -1919,7 +1919,7 @@ bool BubbleLayoutAlgorithm::AvoidToTargetLeft( float bubbleSpacing = scaledBubbleSpacing_; float arrowHalfWidth = BUBBLE_ARROW_WIDTH.ConvertToPx() / BUBBLE_ARROW_HALF; float radius = borderRadius_.ConvertToPx(); - Rect rect = GetLeftRect(); + Rect rect = GetLeftRect(targetSpace_); if (canCompress == false && GreatNotEqual(childSize.Width(), rect.Width() - BUBBLE_ARROW_HEIGHT.ConvertToPx())) { return false; } @@ -2363,14 +2363,15 @@ void BubbleLayoutAlgorithm::RecordMaxSpace(const float maxAreaSpace, const Offse bool BubbleLayoutAlgorithm::CheckPositionBottom( const OffsetF& position, const SizeF& childSize, size_t step, size_t& i, const OffsetF& arrowPosition) { - Rect rect = GetBottomRect(); - auto maxHeight = std::min(rect.Height() - BUBBLE_ARROW_HEIGHT.ConvertToPx(), childSize.Height()); - auto maxWidth = std::min(rect.Width(), childSize.Width()); + Rect rect = GetBottomRect(userSetTargetSpace_); + Rect avoidParentRect = GetBottomRect(targetSpace_); + auto maxHeight = std::min(avoidParentRect.Height() - BUBBLE_ARROW_HEIGHT.ConvertToPx(), childSize.Height()); + auto maxWidth = std::min(avoidParentRect.Width(), childSize.Width()); maxHeight = std::max(0.0f, maxHeight); maxWidth = std::max(0.0f, maxWidth); auto maxAreaSpace = maxHeight * maxWidth; auto minHeight = BUBBLE_ARROW_HEIGHT.ConvertToPx() + POPUP_MIN_HEIGHT.ConvertToPx(); - if (GreatNotEqual(rect.Height(), minHeight)) { + if (GreatNotEqual(avoidParentRect.Height(), minHeight)) { canPlacement_.bottom = true; RecordMaxSpace(maxAreaSpace, position, maxWidth, maxHeight, arrowPosition); } @@ -2386,14 +2387,15 @@ bool BubbleLayoutAlgorithm::CheckPositionBottom( bool BubbleLayoutAlgorithm::CheckPositionTop( const OffsetF& position, const SizeF& childSize, size_t step, size_t& i, const OffsetF& arrowPosition) { - Rect rect = GetTopRect(); - auto maxHeight = std::min(rect.Height() - BUBBLE_ARROW_HEIGHT.ConvertToPx(), childSize.Height()); - auto maxWidth = std::min(rect.Width(), childSize.Width()); + Rect rect = GetTopRect(userSetTargetSpace_); + Rect avoidParentRect = GetTopRect(targetSpace_); + auto maxHeight = std::min(avoidParentRect.Height() - BUBBLE_ARROW_HEIGHT.ConvertToPx(), childSize.Height()); + auto maxWidth = std::min(avoidParentRect.Width(), childSize.Width()); maxHeight = std::max(0.0f, maxHeight); maxWidth = std::max(0.0f, maxWidth); auto maxAreaSpace = maxHeight * maxWidth; auto minHeight = BUBBLE_ARROW_HEIGHT.ConvertToPx() + POPUP_MIN_HEIGHT.ConvertToPx(); - if (GreatNotEqual(rect.Height(), minHeight)) { + if (GreatNotEqual(avoidParentRect.Height(), minHeight)) { canPlacement_.top = true; RecordMaxSpace(maxAreaSpace, position, maxWidth, maxHeight, arrowPosition); } @@ -2409,14 +2411,15 @@ bool BubbleLayoutAlgorithm::CheckPositionTop( bool BubbleLayoutAlgorithm::CheckPositionRight( const OffsetF& position, const SizeF& childSize, size_t step, size_t& i, const OffsetF& arrowPosition) { - Rect rect = GetRightRect(); - auto maxHeight = std::min(rect.Height(), childSize.Height()); - auto maxWidth = std::min(rect.Width() - BUBBLE_ARROW_HEIGHT.ConvertToPx(), childSize.Width()); + Rect rect = GetRightRect(userSetTargetSpace_); + Rect avoidParentRect = GetRightRect(targetSpace_); + auto maxHeight = std::min(avoidParentRect.Height(), childSize.Height()); + auto maxWidth = std::min(avoidParentRect.Width() - BUBBLE_ARROW_HEIGHT.ConvertToPx(), childSize.Width()); maxHeight = std::max(0.0f, maxHeight); maxWidth = std::max(0.0f, maxWidth); auto maxAreaSpace = maxHeight * maxWidth; auto minWidth = BUBBLE_ARROW_HEIGHT.ConvertToPx() + POPUP_MIN_WIDTH.ConvertToPx(); - if (GreatNotEqual(rect.Width(), minWidth)) { + if (GreatNotEqual(avoidParentRect.Width(), minWidth)) { canPlacement_.right = true; RecordMaxSpace(maxAreaSpace, position, maxWidth, maxHeight, arrowPosition); } @@ -2432,14 +2435,15 @@ bool BubbleLayoutAlgorithm::CheckPositionRight( bool BubbleLayoutAlgorithm::CheckPositionLeft( const OffsetF& position, const SizeF& childSize, size_t step, size_t& i, const OffsetF& arrowPosition) { - Rect rect = GetLeftRect(); - auto maxHeight = std::min(rect.Height(), childSize.Height()); - auto maxWidth = std::min(rect.Width() - BUBBLE_ARROW_HEIGHT.ConvertToPx(), childSize.Width()); + Rect rect = GetLeftRect(userSetTargetSpace_); + Rect avoidParentRect = GetLeftRect(targetSpace_); + auto maxHeight = std::min(avoidParentRect.Height(), childSize.Height()); + auto maxWidth = std::min(avoidParentRect.Width() - BUBBLE_ARROW_HEIGHT.ConvertToPx(), childSize.Width()); maxHeight = std::max(0.0f, maxHeight); maxWidth = std::max(0.0f, maxWidth); auto maxAreaSpace = maxHeight * maxWidth; auto minWidth = BUBBLE_ARROW_HEIGHT.ConvertToPx() + POPUP_MIN_WIDTH.ConvertToPx(); - if (GreatNotEqual(rect.Width(), minWidth)) { + if (GreatNotEqual(avoidParentRect.Width(), minWidth)) { canPlacement_.left = true; RecordMaxSpace(maxAreaSpace, position, maxWidth, maxHeight, arrowPosition); } @@ -2461,7 +2465,7 @@ bool BubbleLayoutAlgorithm::CheckPosition( case Placement::BOTTOM_LEFT: case Placement::BOTTOM_RIGHT: case Placement::BOTTOM: { - rect = GetBottomRect(); + rect = GetBottomRect(userSetTargetSpace_); if (!CheckPositionBottom(position, childSize, step, i, arrowPosition)) { return false; } @@ -2470,7 +2474,7 @@ bool BubbleLayoutAlgorithm::CheckPosition( case Placement::TOP_LEFT: case Placement::TOP_RIGHT: case Placement::TOP: { - rect = GetTopRect(); + rect = GetTopRect(userSetTargetSpace_); if (!CheckPositionTop(position, childSize, step, i, arrowPosition)) { return false; } @@ -2479,7 +2483,7 @@ bool BubbleLayoutAlgorithm::CheckPosition( case Placement::RIGHT_TOP: case Placement::RIGHT_BOTTOM: case Placement::RIGHT: { - rect = GetRightRect(); + rect = GetRightRect(userSetTargetSpace_); if (!CheckPositionRight(position, childSize, step, i, arrowPosition)) { return false; } @@ -2488,7 +2492,7 @@ bool BubbleLayoutAlgorithm::CheckPosition( case Placement::LEFT_TOP: case Placement::LEFT_BOTTOM: case Placement::LEFT: { - rect = GetLeftRect(); + rect = GetLeftRect(userSetTargetSpace_); if (!CheckPositionLeft(position, childSize, step, i, arrowPosition)) { return false; } diff --git a/frameworks/core/components_ng/pattern/bubble/bubble_layout_algorithm.h b/frameworks/core/components_ng/pattern/bubble/bubble_layout_algorithm.h index c2762a9d06c99c8e0ff590a7b8582c7e80e9fcf8..25546f97e39603b4ff3bddc8137e983c4ea0fcc5 100644 --- a/frameworks/core/components_ng/pattern/bubble/bubble_layout_algorithm.h +++ b/frameworks/core/components_ng/pattern/bubble/bubble_layout_algorithm.h @@ -298,10 +298,10 @@ private: void RecordMaxSpace(const float maxAreaSpace, const OffsetF& position, const float maxWidth, const float maxHeight, const OffsetF& arrowPosition); void BottomAndTopPosition(OffsetF& bottomPosition, OffsetF& topPosition, const SizeF& childSize); - Rect GetBottomRect(); - Rect GetTopRect(); - Rect GetRightRect(); - Rect GetLeftRect(); + Rect GetBottomRect(const Dimension& targetSpace); + Rect GetTopRect(const Dimension& targetSpace); + Rect GetRightRect(const Dimension& targetSpace); + Rect GetLeftRect(const Dimension& targetSpace); OffsetF AvoidToTopOrBottomByWidth(const SizeF& childSize, OffsetF& arrowPosition, SizeF& resultSize); OffsetF AdjustAvoidPosition(const OffsetF& position, float width, float height, OffsetF& arrowPosition); diff --git a/test/unittest/core/pattern/bubble/bubble_test_two_ng.cpp b/test/unittest/core/pattern/bubble/bubble_test_two_ng.cpp index 1ed74a39856cd70de67ea331c8ee3201b25a71ba..f9ae03c8397486238c1834ba6f40e39f4e7a52ff 100644 --- a/test/unittest/core/pattern/bubble/bubble_test_two_ng.cpp +++ b/test/unittest/core/pattern/bubble/bubble_test_two_ng.cpp @@ -1254,14 +1254,14 @@ HWTEST_F(BubbleTestTwoNg, GetBottomRect001, TestSize.Level1) BubbleTestTwoNg::InitGetRectSetting(algorithm); algorithm.isHalfFoldHover_ = false; - Rect rect = algorithm.GetBottomRect(); + Rect rect = algorithm.GetBottomRect(Dimension(0.0f)); EXPECT_FLOAT_EQ(rect.Width(), CHILDSIZE_ONE_HUNDRED_EIGHTY); EXPECT_FLOAT_EQ(rect.Height(), RESULT_FORTY); EXPECT_FLOAT_EQ(rect.Left(), RESULT_TEN); EXPECT_FLOAT_EQ(rect.Top(), RESULT_ONE_HUNDRED_FIFTY); algorithm.isHalfFoldHover_ = true; - rect = algorithm.GetBottomRect(); + rect = algorithm.GetBottomRect(Dimension(0.0f)); EXPECT_FLOAT_EQ(rect.Width(), CHILDSIZE_ONE_HUNDRED_EIGHTY); EXPECT_FLOAT_EQ(rect.Height(), RESULT_FIFTY); EXPECT_FLOAT_EQ(rect.Left(), RESULT_TEN); @@ -1279,14 +1279,14 @@ HWTEST_F(BubbleTestTwoNg, GetTopRect001, TestSize.Level1) BubbleTestTwoNg::InitGetRectSetting(algorithm); algorithm.isHalfFoldHover_ = false; - Rect rect = algorithm.GetTopRect(); + Rect rect = algorithm.GetTopRect(Dimension(0.0f)); EXPECT_FLOAT_EQ(rect.Width(), CHILDSIZE_ONE_HUNDRED_EIGHTY); EXPECT_FLOAT_EQ(rect.Height(), RESULT_FORTY); EXPECT_FLOAT_EQ(rect.Left(), RESULT_TEN); EXPECT_FLOAT_EQ(rect.Top(), RESULT_TEN); algorithm.isHalfFoldHover_ = true; - rect = algorithm.GetTopRect(); + rect = algorithm.GetTopRect(Dimension(0.0f)); EXPECT_FLOAT_EQ(rect.Width(), CHILDSIZE_ONE_HUNDRED_EIGHTY); EXPECT_FLOAT_EQ(rect.Height(), RESULT_FIFTY); EXPECT_FLOAT_EQ(rect.Left(), RESULT_TEN); @@ -1304,14 +1304,14 @@ HWTEST_F(BubbleTestTwoNg, GetRightRect001, TestSize.Level1) BubbleTestTwoNg::InitGetRectSetting(algorithm); algorithm.isHalfFoldHover_ = false; - Rect rect = algorithm.GetRightRect(); + Rect rect = algorithm.GetRightRect(Dimension(0.0f)); EXPECT_FLOAT_EQ(rect.Width(), RESULT_FORTY); EXPECT_FLOAT_EQ(rect.Height(), CHILDSIZE_ONE_HUNDRED_EIGHTY); EXPECT_FLOAT_EQ(rect.Left(), RESULT_ONE_HUNDRED_FIFTY); EXPECT_FLOAT_EQ(rect.Top(), RESULT_TEN); algorithm.isHalfFoldHover_ = true; - rect = algorithm.GetRightRect(); + rect = algorithm.GetRightRect(Dimension(0.0f)); EXPECT_FLOAT_EQ(rect.Width(), RESULT_FORTY); EXPECT_FLOAT_EQ(rect.Height(), SIZE_TWO_HUNDRED); EXPECT_FLOAT_EQ(rect.Left(), RESULT_ONE_HUNDRED_FIFTY); @@ -1329,14 +1329,14 @@ HWTEST_F(BubbleTestTwoNg, GetLeftRect001, TestSize.Level1) BubbleTestTwoNg::InitGetRectSetting(algorithm); algorithm.isHalfFoldHover_ = false; - Rect rect = algorithm.GetLeftRect(); + Rect rect = algorithm.GetLeftRect(Dimension(0.0f)); EXPECT_FLOAT_EQ(rect.Width(), RESULT_FORTY); EXPECT_FLOAT_EQ(rect.Height(), CHILDSIZE_ONE_HUNDRED_EIGHTY); EXPECT_FLOAT_EQ(rect.Left(), RESULT_TEN); EXPECT_FLOAT_EQ(rect.Top(), RESULT_TEN); algorithm.isHalfFoldHover_ = true; - rect = algorithm.GetLeftRect(); + rect = algorithm.GetLeftRect(Dimension(0.0f)); EXPECT_FLOAT_EQ(rect.Width(), RESULT_FORTY); EXPECT_FLOAT_EQ(rect.Height(), SIZE_TWO_HUNDRED); EXPECT_FLOAT_EQ(rect.Left(), RESULT_TEN);