diff --git a/frameworks/core/components_ng/pattern/swiper_indicator/indicator_common/indicator_model_ng.cpp b/frameworks/core/components_ng/pattern/swiper_indicator/indicator_common/indicator_model_ng.cpp index f0a7f833213d18a55c2fab933c7a93baaff9a4a4..76bf76f47dc9a7542853b3f8a6fa6a5906ba7773 100644 --- a/frameworks/core/components_ng/pattern/swiper_indicator/indicator_common/indicator_model_ng.cpp +++ b/frameworks/core/components_ng/pattern/swiper_indicator/indicator_common/indicator_model_ng.cpp @@ -217,28 +217,39 @@ int32_t IndicatorModelNG::GetCount(FrameNode* frameNode) } template -void ParseType(const RefPtr& resObj, T& result) +bool ParseType(const RefPtr& resObj, const std::string& name, T& result) { if constexpr (std::is_same_v) { - ResourceParseUtils::ParseResColor(resObj, result); + return ResourceParseUtils::ParseResColor(resObj, result); } else if constexpr (std::is_same_v) { - ResourceParseUtils::ParseResDimensionVpNG(resObj, result); + if (name == "fontSize" || name == "selectedFontSize") { + return ResourceParseUtils::ParseResDimensionFpNG(resObj, result); + } + return ResourceParseUtils::ParseResDimensionVpNG(resObj, result); } + return false; } -#define UPDATE_DOT_VALUE(frameNode, name, resObj, resultType) \ +#define UPDATE_DOT_VALUE(frameNode, attrType, name, resObj, resultType) \ do { \ CHECK_NULL_VOID(frameNode); \ auto pattern = frameNode->GetPattern(); \ CHECK_NULL_VOID(pattern); \ if (resObj) { \ - auto&& updateFunc = [weak = AceType::WeakClaim(frameNode)](const RefPtr& resObj) { \ + auto&& updateFunc = [weak = AceType::WeakClaim(frameNode)](const RefPtr& theObj) { \ auto node = weak.Upgrade(); \ CHECK_NULL_VOID(node); \ auto pattern = node->GetPattern(); \ CHECK_NULL_VOID(pattern); \ resultType result; \ - ParseType(resObj, result); \ + bool isOk = ParseType(theObj, #name, result) && (result.Unit() != DimensionUnit::PERCENT); \ + if (!(isOk && result > 0.0_vp)) { \ + auto pipelineContext = node->GetContext(); \ + CHECK_NULL_VOID(pipelineContext); \ + auto theme = pipelineContext->GetTheme(); \ + CHECK_NULL_VOID(theme); \ + result = theme->Get##attrType(); \ + } \ auto params = pattern->GetIndicatorParameters(); \ params->name = result; \ }; \ @@ -248,19 +259,82 @@ void ParseType(const RefPtr& resObj, T& result) } \ } while (false) -#define UPDATE_DIGITAL_VALUE(frameNode, name, resObj, resultType) \ +#define UPDATE_DIGITAL_VALUE(frameNode, attrType, name, resObj, resultType) \ do { \ CHECK_NULL_VOID(frameNode); \ auto pattern = frameNode->GetPattern(); \ CHECK_NULL_VOID(pattern); \ if (resObj) { \ - auto&& updateFunc = [weak = AceType::WeakClaim(frameNode)](const RefPtr& resObj) { \ + auto&& updateFunc = [weak = AceType::WeakClaim(frameNode)](const RefPtr& theObj) { \ auto node = weak.Upgrade(); \ CHECK_NULL_VOID(node); \ auto pattern = node->GetPattern(); \ CHECK_NULL_VOID(pattern); \ resultType result; \ - ParseType(resObj, result); \ + if (!ParseType(theObj, #name, result) || LessOrEqual(result.Value(), 0.0) || \ + result.Unit() == DimensionUnit::PERCENT) { \ + auto pipelineContext = node->GetContext(); \ + CHECK_NULL_VOID(pipelineContext); \ + auto theme = pipelineContext->GetTheme(); \ + CHECK_NULL_VOID(theme); \ + result = theme->GetDigitalIndicatorTextStyle().Get##attrType(); \ + } \ + auto params = pattern->GetSwiperDigitalParameters(); \ + params->name = result; \ + }; \ + pattern->AddResObj("indicator." #name, resObj, std::move(updateFunc)); \ + } else { \ + pattern->RemoveResObj("indicator." #name); \ + } \ + } while (false) + +#define UPDATE_DOT_COLOR_VALUE(frameNode, attrType, name, resObj, resultType) \ + do { \ + CHECK_NULL_VOID(frameNode); \ + auto pattern = frameNode->GetPattern(); \ + CHECK_NULL_VOID(pattern); \ + if (resObj) { \ + auto&& updateFunc = [weak = AceType::WeakClaim(frameNode)](const RefPtr& theObj) { \ + auto node = weak.Upgrade(); \ + CHECK_NULL_VOID(node); \ + auto pattern = node->GetPattern(); \ + CHECK_NULL_VOID(pattern); \ + resultType result; \ + if (!ParseType(theObj, #name, result)) { \ + auto pipelineContext = node->GetContext(); \ + CHECK_NULL_VOID(pipelineContext); \ + auto theme = pipelineContext->GetTheme(); \ + CHECK_NULL_VOID(theme); \ + result = theme->Get##attrType(); \ + } \ + auto params = pattern->GetIndicatorParameters(); \ + params->name = result; \ + }; \ + pattern->AddResObj("indicator." #name, resObj, std::move(updateFunc)); \ + } else { \ + pattern->RemoveResObj("indicator." #name); \ + } \ + } while (false) + +#define UPDATE_DIGITAL_COLOR_VALUE(frameNode, attrType, name, resObj, resultType) \ + do { \ + CHECK_NULL_VOID(frameNode); \ + auto pattern = frameNode->GetPattern(); \ + CHECK_NULL_VOID(pattern); \ + if (resObj) { \ + auto&& updateFunc = [weak = AceType::WeakClaim(frameNode)](const RefPtr& theObj) { \ + auto node = weak.Upgrade(); \ + CHECK_NULL_VOID(node); \ + auto pattern = node->GetPattern(); \ + CHECK_NULL_VOID(pattern); \ + resultType result; \ + if (!ParseType(theObj, #name, result)) { \ + auto pipelineContext = node->GetContext(); \ + CHECK_NULL_VOID(pipelineContext); \ + auto theme = pipelineContext->GetTheme(); \ + CHECK_NULL_VOID(theme); \ + result = theme->GetDigitalIndicatorTextStyle().Get##attrType(); \ + } \ auto params = pattern->GetSwiperDigitalParameters(); \ params->name = result; \ }; \ @@ -274,17 +348,17 @@ void IndicatorModelNG::CreateDotWithResourceObj(FrameNode* frameNode, const Swip { CHECK_NULL_VOID(frameNode); auto resObj = swiperParameters.resourceColorValueObject; - UPDATE_DOT_VALUE(frameNode, colorVal, resObj, Color); + UPDATE_DOT_COLOR_VALUE(frameNode, Color, colorVal, resObj, Color); resObj = swiperParameters.resourceSelectedColorValueObject; - UPDATE_DOT_VALUE(frameNode, selectedColorVal, resObj, Color); + UPDATE_DOT_COLOR_VALUE(frameNode, SelectedColor, selectedColorVal, resObj, Color); resObj = swiperParameters.resourceItemWidthValueObject; - UPDATE_DOT_VALUE(frameNode, itemWidth, resObj, CalcDimension); + UPDATE_DOT_VALUE(frameNode, Size, itemWidth, resObj, CalcDimension); resObj = swiperParameters.resourceItemHeightValueObject; - UPDATE_DOT_VALUE(frameNode, itemHeight, resObj, CalcDimension); + UPDATE_DOT_VALUE(frameNode, Size, itemHeight, resObj, CalcDimension); resObj = swiperParameters.resourceSelectedItemWidthValueObject; - UPDATE_DOT_VALUE(frameNode, selectedItemWidth, resObj, CalcDimension); + UPDATE_DOT_VALUE(frameNode, Size, selectedItemWidth, resObj, CalcDimension); resObj = swiperParameters.resourceSelectedItemHeightValueObject; - UPDATE_DOT_VALUE(frameNode, selectedItemHeight, resObj, CalcDimension); + UPDATE_DOT_VALUE(frameNode, Size, selectedItemHeight, resObj, CalcDimension); } void IndicatorModelNG::CreateDigitWithResourceObj(FrameNode* frameNode, @@ -292,12 +366,12 @@ void IndicatorModelNG::CreateDigitWithResourceObj(FrameNode* frameNode, { CHECK_NULL_VOID(frameNode); auto resObj = swiperDigitalParameters.resourceFontColorValueObject; - UPDATE_DIGITAL_VALUE(frameNode, fontColor, resObj, Color); + UPDATE_DIGITAL_COLOR_VALUE(frameNode, TextColor, fontColor, resObj, Color); resObj = swiperDigitalParameters.resourceFontSizeValueObject; - UPDATE_DIGITAL_VALUE(frameNode, fontSize, resObj, CalcDimension); + UPDATE_DIGITAL_VALUE(frameNode, FontSize, fontSize, resObj, CalcDimension); resObj = swiperDigitalParameters.resourceSelectedFontColorValueObject; - UPDATE_DIGITAL_VALUE(frameNode, selectedFontColor, resObj, Color); + UPDATE_DIGITAL_COLOR_VALUE(frameNode, TextColor, selectedFontColor, resObj, Color); resObj = swiperDigitalParameters.resourceSelectedFontSizeValueObject; - UPDATE_DIGITAL_VALUE(frameNode, selectedFontSize, resObj, CalcDimension); + UPDATE_DIGITAL_VALUE(frameNode, FontSize, selectedFontSize, resObj, CalcDimension); } } // namespace OHOS::Ace::NG