From 95e24ec007591a0fb9adfcb3048e9cac84d6dfb5 Mon Sep 17 00:00:00 2001 From: zhangwenbin Date: Thu, 24 Oct 2024 19:58:48 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=94=B6=E7=BC=96=E3=80=91=E3=80=90sw?= =?UTF-8?q?iper=E3=80=91=E5=B7=AE=E5=BC=82=E5=8C=96=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E2=80=94=E2=80=94=E4=BF=AE=E5=A4=8Dswiper=E7=84=A6=E6=A1=86?= =?UTF-8?q?=E4=B8=8D=E8=B4=B4=E5=90=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangwenbin --- .../swiper_indicator_pattern.cpp | 56 +++++++++++++++++++ .../swiper_indicator_pattern.h | 1 + 2 files changed, 57 insertions(+) diff --git a/frameworks/core/components_ng/pattern/swiper_indicator/indicator_common/swiper_indicator_pattern.cpp b/frameworks/core/components_ng/pattern/swiper_indicator/indicator_common/swiper_indicator_pattern.cpp index f0caa9813ea..9a6a04bc233 100644 --- a/frameworks/core/components_ng/pattern/swiper_indicator/indicator_common/swiper_indicator_pattern.cpp +++ b/frameworks/core/components_ng/pattern/swiper_indicator/indicator_common/swiper_indicator_pattern.cpp @@ -31,6 +31,8 @@ constexpr uint32_t INDICATOR_HAS_CHILD = 2; constexpr Dimension INDICATOR_DRAG_MIN_DISTANCE = 4.0_vp; constexpr Dimension INDICATOR_DRAG_MAX_DISTANCE = 18.0_vp; constexpr Dimension INDICATOR_TOUCH_BOTTOM_MAX_DISTANCE = 80.0_vp; +constexpr Dimension INDICATOR_ITEM_SPACE_POINT = 8.0_vp; +constexpr int32_t MULTIPLIER = 2; constexpr int32_t LONG_PRESS_DELAY = 300; constexpr float HALF_FLOAT = 0.5f; constexpr float MAX_FONT_SCALE = 2.0f; @@ -121,6 +123,54 @@ void SwiperIndicatorPattern::OnModifyDone() } } +void SwiperIndicatorPattern::GetInnerFocusPaintRect(RoundRect& paintRect) +{ + auto host = GetHost(); + CHECK_NULL_VOID(host); + auto geometryNode = host->GetGeometryNode(); + CHECK_NULL_VOID(geometryNode); + auto swiperNode = GetSwiperNode(); + CHECK_NULL_VOID(swiperNode); + auto swiperPattern = swiperNode->GetPattern(); + CHECK_NULL_VOID(swiperPattern); + auto pipelineContext = host->GetContext(); + CHECK_NULL_VOID(pipelineContext); + auto swiperTheme = pipelineContext->GetTheme(); + CHECK_NULL_VOID(swiperTheme); + auto focusPadding = swiperTheme->GetIndicatorFocusedPadding().ConvertToPx(); + auto swiperSize = geometryNode->GetFrameSize(); + auto maxDisplayCount = swiperPattern->GetMaxDisplayCount() > 0 ? swiperPattern->GetMaxDisplayCount() + : swiperPattern->DisplayIndicatorTotalCount(); + float itemWidth = swiperTheme->GetSize().ConvertToPx(); + float itemHeight = swiperTheme->GetSize().ConvertToPx(); + auto indicatorHeightPadding = swiperTheme->GetIndicatorBgHeight().ConvertToPx(); + auto allPointSpaceSum = static_cast(INDICATOR_ITEM_SPACE_POINT.ConvertToPx()) * (maxDisplayCount - 1); + auto paddingSide = swiperTheme->GetIndicatorPaddingDot().ConvertToPx(); + auto width = itemWidth * (maxDisplayCount + 1) + allPointSpaceSum + + MULTIPLIER * paddingSide + MULTIPLIER * focusPadding; + auto height = itemHeight + MULTIPLIER * indicatorHeightPadding + MULTIPLIER * focusPadding; + auto widthSize = swiperSize.Width() + MULTIPLIER * focusPadding; + auto heightSize = swiperSize.Height() + MULTIPLIER * focusPadding; + auto widthDiff = (widthSize - width) / MULTIPLIER; + auto heightDiff = (heightSize - height) / MULTIPLIER; + paintRect.SetRect({ widthDiff - focusPadding, heightDiff - focusPadding, width, height }); + auto renderContext = host->GetRenderContext(); + CHECK_NULL_VOID(renderContext); + auto radius = renderContext->GetBorderRadius().value_or(BorderRadiusProperty()); + paintRect.SetCornerRadius(RoundRect::CornerPos::TOP_LEFT_POS, + static_cast(radius.radiusTopLeft->ConvertToPx() + focusPadding), + static_cast(radius.radiusTopLeft->ConvertToPx() + focusPadding)); + paintRect.SetCornerRadius(RoundRect::CornerPos::TOP_RIGHT_POS, + static_cast(radius.radiusTopRight->ConvertToPx() + focusPadding), + static_cast(radius.radiusTopRight->ConvertToPx() + focusPadding)); + paintRect.SetCornerRadius(RoundRect::CornerPos::BOTTOM_LEFT_POS, + static_cast(radius.radiusBottomLeft->ConvertToPx() + focusPadding), + static_cast(radius.radiusBottomLeft->ConvertToPx() + focusPadding)); + paintRect.SetCornerRadius(RoundRect::CornerPos::BOTTOM_RIGHT_POS, + static_cast(radius.radiusBottomRight->ConvertToPx() + focusPadding), + static_cast(radius.radiusBottomRight->ConvertToPx() + focusPadding)); +} + void SwiperIndicatorPattern::InitFocusEvent() { if (focusEventInitialized_) { @@ -142,6 +192,12 @@ void SwiperIndicatorPattern::InitFocusEvent() pattern->HandleBlurEvent(); }; focusHub->SetOnBlurInternal(blurTask); + auto getInnerPaintRectCallback = [wp = WeakClaim(this)](RoundRect& paintRect) { + auto pattern = wp.Upgrade(); + CHECK_NULL_VOID(pattern); + pattern->GetInnerFocusPaintRect(paintRect); + }; + focusHub->SetInnerFocusPaintRectCallback(getInnerPaintRectCallback); focusEventInitialized_ = true; } diff --git a/frameworks/core/components_ng/pattern/swiper_indicator/indicator_common/swiper_indicator_pattern.h b/frameworks/core/components_ng/pattern/swiper_indicator/indicator_common/swiper_indicator_pattern.h index bdc5ec28051..ae4530806ed 100644 --- a/frameworks/core/components_ng/pattern/swiper_indicator/indicator_common/swiper_indicator_pattern.h +++ b/frameworks/core/components_ng/pattern/swiper_indicator/indicator_common/swiper_indicator_pattern.h @@ -204,6 +204,7 @@ private: bool CheckIsTouchBottom(const TouchLocationInfo& info); float HandleTouchClickMargin(); int32_t GetCurrentIndex() const; + void GetInnerFocusPaintRect(RoundRect& paintRect); void InitFocusEvent(); void HandleFocusEvent(); void HandleBlurEvent();