From 7869b6714f008a726ecb319fbc62d21c94f98546 Mon Sep 17 00:00:00 2001 From: Tianer Zhou Date: Tue, 16 Jul 2024 19:44:36 +0800 Subject: [PATCH 1/2] fix sectioned layout margin Signed-off-by: Tianer Zhou Change-Id: I565fe05750da9e1d6eb2f8eb7448661812e114dd --- .../sliding_window/water_flow_layout_sw.cpp | 17 +++++++++++++++-- .../top_down/water_flow_segmented_layout.cpp | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/frameworks/core/components_ng/pattern/waterflow/layout/sliding_window/water_flow_layout_sw.cpp b/frameworks/core/components_ng/pattern/waterflow/layout/sliding_window/water_flow_layout_sw.cpp index 3c3c0c0bf5d..99ec3617dfd 100644 --- a/frameworks/core/components_ng/pattern/waterflow/layout/sliding_window/water_flow_layout_sw.cpp +++ b/frameworks/core/components_ng/pattern/waterflow/layout/sliding_window/water_flow_layout_sw.cpp @@ -26,6 +26,7 @@ #include "core/components_ng/pattern/waterflow/layout/water_flow_layout_utils.h" #include "core/components_ng/pattern/waterflow/water_flow_layout_property.h" #include "core/components_ng/pattern/waterflow/water_flow_pattern.h" +#include "core/components_ng/property/measure_property.h" #include "core/components_ng/property/measure_utils.h" #include "core/components_ng/property/templates_parser.h" @@ -594,15 +595,27 @@ float WaterFlowLayoutSW::MeasureChild(const RefPtr& pro return child->GetGeometryNode()->GetMarginFrameSize().MainSize(info_->axis_); } +namespace { +float MarginStart(Axis axis, const PaddingPropertyF& margin) +{ + return (axis == Axis::VERTICAL ? margin.left : margin.top).value_or(0.0f); +} +float MarginEnd(Axis axis, const PaddingPropertyF& margin) +{ + return (axis == Axis::VERTICAL ? margin.right : margin.bottom).value_or(0.0f); +} +} // namespace + void WaterFlowLayoutSW::LayoutSection( size_t idx, const OffsetF& paddingOffset, float selfCrossLen, bool reverse, bool rtl) { - float crossPos = rtl ? selfCrossLen + mainGaps_[idx] : 0.0f; + const auto& margin = info_->margins_[idx]; + float crossPos = rtl ? selfCrossLen + mainGaps_[idx] - MarginEnd(axis_, margin) : MarginStart(axis_, margin); for (size_t i = 0; i < info_->lanes_[idx].size(); ++i) { if (rtl) { crossPos -= itemsCrossSize_[idx][i] + crossGaps_[idx]; } - auto& lane = info_->lanes_[idx][i]; + const auto& lane = info_->lanes_[idx][i]; float mainPos = lane.startPos; for (const auto& item : lane.items_) { auto child = wrapper_->GetOrCreateChildByIndex(nodeIdx(item.idx)); diff --git a/frameworks/core/components_ng/pattern/waterflow/layout/top_down/water_flow_segmented_layout.cpp b/frameworks/core/components_ng/pattern/waterflow/layout/top_down/water_flow_segmented_layout.cpp index 06afa62c33d..333f50a441a 100644 --- a/frameworks/core/components_ng/pattern/waterflow/layout/top_down/water_flow_segmented_layout.cpp +++ b/frameworks/core/components_ng/pattern/waterflow/layout/top_down/water_flow_segmented_layout.cpp @@ -303,7 +303,7 @@ void WaterFlowSegmentedLayout::MeasureOnOffset() if (!forward) { // measure appearing items when scrolling upwards auto props = DynamicCast(wrapper_->GetLayoutProperty()); - int32_t bound = std::min(oldStart, info_->endIndex_); + const int32_t bound = std::min(oldStart, info_->endIndex_); for (int32_t i = info_->startIndex_; i <= bound; ++i) { MeasureItem(props, i, info_->itemInfos_[i].crossIdx, WaterFlowLayoutUtils::GetUserDefHeight(sections_, info_->GetSegment(i), i)); From bd05d7890ec2d2aaa2a1f3b0b745e4419e28313f Mon Sep 17 00:00:00 2001 From: Tianer Zhou Date: Tue, 16 Jul 2024 19:45:12 +0800 Subject: [PATCH 2/2] add tests Signed-off-by: Tianer Zhou Change-Id: I0393c51d943d2f381dd4a3ee99194a8395e6a15e --- test/unittest/core/pattern/waterflow/water_flow_item_maps.h | 3 ++- .../core/pattern/waterflow/water_flow_segment_common_test.cpp | 3 ++- .../core/pattern/waterflow/water_flow_segment_layout_test.cpp | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/test/unittest/core/pattern/waterflow/water_flow_item_maps.h b/test/unittest/core/pattern/waterflow/water_flow_item_maps.h index 8187671a1b9..037b9c06a55 100644 --- a/test/unittest/core/pattern/waterflow/water_flow_item_maps.h +++ b/test/unittest/core/pattern/waterflow/water_flow_item_maps.h @@ -135,6 +135,7 @@ const PaddingProperty MARGIN_1 = { .bottom = CalcLength(5.0_vp), .top = CalcLength(1.0_vp), .right = CalcLength(3.0_vp), + .left = CalcLength(5.0_vp), }; const std::vector SECTION_5 = { @@ -162,7 +163,7 @@ const std::vector CROSS_GAP_5 = { 0.0f, 0.0f, 0.0f, 2.0f, 0.0f }; const std::vector MAIN_GAP_5 = { 5.0f, 0.0f, 0.0f, 1.0f, 2.0f }; // assuming WaterFlow width = 400.0f const std::vector> ITEM_CROSS_SIZE_5 = { { 400.0f / 3, 400.0f / 3, 400.0f / 3 }, - { 79.4f, 79.4f, 79.4f, 79.4f, 79.4f }, { 400.0f }, { 400.0f }, { 200.0f, 200.0f } }; + { 78.4f, 78.4f, 78.4f, 78.4f, 78.4f }, { 400.0f }, { 400.0f }, { 200.0f, 200.0f } }; const std::vector ADD_SECTION_6 = { WaterFlowSections::Section { .itemsCount = 10, diff --git a/test/unittest/core/pattern/waterflow/water_flow_segment_common_test.cpp b/test/unittest/core/pattern/waterflow/water_flow_segment_common_test.cpp index 4a21fa32ba5..84feedc9e4c 100644 --- a/test/unittest/core/pattern/waterflow/water_flow_segment_common_test.cpp +++ b/test/unittest/core/pattern/waterflow/water_flow_segment_common_test.cpp @@ -775,8 +775,9 @@ HWTEST_F(WaterFlowSegmentCommonTest, Constraint001, TestSize.Level1) EXPECT_EQ(GetChildWidth(frameNode_, i), 500.f / 3); } for (int i = 5; i < 10; i++) { - EXPECT_EQ(GetChildWidth(frameNode_, i), (500.f - 3) / 5); + EXPECT_EQ(GetChildWidth(frameNode_, i), (500.f - 8.0f) / 5); } + EXPECT_EQ(GetChildX(frameNode_, 5), 5.0f); EXPECT_EQ(GetChildWidth(frameNode_, 10), 500.f); EXPECT_EQ(info_->endIndex_, 10); diff --git a/test/unittest/core/pattern/waterflow/water_flow_segment_layout_test.cpp b/test/unittest/core/pattern/waterflow/water_flow_segment_layout_test.cpp index 34c2270ebde..d6e3803220c 100644 --- a/test/unittest/core/pattern/waterflow/water_flow_segment_layout_test.cpp +++ b/test/unittest/core/pattern/waterflow/water_flow_segment_layout_test.cpp @@ -1393,7 +1393,7 @@ HWTEST_F(WaterFlowSegmentTest, Constraint001, TestSize.Level1) EXPECT_EQ(GetChildWidth(frameNode_, i), 500.f / 3); } for (int i = 5; i < 10; i++) { - EXPECT_EQ(GetChildWidth(frameNode_, i), (500.f - 3) / 5); + EXPECT_EQ(GetChildWidth(frameNode_, i), (500.f - 8.0f) / 5); } EXPECT_EQ(GetChildWidth(frameNode_, 10), 500.f); EXPECT_EQ(info->endIndex_, 10);