From c1dfddf03151929033afd6988efc0926296f118b Mon Sep 17 00:00:00 2001 From: limeng Date: Thu, 24 Aug 2023 21:13:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=9A=E7=BA=A7=E8=8F=9C=E5=8D=95=E9=81=BF?= =?UTF-8?q?=E9=9A=9C=E6=B7=BB=E5=8A=A0=E7=AA=97=E5=8F=A3=E5=AE=89=E5=85=A8?= =?UTF-8?q?=E8=B7=9D=E7=A6=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: limeng --- .../pattern/menu/menu_layout_algorithm.h | 19 +++++++++++++++++++ .../menu/sub_menu_layout_algorithm.cpp | 14 +++++++------- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/frameworks/core/components_ng/pattern/menu/menu_layout_algorithm.h b/frameworks/core/components_ng/pattern/menu/menu_layout_algorithm.h index da8f9749054..ff871120698 100644 --- a/frameworks/core/components_ng/pattern/menu/menu_layout_algorithm.h +++ b/frameworks/core/components_ng/pattern/menu/menu_layout_algorithm.h @@ -46,6 +46,25 @@ protected: RefPtr GetPaintProperty(const LayoutWrapper* layoutWrapper); OffsetF GetMenuWrapperOffset(const LayoutWrapper* layoutWrapper); + float GetPaddingStart() + { + return paddingStart_; + } + + float GetPaddingEnd() + { + return paddingEnd_; + } + + float GetPaddingTop() + { + return paddingTop_; + } + + float GetPaddingBottom() + { + return paddingBottom_; + } // position input is relative to main window left top point, // menu show position is relative to menuWrapper. diff --git a/frameworks/core/components_ng/pattern/menu/sub_menu_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/menu/sub_menu_layout_algorithm.cpp index 4a83364c4e8..00ddaf37666 100644 --- a/frameworks/core/components_ng/pattern/menu/sub_menu_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/menu/sub_menu_layout_algorithm.cpp @@ -73,14 +73,14 @@ void SubMenuLayoutAlgorithm::Layout(LayoutWrapper* layoutWrapper) float SubMenuLayoutAlgorithm::VerticalLayoutSubMenu(const SizeF& size, float position, const SizeF& menuItemSize) { float wrapperHeight = wrapperSize_.Height(); - float bottomSpace = wrapperHeight - position; + float bottomSpace = wrapperHeight - position - GetPaddingBottom(); // line up top of subMenu with top of the menuItem if (bottomSpace >= size.Height()) { return position; } // line up bottom of menu with bottom of the screen - if (size.Height() < wrapperHeight) { - return wrapperHeight - size.Height(); + if (size.Height() < (wrapperHeight - GetPaddingTop() - GetPaddingBottom())) { + return wrapperHeight - GetPaddingBottom() - size.Height(); } // can't fit in screen, line up with top of the screen return 0.0f; @@ -90,8 +90,8 @@ float SubMenuLayoutAlgorithm::VerticalLayoutSubMenu(const SizeF& size, float pos float SubMenuLayoutAlgorithm::HorizontalLayoutSubMenu(const SizeF& size, float position, const SizeF& menuItemSize) { float wrapperWidth = wrapperSize_.Width(); - float rightSpace = wrapperWidth - position; - float leftSpace = position - menuItemSize.Width(); + float rightSpace = wrapperWidth - position - GetPaddingEnd(); + float leftSpace = position - menuItemSize.Width() - GetPaddingStart(); // can fit subMenu on the right side of menuItem if (rightSpace >= size.Width()) { return position; @@ -101,8 +101,8 @@ float SubMenuLayoutAlgorithm::HorizontalLayoutSubMenu(const SizeF& size, float p return position - size.Width() - menuItemSize.Width(); } // line up right side of menu with right boundary of the screen - if (size.Width() < wrapperWidth) { - return wrapperWidth - size.Width(); + if (size.Width() < wrapperWidth - GetPaddingStart() - GetPaddingEnd()) { + return wrapperWidth - GetPaddingEnd() - size.Width(); } // can't fit in screen, line up with left side of the screen return 0.0f; -- Gitee