diff --git a/frameworks/core/components_ng/pattern/grid/grid_adaptive/grid_adaptive_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/grid/grid_adaptive/grid_adaptive_layout_algorithm.cpp index 23e6592a06123b7e648650cb0b8a183bea881fa6..ab373972683b7872069e353ed747eecf86a84b6f 100644 --- a/frameworks/core/components_ng/pattern/grid/grid_adaptive/grid_adaptive_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/grid/grid_adaptive/grid_adaptive_layout_algorithm.cpp @@ -158,9 +158,9 @@ OffsetF GridAdaptiveLayoutAlgorithm::CalculateChildOffset(int32_t index, LayoutW auto padding = layoutProperty->CreatePaddingAndBorder(); auto layoutDirection = layoutProperty->GetGridDirection().value_or(FlexDirection::ROW); auto scale = layoutProperty->GetLayoutConstraint()->scaleProperty; - auto rowsGap = ConvertToPx(layoutProperty->GetRowsGap().value_or(0.0_vp), scale, frameSize.Width()).value_or(0); + auto rowsGap = ConvertToPx(layoutProperty->GetRowsGap().value_or(0.0_vp), scale, frameSize.Height()).value_or(0); auto columnsGap = - ConvertToPx(layoutProperty->GetColumnsGap().value_or(0.0_vp), scale, frameSize.Height()).value_or(0); + ConvertToPx(layoutProperty->GetColumnsGap().value_or(0.0_vp), scale, frameSize.Width()).value_or(0); int32_t rowIndex = 0; int32_t columnIndex = 0; diff --git a/frameworks/core/components_ng/pattern/grid/grid_layout/grid_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/grid/grid_layout/grid_layout_algorithm.cpp index fee245d7dd0205ab46467a9efa99a923506714f1..e31ee4c94b2b67014cbd94ac9910be79cf860841 100644 --- a/frameworks/core/components_ng/pattern/grid/grid_layout/grid_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/grid/grid_layout/grid_layout_algorithm.cpp @@ -34,9 +34,9 @@ LayoutConstraintF GridLayoutAlgorithm::CreateChildConstraint(const SizeF& idealS { LayoutConstraintF layoutConstraint = layoutProperty->CreateChildConstraint(); auto scale = layoutProperty->GetLayoutConstraint()->scaleProperty; - auto rowsGap = ConvertToPx(layoutProperty->GetRowsGap().value_or(0.0_vp), scale, idealSize.Width()).value_or(0); + auto rowsGap = ConvertToPx(layoutProperty->GetRowsGap().value_or(0.0_vp), scale, idealSize.Height()).value_or(0); auto columnsGap = - ConvertToPx(layoutProperty->GetColumnsGap().value_or(0.0_vp), scale, idealSize.Height()).value_or(0); + ConvertToPx(layoutProperty->GetColumnsGap().value_or(0.0_vp), scale, idealSize.Width()).value_or(0); float rowLen = 0.0; for (int32_t i = 0; i < rowSpan; ++i) { @@ -60,9 +60,9 @@ void GridLayoutAlgorithm::InitGridCeils(LayoutWrapper* layoutWrapper, const Size auto layoutProperty = DynamicCast(layoutWrapper->GetLayoutProperty()); CHECK_NULL_VOID(layoutProperty); auto scale = layoutProperty->GetLayoutConstraint()->scaleProperty; - auto rowsGap = ConvertToPx(layoutProperty->GetRowsGap().value_or(0.0_vp), scale, idealSize.Width()).value_or(0); + auto rowsGap = ConvertToPx(layoutProperty->GetRowsGap().value_or(0.0_vp), scale, idealSize.Height()).value_or(0); auto columnsGap = - ConvertToPx(layoutProperty->GetColumnsGap().value_or(0.0_vp), scale, idealSize.Height()).value_or(0); + ConvertToPx(layoutProperty->GetColumnsGap().value_or(0.0_vp), scale, idealSize.Width()).value_or(0); auto rowsLen = GridUtils::ParseArgs(layoutProperty->GetRowsTemplate().value_or(""), idealSize.Height(), rowsGap); auto colsLen = GridUtils::ParseArgs(layoutProperty->GetColumnsTemplate().value_or(""), idealSize.Width(), columnsGap); @@ -159,9 +159,9 @@ OffsetF GridLayoutAlgorithm::ComputeItemPosition( CHECK_NULL_RETURN(layoutProperty, OffsetF()); auto frameSize = layoutWrapper->GetGeometryNode()->GetMarginFrameSize(); auto scale = layoutProperty->GetLayoutConstraint()->scaleProperty; - auto rowsGap = ConvertToPx(layoutProperty->GetRowsGap().value_or(0.0_vp), scale, frameSize.Width()).value_or(0); + auto rowsGap = ConvertToPx(layoutProperty->GetRowsGap().value_or(0.0_vp), scale, frameSize.Height()).value_or(0); auto columnsGap = - ConvertToPx(layoutProperty->GetColumnsGap().value_or(0.0_vp), scale, frameSize.Height()).value_or(0); + ConvertToPx(layoutProperty->GetColumnsGap().value_or(0.0_vp), scale, frameSize.Width()).value_or(0); // Calculate the position for current child. float positionX = 0.0f; diff --git a/frameworks/core/components_ng/pattern/grid/grid_scroll/grid_scroll_layout_algorithm.cpp b/frameworks/core/components_ng/pattern/grid/grid_scroll/grid_scroll_layout_algorithm.cpp index 927b02582be84a752cd8e6ab18a753a0d38e781d..f799f41898e28e94dec61f93cf4983b080a25204 100644 --- a/frameworks/core/components_ng/pattern/grid/grid_scroll/grid_scroll_layout_algorithm.cpp +++ b/frameworks/core/components_ng/pattern/grid/grid_scroll/grid_scroll_layout_algorithm.cpp @@ -206,8 +206,7 @@ void GridScrollLayoutAlgorithm::Layout(LayoutWrapper* layoutWrapper) gridItemLayoutProperty->UpdateMainIndex(line->first); gridItemLayoutProperty->UpdateCrossIndex(iter->first); } - prevLineHeight += - gridLayoutInfo_.lineHeightMap_[line->first] + GridUtils::GetMainGap(gridLayoutProperty, size, axis_); + prevLineHeight += gridLayoutInfo_.lineHeightMap_[line->first] + mainGap_; } } @@ -219,10 +218,14 @@ void GridScrollLayoutAlgorithm::InitialItemsCrossSize( auto columnsTemplate = layoutProperty->GetColumnsTemplate().value_or(""); axis_ = columnsTemplate.empty() ? Axis::HORIZONTAL : Axis::VERTICAL; auto scale = layoutProperty->GetLayoutConstraint()->scaleProperty; - auto rowsGap = ConvertToPx(layoutProperty->GetRowsGap().value_or(0.0_vp), scale, frameSize.Width()).value_or(0); + auto rowsGap = ConvertToPx(layoutProperty->GetRowsGap().value_or(0.0_vp), scale, frameSize.Height()).value_or(0); auto columnsGap = - ConvertToPx(layoutProperty->GetColumnsGap().value_or(0.0_vp), scale, frameSize.Height()).value_or(0); + ConvertToPx(layoutProperty->GetColumnsGap().value_or(0.0_vp), scale, frameSize.Width()).value_or(0); mainGap_ = axis_ == Axis::HORIZONTAL ? columnsGap : rowsGap; + crossGap_ = axis_ == Axis::VERTICAL ? columnsGap : rowsGap; + auto padding = layoutProperty->CreatePaddingAndBorder(); + crossPaddingOffset_ = axis_ == Axis::HORIZONTAL ? padding.top.value_or(0) : padding.left.value_or(0); + std::vector crossLens; if (!rowsTemplate.empty()) { crossLens = GridUtils::ParseArgs(rowsTemplate, frameSize.Height(), rowsGap); @@ -1062,24 +1065,13 @@ bool GridScrollLayoutAlgorithm::CheckGridPlaced( float GridScrollLayoutAlgorithm::ComputeItemCrossPosition(LayoutWrapper* layoutWrapper, int32_t crossStart) const { - auto layoutProperty = DynamicCast(layoutWrapper->GetLayoutProperty()); - CHECK_NULL_RETURN(layoutProperty, 0); - auto frameSize = layoutWrapper->GetGeometryNode()->GetMarginFrameSize(); - auto scale = layoutProperty->GetLayoutConstraint()->scaleProperty; - auto rowsGap = ConvertToPx(layoutProperty->GetRowsGap().value_or(0.0_vp), scale, frameSize.Width()).value_or(0); - auto columnsGap = - ConvertToPx(layoutProperty->GetColumnsGap().value_or(0.0_vp), scale, frameSize.Height()).value_or(0); - auto crossGap = axis_ == Axis::VERTICAL ? columnsGap : rowsGap; - auto padding = layoutProperty->CreatePaddingAndBorder(); - auto crossPaddingOffset = axis_ == Axis::HORIZONTAL ? padding.top.value_or(0) : padding.left.value_or(0); - float position = 0.0f; for (int32_t index = 0; index < crossStart; ++index) { if (index >= 0 && index < static_cast(itemsCrossSize_.size())) { position += itemsCrossSize_.at(index); } } - position += crossStart * crossGap + crossPaddingOffset; + position += crossStart * crossGap_ + crossPaddingOffset_; return position; } diff --git a/frameworks/core/components_ng/pattern/grid/grid_scroll/grid_scroll_layout_algorithm.h b/frameworks/core/components_ng/pattern/grid/grid_scroll/grid_scroll_layout_algorithm.h index 8b34f0e37ab448e322bbc553e0aa8b683689667c..825445616b02dc18936ed90d057f3adbceb8b574 100644 --- a/frameworks/core/components_ng/pattern/grid/grid_scroll/grid_scroll_layout_algorithm.h +++ b/frameworks/core/components_ng/pattern/grid/grid_scroll/grid_scroll_layout_algorithm.h @@ -93,6 +93,8 @@ private: Axis axis_ = Axis::VERTICAL; float mainGap_ = 0; + float crossGap_ = 0; + float crossPaddingOffset_ = 0; // Map structure: [index, crossPosition], store cross position of each item. std::map itemsCrossPosition_; diff --git a/frameworks/core/components_ng/pattern/grid/grid_utils.cpp b/frameworks/core/components_ng/pattern/grid/grid_utils.cpp index 7a9fe80fd9ea52a5606adc125fca18e9a828711d..7d389c261ed6686118294b43be50912290471e0a 100644 --- a/frameworks/core/components_ng/pattern/grid/grid_utils.cpp +++ b/frameworks/core/components_ng/pattern/grid/grid_utils.cpp @@ -55,18 +55,20 @@ std::vector GridUtils::ParseArgs(const std::string& args, float size, flo float GridUtils::GetMainGap(const RefPtr& gridLayoutProperty, const SizeF& frameSize, Axis axis) { auto scale = gridLayoutProperty->GetLayoutConstraint()->scaleProperty; - auto rowsGap = ConvertToPx(gridLayoutProperty->GetRowsGap().value_or(0.0_vp), scale, frameSize.Width()).value_or(0); + auto rowsGap = + ConvertToPx(gridLayoutProperty->GetRowsGap().value_or(0.0_vp), scale, frameSize.Height()).value_or(0); auto columnsGap = - ConvertToPx(gridLayoutProperty->GetColumnsGap().value_or(0.0_vp), scale, frameSize.Height()).value_or(0); + ConvertToPx(gridLayoutProperty->GetColumnsGap().value_or(0.0_vp), scale, frameSize.Width()).value_or(0); return axis == Axis::HORIZONTAL ? columnsGap : rowsGap; } float GridUtils::GetCrossGap(const RefPtr& gridLayoutProperty, const SizeF& frameSize, Axis axis) { auto scale = gridLayoutProperty->GetLayoutConstraint()->scaleProperty; - auto rowsGap = ConvertToPx(gridLayoutProperty->GetRowsGap().value_or(0.0_vp), scale, frameSize.Width()).value_or(0); + auto rowsGap = + ConvertToPx(gridLayoutProperty->GetRowsGap().value_or(0.0_vp), scale, frameSize.Height()).value_or(0); auto columnsGap = - ConvertToPx(gridLayoutProperty->GetColumnsGap().value_or(0.0_vp), scale, frameSize.Height()).value_or(0); + ConvertToPx(gridLayoutProperty->GetColumnsGap().value_or(0.0_vp), scale, frameSize.Width()).value_or(0); return axis == Axis::HORIZONTAL ? rowsGap : columnsGap; }