From 965c759eb95f3b61d0f37aee7c7231d58a123750 Mon Sep 17 00:00:00 2001 From: kondratievvladislav Date: Mon, 11 Nov 2024 15:19:14 +0300 Subject: [PATCH] Apply the token theme to the Divider color --- frameworks/core/components/picker/picker_theme.h | 2 +- .../pattern/picker/datepicker_paint_method.cpp | 7 ++++--- .../pattern/picker/picker_theme_wrapper.h | 7 +++---- .../pattern/text_picker/textpicker_paint_method.cpp | 9 +++++---- .../pattern/text_picker/textpicker_paint_method.h | 2 +- .../pattern/time_picker/timepicker_paint_method.cpp | 11 ++++------- 6 files changed, 18 insertions(+), 20 deletions(-) diff --git a/frameworks/core/components/picker/picker_theme.h b/frameworks/core/components/picker/picker_theme.h index 3a5110147664..c34eb1de279a 100644 --- a/frameworks/core/components/picker/picker_theme.h +++ b/frameworks/core/components/picker/picker_theme.h @@ -523,6 +523,7 @@ protected: TextStyle selectedOptionStyle_; TextStyle disappearOptionStyle_; TextStyle normalOptionStyle_; + Color dividerColor_; private: Color focusColor_; @@ -573,7 +574,6 @@ private: double rotateInterval_ = 0.0; Dimension dividerThickness_; Dimension dividerSpacing_; - Color dividerColor_; Dimension gradientHeight_; Dimension columnFixedWidth_; diff --git a/frameworks/core/components_ng/pattern/picker/datepicker_paint_method.cpp b/frameworks/core/components_ng/pattern/picker/datepicker_paint_method.cpp index bd7b85de14e9..24f05ce66b8c 100644 --- a/frameworks/core/components_ng/pattern/picker/datepicker_paint_method.cpp +++ b/frameworks/core/components_ng/pattern/picker/datepicker_paint_method.cpp @@ -32,11 +32,9 @@ constexpr float DIVIDER_LINE_WIDTH = 1.0f; CanvasDrawFunction DatePickerPaintMethod::GetForegroundDrawFunction(PaintWrapper* paintWrapper) { + CHECK_NULL_RETURN(paintWrapper, nullptr); auto pipeline = PipelineBase::GetCurrentContext(); CHECK_NULL_RETURN(pipeline, nullptr); - auto theme = pipeline->GetTheme(); - CHECK_NULL_RETURN(theme, nullptr); - auto dividerColor = theme->GetDividerColor(); const auto& geometryNode = paintWrapper->GetGeometryNode(); CHECK_NULL_RETURN(geometryNode, nullptr); @@ -46,6 +44,9 @@ CanvasDrawFunction DatePickerPaintMethod::GetForegroundDrawFunction(PaintWrapper CHECK_NULL_RETURN(renderContext, nullptr); auto pickerNode = renderContext->GetHost(); CHECK_NULL_RETURN(pickerNode, nullptr); + auto theme = pipeline->GetTheme(pickerNode->GetThemeScopeId()); + CHECK_NULL_RETURN(theme, nullptr); + auto dividerColor = theme->GetDividerColor(); auto layoutProperty = pickerNode->GetLayoutProperty(); CHECK_NULL_RETURN(layoutProperty, nullptr); auto dividerSpacing = pipeline->NormalizeToPx(theme->GetDividerSpacing()); diff --git a/frameworks/core/components_ng/pattern/picker/picker_theme_wrapper.h b/frameworks/core/components_ng/pattern/picker/picker_theme_wrapper.h index 6524c9d4f940..1ee0eef53062 100644 --- a/frameworks/core/components_ng/pattern/picker/picker_theme_wrapper.h +++ b/frameworks/core/components_ng/pattern/picker/picker_theme_wrapper.h @@ -37,11 +37,9 @@ public: RefPtr wrapper = AceType::Claim(new PickerThemeWrapper()); RefPtr theme = AceType::DynamicCast(wrapper); RefPtr themeStyle = themeConstants->GetThemeStyle(); - if (themeStyle) { + if (theme && themeStyle) { InitializeTextStyles(theme, themeStyle); - } - if (themeConstants) { - Parse(themeConstants->GetThemeStyle(), AceType::DynamicCast(wrapper)); + Parse(themeStyle, theme); } return wrapper; } @@ -52,6 +50,7 @@ public: selectedOptionStyle_.SetTextColor(colors->FontEmphasize()); disappearOptionStyle_.SetTextColor(colors->FontPrimary()); normalOptionStyle_.SetTextColor(colors->FontPrimary()); + dividerColor_ = colors->IconFourth(); } } }; diff --git a/frameworks/core/components_ng/pattern/text_picker/textpicker_paint_method.cpp b/frameworks/core/components_ng/pattern/text_picker/textpicker_paint_method.cpp index f1c610b5bd02..647549020fab 100644 --- a/frameworks/core/components_ng/pattern/text_picker/textpicker_paint_method.cpp +++ b/frameworks/core/components_ng/pattern/text_picker/textpicker_paint_method.cpp @@ -31,6 +31,7 @@ const Dimension PICKER_DIALOG_DIVIDER_MARGIN = 24.0_vp; CanvasDrawFunction TextPickerPaintMethod::GetForegroundDrawFunction(PaintWrapper* paintWrapper) { + CHECK_NULL_RETURN(paintWrapper, nullptr); const auto& geometryNode = paintWrapper->GetGeometryNode(); CHECK_NULL_RETURN(geometryNode, nullptr); auto frameRect = geometryNode->GetFrameRect(); @@ -48,7 +49,7 @@ CanvasDrawFunction TextPickerPaintMethod::GetForegroundDrawFunction(PaintWrapper return [weak = WeakClaim(this), layoutProperty, frameRect, - fontScale, pattern = pattern_](RSCanvas& canvas) { + fontScale, pattern = pattern_, themeScopeId = pickerNode->GetThemeScopeId()](RSCanvas& canvas) { auto picker = weak.Upgrade(); CHECK_NULL_VOID(picker); auto textPickerPattern = DynamicCast(pattern.Upgrade()); @@ -70,7 +71,7 @@ CanvasDrawFunction TextPickerPaintMethod::GetForegroundDrawFunction(PaintWrapper divider.isRtl = (textDirection == TextDirection::RTL) ? true : false; picker->PaintCustomDividerLines(canvas, contentRect, frameRect, divider, dividerHeight); } else { - picker->PaintDefaultDividerLines(canvas, contentRect, dividerHeight); + picker->PaintDefaultDividerLines(canvas, contentRect, dividerHeight, themeScopeId); } } }; @@ -86,11 +87,11 @@ void TextPickerPaintMethod::PaintCustomDividerLines(RSCanvas& canvas, const Rect } void TextPickerPaintMethod::PaintDefaultDividerLines(RSCanvas& canvas, const RectF &contentRect, - double dividerHeight) + double dividerHeight, const int32_t themeScopeId) { auto pipeline = PipelineContext::GetCurrentContext(); CHECK_NULL_VOID(pipeline); - auto theme = pipeline->GetTheme(); + auto theme = pipeline->GetTheme(themeScopeId); auto dividerColor = theme->GetDividerColor(); auto dividerLineWidth = theme->GetDividerThickness().ConvertToPx(); diff --git a/frameworks/core/components_ng/pattern/text_picker/textpicker_paint_method.h b/frameworks/core/components_ng/pattern/text_picker/textpicker_paint_method.h index 1283dd90ffd0..7240f711a12d 100644 --- a/frameworks/core/components_ng/pattern/text_picker/textpicker_paint_method.h +++ b/frameworks/core/components_ng/pattern/text_picker/textpicker_paint_method.h @@ -65,7 +65,7 @@ private: bool NeedPaintDividerLines(const RectF &contentRect, const ItemDivider ÷r, double dividerHeight, DividerInfo& info); - void PaintDefaultDividerLines(RSCanvas& canvas, const RectF &contentRect, double dividerHeight); + void PaintDefaultDividerLines(RSCanvas& canvas, const RectF &contentRect, double dividerHeight, const int32_t themeScopeId); void PaintCustomDividerLines(RSCanvas& canvas, const RectF &contentRect, const RectF &frameRect, const ItemDivider ÷r, double dividerHeight); void PaintLine(const OffsetF& offset, const DividerInfo &info, RSCanvas& canvas); diff --git a/frameworks/core/components_ng/pattern/time_picker/timepicker_paint_method.cpp b/frameworks/core/components_ng/pattern/time_picker/timepicker_paint_method.cpp index f1f9804f24be..0c8a83eda654 100644 --- a/frameworks/core/components_ng/pattern/time_picker/timepicker_paint_method.cpp +++ b/frameworks/core/components_ng/pattern/time_picker/timepicker_paint_method.cpp @@ -30,10 +30,9 @@ constexpr float DIVIDER_LINE_WIDTH = 1.0f; CanvasDrawFunction TimePickerPaintMethod::GetForegroundDrawFunction(PaintWrapper* paintWrapper) { + CHECK_NULL_RETURN(paintWrapper, nullptr); auto pipeline = PipelineContext::GetCurrentContext(); CHECK_NULL_RETURN(pipeline, nullptr); - auto theme = pipeline->GetTheme(); - auto dividerColor = theme->GetDividerColor(); const auto& geometryNode = paintWrapper->GetGeometryNode(); CHECK_NULL_RETURN(geometryNode, nullptr); @@ -43,6 +42,8 @@ CanvasDrawFunction TimePickerPaintMethod::GetForegroundDrawFunction(PaintWrapper CHECK_NULL_RETURN(renderContext, nullptr); auto pickerNode = renderContext->GetHost(); CHECK_NULL_RETURN(pickerNode, nullptr); + auto theme = pipeline->GetTheme(pickerNode->GetThemeScopeId()); + auto dividerColor = theme->GetDividerColor(); auto layoutProperty = pickerNode->GetLayoutProperty(); CHECK_NULL_RETURN(layoutProperty, nullptr); @@ -51,11 +52,7 @@ CanvasDrawFunction TimePickerPaintMethod::GetForegroundDrawFunction(PaintWrapper CHECK_NULL_RETURN(timePickerPattern, nullptr); auto fontScale = timePickerPattern->GetPaintDividerSpacing(); dividerSpacing = dividerSpacing * fontScale; - return [weak = WeakClaim(this), dividerLineWidth = DIVIDER_LINE_WIDTH, layoutProperty, frameRect, dividerSpacing, - dividerColor](RSCanvas& canvas) { - auto picker = weak.Upgrade(); - CHECK_NULL_VOID(picker); - + return [dividerLineWidth = DIVIDER_LINE_WIDTH, layoutProperty, frameRect, dividerSpacing, dividerColor](RSCanvas& canvas) { PaddingPropertyF padding = layoutProperty->CreatePaddingAndBorder(); RectF contentRect = { padding.left.value_or(0), padding.top.value_or(0), frameRect.Width() - padding.Width(), frameRect.Height() - padding.Height() }; -- Gitee