diff --git a/frameworks/core/components/calendar/calendar_theme.h b/frameworks/core/components/calendar/calendar_theme.h index d91c750004afeda5379a292b41f86ac123f1c2a4..31ef9bb6ad943368edfc71ad1d6a58c05e2213f4 100644 --- a/frameworks/core/components/calendar/calendar_theme.h +++ b/frameworks/core/components/calendar/calendar_theme.h @@ -31,6 +31,23 @@ constexpr Color DEFAULT_WEEKEND_DAY_COLOR = Color(0x7D181819); constexpr Color DEFAULT_WEEKEND_LUNAR_COLOR = Color(0x7D181819); constexpr Color DEFAULT_NON_CURRENT_MONTH_LUNAR_COLOR = Color(0x75181819); constexpr Color DEFAULT_LUNAR_COLOR = Color(0x96181819); +constexpr Color DEFAULT_CALENDAR_WEEK_COLOR = Color(0xffa0a1a5); +constexpr Color DEFAULT_CALENDAR_DAY_COLOR = Color(0xffeaebed); +constexpr Color DEFAULT_CALENDAR_LUNAR_COLOR = Color(0xffa0a1a5); +constexpr Color DEFAULT_CALENDAR_WEEKEND_DAY_COLOR = Color(0xff808080); +constexpr Color DEFAULT_CALENDAR_WEEKEND_LUNAR_COLOR = Color(0xff808080); +constexpr Color DEFAULT_CALENDAR_TODAY_DAY_FOCUS_COLOR = Color(0xffffffff); +constexpr Color DEFAULT_CALENDAR_TODAY_LUNAR_FOCUS_COLOR = Color(0xffffffff); +constexpr Color DEFAULT_CALENDAR_TODAY_DAY_UNFOCUS_COLOR = Color(0xff0a59f7); +constexpr Color DEFAULT_CALENDAR_TODAY_LUNAR_UNFOCUS_COLOR = Color(0xff0a59f7); +constexpr Color DEFAULT_CALENDAR_WORK_MARK_COLOR = Color(0xffe84026); +constexpr Color DEFAULT_CALENDAR_OFF_MARK_COLOR = Color(0xff0a59f7); +constexpr Color DEFAULT_CALENDAR_NONCURRENT_MONTH_WORK_MARK_COLOR = Color(0x33e84026); +constexpr Color DEFAULT_CALENDAR_NONCURRENT_MONTH_OFF_MARK_COLOR = Color(0x330a59f7); +constexpr Color DEFAULT_CALENDAR_NONCURRENT_MONTH_DAY_COLOR = Color(0xff555e6b); +constexpr Color DEFAULT_CALENDAR_NONCURRENT_MONTH_LUNAR_COLOR = Color(0xff555e6b); +constexpr Color DEFAULT_CALENDAR_FOCUS_AREA_BACKGROUND_COLOR = Color(0xff5ea1ff); +constexpr Color DEFAULT_CALENDAR_BLUR_AREA_BACKGROUND_COLOR = Color(0xffffffff); } // namespace @@ -253,6 +270,7 @@ public: void ParsePattern(const RefPtr& themeStyle, const RefPtr& theme) const { if (!themeStyle) { + LOGW("Calendar parse pattern failed, themeStyle is invalid."); return; } auto pattern = themeStyle->GetAttr>(THEME_PATTERN_CALENDAR, nullptr); @@ -260,6 +278,7 @@ public: LOGW("find pattern of calendar fail"); return; } + // Card theme theme->cardCalendarTheme_.focusedAreaBackgroundColor = pattern->GetAttr("card_area_bg_color_focused", Color::BLUE); theme->cardCalendarTheme_.dayColor = @@ -286,6 +305,42 @@ public: pattern->GetAttr("card_title_text_color", Color::BLACK); theme->cardCalendarTheme_.clickEffectColor = pattern->GetAttr("card_switch_button_bg_color_clicked", Color::TRANSPARENT); + + // Normal theme + theme->calendarTheme_.dayColor = + pattern->GetAttr(CALENDAR_DAY_COLOR, DEFAULT_CALENDAR_DAY_COLOR); + theme->calendarTheme_.weekColor = + pattern->GetAttr(CALENDAR_WEEK_COLOR, DEFAULT_CALENDAR_WEEK_COLOR); + theme->calendarTheme_.lunarColor = + pattern->GetAttr(CALENDAR_LUNAR_COLOR, DEFAULT_CALENDAR_LUNAR_COLOR); + theme->calendarTheme_.weekendDayColor = + pattern->GetAttr(CALENDAR_WEEKEND_DAY_COLOR, DEFAULT_CALENDAR_WEEKEND_DAY_COLOR); + theme->calendarTheme_.weekendLunarColor = + pattern->GetAttr(CALENDAR_WEEKEND_LUNAR_COLOR, DEFAULT_CALENDAR_WEEKEND_LUNAR_COLOR); + theme->calendarTheme_.focusedDayColor = + pattern->GetAttr(CALENDAR_TODAY_DAY_FOCUS_COLOR, DEFAULT_CALENDAR_TODAY_DAY_FOCUS_COLOR); + theme->calendarTheme_.focusedLunarColor = + pattern->GetAttr(CALENDAR_TODAY_LUNAR_FOCUS_COLOR, DEFAULT_CALENDAR_TODAY_LUNAR_FOCUS_COLOR); + theme->calendarTheme_.todayColor = + pattern->GetAttr(CALENDAR_TODAY_DAY_UNFOCUS_COLOR, DEFAULT_CALENDAR_TODAY_DAY_UNFOCUS_COLOR); + theme->calendarTheme_.todayLunarColor = + pattern->GetAttr(CALENDAR_TODAY_LUNAR_UNFOCUS_COLOR, DEFAULT_CALENDAR_TODAY_LUNAR_UNFOCUS_COLOR); + theme->calendarTheme_.workDayMarkColor = + pattern->GetAttr(CALENDAR_WORK_MARK_COLOR, DEFAULT_CALENDAR_WORK_MARK_COLOR); + theme->calendarTheme_.offDayMarkColor = + pattern->GetAttr(CALENDAR_OFF_MARK_COLOR, DEFAULT_CALENDAR_OFF_MARK_COLOR); + theme->calendarTheme_.nonCurrentMonthWorkDayMarkColor = pattern->GetAttr( + CALENDAR_NONCURRENT_MONTH_WORK_MARK_COLOR, DEFAULT_CALENDAR_NONCURRENT_MONTH_WORK_MARK_COLOR); + theme->calendarTheme_.nonCurrentMonthOffDayMarkColor = pattern->GetAttr( + CALENDAR_NONCURRENT_MONTH_OFF_MARK_COLOR, DEFAULT_CALENDAR_NONCURRENT_MONTH_OFF_MARK_COLOR); + theme->calendarTheme_.nonCurrentMonthDayColor = pattern->GetAttr( + CALENDAR_NONCURRENT_MONTH_DAY_COLOR, DEFAULT_CALENDAR_NONCURRENT_MONTH_DAY_COLOR); + theme->calendarTheme_.nonCurrentMonthLunarColor = pattern->GetAttr( + CALENDAR_NONCURRENT_MONTH_LUNAR_COLOR, DEFAULT_CALENDAR_NONCURRENT_MONTH_LUNAR_COLOR); + theme->calendarTheme_.focusedAreaBackgroundColor = pattern->GetAttr( + CALENDAR_FOCUS_AREA_BACKGROUND_COLOR, DEFAULT_CALENDAR_FOCUS_AREA_BACKGROUND_COLOR); + theme->calendarTheme_.blurAreaBackgroundColor = pattern->GetAttr( + CALENDAR_BLUR_AREA_BACKGROUND_COLOR, DEFAULT_CALENDAR_BLUR_AREA_BACKGROUND_COLOR); } }; diff --git a/frameworks/core/components/theme/theme_attributes.cpp b/frameworks/core/components/theme/theme_attributes.cpp index ef5de90a88d97a71e1c9bf6b610f585cc6a2b90e..76fbec9a480fba7fa678f843a11e413b7dc515bf 100644 --- a/frameworks/core/components/theme/theme_attributes.cpp +++ b/frameworks/core/components/theme/theme_attributes.cpp @@ -98,6 +98,25 @@ const char SWITCH_HORIZONTAL_PADDING[] = "switch_horizontal_padding"; const char SWITCH_VERTICAL_PADDING[] = "switch_vertical_padding"; const char RADIO_PADDING[] = "radio_padding"; +// pattern attributes for calendar +const char CALENDAR_WEEK_COLOR[] = "week_color"; +const char CALENDAR_DAY_COLOR[] = "day_color"; +const char CALENDAR_LUNAR_COLOR[] = "lunar_color"; +const char CALENDAR_WEEKEND_DAY_COLOR[] = "weekend_day_color"; +const char CALENDAR_WEEKEND_LUNAR_COLOR[] = "weekend_lunar_color"; +const char CALENDAR_TODAY_DAY_FOCUS_COLOR[] = "today_day_focus_color"; +const char CALENDAR_TODAY_LUNAR_FOCUS_COLOR[] = "today_lunar_focus_color"; +const char CALENDAR_TODAY_DAY_UNFOCUS_COLOR[] = "today_day_unfocus_color"; +const char CALENDAR_TODAY_LUNAR_UNFOCUS_COLOR[] = "today_lunar_unfocus_color"; +const char CALENDAR_WORK_MARK_COLOR[] = "work_mark_color"; +const char CALENDAR_OFF_MARK_COLOR[] = "off_mark_color"; +const char CALENDAR_NONCURRENT_MONTH_WORK_MARK_COLOR[] = "non_current_month_work_mark_color"; +const char CALENDAR_NONCURRENT_MONTH_OFF_MARK_COLOR[] = "non_current_month_off_mark_color"; +const char CALENDAR_NONCURRENT_MONTH_DAY_COLOR[] = "non_current_month_day_color"; +const char CALENDAR_NONCURRENT_MONTH_LUNAR_COLOR[] = "non_current_month_lunar_color"; +const char CALENDAR_FOCUS_AREA_BACKGROUND_COLOR[] = "focus_area_background_color"; +const char CALENDAR_BLUR_AREA_BACKGROUND_COLOR[] = "blur_area_background_color"; + // data panel attributes const char DATA_PANEL_COLOR_1_START[] = "rainbow_fg_color_1_start"; const char DATA_PANEL_COLOR_2_START[] = "rainbow_fg_color_2_start"; @@ -165,4 +184,4 @@ const char ARROW_DISABLED_ALPHA[] = "arrow_disabled_alpha"; const char ARROW_HORIZONTAL_MARGIN[] = "arrow_horizontal_margin"; const char ARROW_VERTICAL_MARGIN[] = "arrow_vertical_margin"; const char ARROW_COLOR_COMPONENT_NORMAL[] = "arrow_color_component_normal"; -} // namespace OHOS::Ace \ No newline at end of file +} // namespace OHOS::Ace diff --git a/frameworks/core/components/theme/theme_attributes.h b/frameworks/core/components/theme/theme_attributes.h index 2a767cc8d64c6adb87dc5734eca5f33a6d1d71ec..4b9d0490da244cb5bfb173db029389c4197bb39c 100644 --- a/frameworks/core/components/theme/theme_attributes.h +++ b/frameworks/core/components/theme/theme_attributes.h @@ -92,6 +92,25 @@ extern const char PATTERN_TEXT_SIZE[]; extern const char PATTERN_WIDTH[]; extern const char PATTERN_HEIGHT[]; +// pattern attributes for calendar +extern const char CALENDAR_WEEK_COLOR[]; +extern const char CALENDAR_DAY_COLOR[]; +extern const char CALENDAR_LUNAR_COLOR[]; +extern const char CALENDAR_WEEKEND_DAY_COLOR[]; +extern const char CALENDAR_WEEKEND_LUNAR_COLOR[]; +extern const char CALENDAR_TODAY_DAY_FOCUS_COLOR[]; +extern const char CALENDAR_TODAY_LUNAR_FOCUS_COLOR[]; +extern const char CALENDAR_TODAY_DAY_UNFOCUS_COLOR[]; +extern const char CALENDAR_TODAY_LUNAR_UNFOCUS_COLOR[]; +extern const char CALENDAR_WORK_MARK_COLOR[]; +extern const char CALENDAR_OFF_MARK_COLOR[]; +extern const char CALENDAR_NONCURRENT_MONTH_WORK_MARK_COLOR[]; +extern const char CALENDAR_NONCURRENT_MONTH_OFF_MARK_COLOR[]; +extern const char CALENDAR_NONCURRENT_MONTH_DAY_COLOR[]; +extern const char CALENDAR_NONCURRENT_MONTH_LUNAR_COLOR[]; +extern const char CALENDAR_FOCUS_AREA_BACKGROUND_COLOR[]; +extern const char CALENDAR_BLUR_AREA_BACKGROUND_COLOR[]; + // pattern attributes for checkable extern const char RADIO_WIDTH[]; extern const char SWITCH_WIDTH[]; diff --git a/frameworks/core/components_ng/pattern/calendar/calendar_paint_method.cpp b/frameworks/core/components_ng/pattern/calendar/calendar_paint_method.cpp index ad663cec598a351949cfefff819bcc117e7b54d4..19d8bc050bc288bdec6383e7076bc02eaae09df9 100644 --- a/frameworks/core/components_ng/pattern/calendar/calendar_paint_method.cpp +++ b/frameworks/core/components_ng/pattern/calendar/calendar_paint_method.cpp @@ -240,49 +240,57 @@ void CalendarPaintMethod::SetDayTextStyle( } } +void CalendarPaintMethod::SetOffWorkTextStyle(RSTextStyle& offWorkTextStyle, const CalendarDay& day) const +{ + // Paint off or work mark value. + offWorkTextStyle.fontWeight_ = static_cast(workStateFontWeight_); + offWorkTextStyle.locale_ = Localization::GetInstance()->GetFontLocale(); + if (day.month.month == currentMonth_.month) { + if (day.dayMark == "work") { + offWorkTextStyle.fontSize_ = workDayMarkSize_; + offWorkTextStyle.color_ = workDayMarkColor_; + } else if (day.dayMark == "off") { + offWorkTextStyle.fontSize_ = offDayMarkSize_; + offWorkTextStyle.color_ = offDayMarkColor_; + } + } else { + if (day.dayMark == "work") { + offWorkTextStyle.fontSize_ = workDayMarkSize_; + offWorkTextStyle.color_ = + RSColor(nonCurrentMonthWorkDayMarkColor_.GetRed(), nonCurrentMonthWorkDayMarkColor_.GetGreen(), + nonCurrentMonthWorkDayMarkColor_.GetBlue(), WEEKEND_TRANSPARENT); + } else if (day.dayMark == "off") { + offWorkTextStyle.fontSize_ = offDayMarkSize_; + offWorkTextStyle.color_ = + RSColor(nonCurrentMonthOffDayMarkColor_.GetRed(), nonCurrentMonthOffDayMarkColor_.GetGreen(), + nonCurrentMonthOffDayMarkColor_.GetBlue(), WEEKEND_TRANSPARENT); + } + } + + // If it is today and it is focused, workState color is same as focused day color. + if (IsToday(day) && day.focused) { + offWorkTextStyle.color_ = focusedDayColor_; + } +} + void CalendarPaintMethod::PaintDay( RSCanvas& canvas, const Offset& offset, const CalendarDay& day, RSTextStyle& textStyle) const { - // paint day + // Paint day value. Rect boxRect { offset.GetX(), offset.GetY(), dayWidth_, gregorianDayHeight_ }; Rect textRect; - RSTextStyle workStateStyle; auto dayStr = std::to_string(day.day); dayStr = Localization::GetInstance()->NumberFormat(day.day); DrawCalendarText(&canvas, dayStr, textStyle, boxRect, textRect); + // Paint off and work mark value. if (!day.dayMark.empty() && showHoliday_) { - workStateStyle.fontWeight_ = static_cast(workStateFontWeight_); - workStateStyle.locale_ = Localization::GetInstance()->GetFontLocale(); + RSTextStyle workStateStyle; boxRect = { textRect.GetOffset().GetX() + textRect.Width() - workStateHorizontalMovingDistance_, textRect.GetOffset().GetY() + textRect.Height() - workStateVerticalMovingDistance_, workStateWidth_, workStateWidth_ }; - if (day.month.month == currentMonth_.month) { - if (day.dayMark == "work") { - workStateStyle.fontSize_ = workDayMarkSize_; - workStateStyle.color_ = workDayMarkColor_; - } else if (day.dayMark == "off") { - workStateStyle.fontSize_ = offDayMarkSize_; - workStateStyle.color_ = offDayMarkColor_; - } - } else { - if (day.dayMark == "work") { - workStateStyle.fontSize_ = workDayMarkSize_; - workStateStyle.color_ = RSColor(workDayMarkColor_.GetRed(), workDayMarkColor_.GetGreen(), - workDayMarkColor_.GetBlue(), WEEKEND_TRANSPARENT); - } else if (day.dayMark == "off") { - workStateStyle.fontSize_ = offDayMarkSize_; - workStateStyle.color_ = RSColor(offDayMarkColor_.GetRed(), offDayMarkColor_.GetGreen(), - offDayMarkColor_.GetBlue(), WEEKEND_TRANSPARENT); - } - if (day.focused) { - workStateStyle.color_ = Color::BLACK.GetValue(); - } - if (IsToday(day) && day.touched) { - workStateStyle.color_ = focusedDayColor_; - } - } + SetOffWorkTextStyle(workStateStyle, day); DrawCalendarText(&canvas, day.dayMarkValue, workStateStyle, boxRect); } } diff --git a/frameworks/core/components_ng/pattern/calendar/calendar_paint_method.h b/frameworks/core/components_ng/pattern/calendar/calendar_paint_method.h index 81337398d51b0590654fe831398ad5dac8d4d7f6..1a7c47a2d8258e21d7566336c12490f7febc16e6 100644 --- a/frameworks/core/components_ng/pattern/calendar/calendar_paint_method.h +++ b/frameworks/core/components_ng/pattern/calendar/calendar_paint_method.h @@ -49,6 +49,7 @@ private: void DrawFocusedArea(RSCanvas& canvas, const Offset& offset, double x, double y) const; void InitTextStyle(RSTextStyle& dateTextStyle, RSTextStyle& lunarTextStyle); void SetDayTextStyle(RSTextStyle& dateTextStyle, RSTextStyle& lunarTextStyle, const CalendarDay& day); + void SetOffWorkTextStyle(RSTextStyle& offWorkTextStyle, const CalendarDay& day) const; void PaintDay(RSCanvas& canvas, const Offset& offset, const CalendarDay& day, RSTextStyle& textStyle) const; void PaintLunarDay( RSCanvas& canvas, const Offset& offset, const CalendarDay& day, const RSTextStyle& textStyle) const;