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 da8f9749054d4ca7b66a00bb623b37f0076ba24a..ff8711206984ff58dce19820d97066658c54eef6 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 4a83364c4e84033393e1f3f5b7c7f5d0cac8f2d5..00ddaf37666b5d60e59a99430d40c373eae2c0aa 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;