• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "core/components/checkable/checkable_theme.h"
17 
18 namespace OHOS::Ace {
SetCheckboxFocus(const RefPtr<ThemeConstants> & themeConstants,const RefPtr<CheckboxTheme> & theme) const19 void CheckboxTheme::Builder::SetCheckboxFocus(const RefPtr<ThemeConstants>& themeConstants,
20     const RefPtr<CheckboxTheme>& theme) const
21 {
22     RefPtr<ThemeStyle> checkboxPattern = themeConstants->GetPatternByName(THEME_PATTERN_CHECKBOX);
23     if (!checkboxPattern) {
24         LOGE("Pattern of checkbox is null, please check!");
25         return;
26     }
27     theme->focusBoardColor_ = checkboxPattern->GetAttr<Color>("color_focused_bg", Color(0xffff0000));
28     theme->focusBoardSize_ = checkboxPattern->GetAttr<Dimension>("size_focused_bg", 2.0_vp);
29     theme->borderFocusedColor_ = checkboxPattern->GetAttr<Color>("focused_border_color", Color(0xffff0000));
30     theme->focusedBGColorUnselected_ =
31         checkboxPattern->GetAttr<Color>("focused_bg_color_unselected", Color(0xffff0000));
32     theme->roundFocusBoardSize_ = checkboxPattern->GetAttr<Dimension>("round_size_focused_bg", 2.0_vp);
33     theme->whiteBorderRadius_ = checkboxPattern->GetAttr<Dimension>("focus_white_border_radius", 0.0_vp);
34     theme->focusLineColor_ = checkboxPattern->GetAttr<Color>("checkbox_focus_color_sys", Color(0xff007dff));
35     theme->defaultRoundPaddingSize_ =
36         checkboxPattern->GetAttr<Dimension>("checkbox_default_round_padding_size", 2.0_vp);
37 }
38 
ParsePattern(const RefPtr<ThemeConstants> & themeConstants,const RefPtr<CheckboxTheme> & theme) const39 void CheckboxTheme::Builder::ParsePattern(const RefPtr<ThemeConstants>& themeConstants,
40     const RefPtr<CheckboxTheme>& theme) const
41 {
42     RefPtr<ThemeStyle> checkboxPattern = themeConstants->GetPatternByName(THEME_PATTERN_CHECKBOX);
43     if (!checkboxPattern) {
44         LOGE("Pattern of checkbox is null, please check!");
45         return;
46     }
47     theme->width_ = checkboxPattern->GetAttr<Dimension>("checkbox_size", 0.0_vp);
48     theme->height_ = theme->width_;
49     theme->hotZoneHorizontalPadding_ = checkboxPattern->GetAttr<Dimension>("checkbox_hotzone_padding", 0.0_vp);
50     theme->defaultWidth_ = checkboxPattern->GetAttr<Dimension>("checkbox_default_size", 0.0_vp);
51     if (Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_TWELVE)) {
52         theme->defaultPaddingSize_ =
53             checkboxPattern->GetAttr<Dimension>("checkbox_default_padding_size", 2.0_vp);
54         theme->defaultWidth_ = checkboxPattern->GetAttr<Dimension>("checkbox_default_size_twelve", 24.0_vp);
55         theme->hoverPaddingSize_ = checkboxPattern->GetAttr<Dimension>("checkbox_hover_padding_size", 2.0_vp);
56         theme->showCircleDial_ = static_cast<bool>(checkboxPattern->GetAttr<double>("radio_circle_dial", 0.0));
57     }
58     theme->hotZoneVerticalPadding_ = theme->hotZoneHorizontalPadding_;
59     theme->defaultHeight_ = theme->defaultWidth_;
60     theme->needFocus_ = static_cast<bool>(checkboxPattern->GetAttr<double>("checkbox_need_focus", 0.0));
61     theme->backgroundSolid_ =
62         static_cast<bool>(checkboxPattern->GetAttr<double>("checkbox_inactive_background_solid", 0.0));
63     theme->borderWidth_ = checkboxPattern->GetAttr<Dimension>("checkbox_border_width", 0.0_vp);
64     theme->checkStroke_ = checkboxPattern->GetAttr<Dimension>("checkbox_stroke_width", 0.0_vp);
65     theme->shadowColor_ = checkboxPattern->GetAttr<Color>("checkbox_shadow_color", Color());
66     theme->shadowWidth_ = checkboxPattern->GetAttr<Dimension>("checkbox_shadow_width", 0.0_vp);
67     theme->pointColor_ = checkboxPattern->GetAttr<Color>("fg_color_checked", Color::RED);
68     theme->activeColor_ = checkboxPattern->GetAttr<Color>("bg_color_checked", Color::RED);
69     theme->inactiveColor_ = checkboxPattern->GetAttr<Color>("bg_border_color_unchecked", Color::RED);
70     theme->focusColor_ = checkboxPattern->GetAttr<Color>("focus_border_color", Color::RED);
71     theme->borderRadius_ = checkboxPattern->GetAttr<Dimension>("bg_border_radius", 0.0_vp);
72     theme->hoverColor_ = checkboxPattern->GetAttr<Color>("hover_border_color", Color::RED);
73     theme->clickEffectColor_ = checkboxPattern->GetAttr<Color>("click_effect_color", Color::RED);
74     theme->inactivePointColor_ = checkboxPattern->GetAttr<Color>("bg_color_unchecked", Color::RED);
75     theme->hoverRadius_ = checkboxPattern->GetAttr<Dimension>("hover_border_radius", 0.0_vp);
76     theme->focusRadius_ = checkboxPattern->GetAttr<Dimension>("focus_border_radius", 0.0_vp);
77     theme->focusPaintPadding_ = checkboxPattern->GetAttr<Dimension>("focus_paint_padding", 0.0_vp);
78     theme->hoverDuration_ = checkboxPattern->GetAttr<double>("hover_animation_duration", 0.0);
79     theme->hoverToTouchDuration_ = checkboxPattern->GetAttr<double>("hover_to_press_animation_duration", 0.0);
80     theme->touchDuration_ = checkboxPattern->GetAttr<double>("touch_animation_duration", 0.0);
81     theme->colorAnimationDuration_ = checkboxPattern->GetAttr<double>("color_animation_duration", 0.0);
82     SetCheckboxFocus(themeConstants, theme);
83 }
84 
ParsePattern(const RefPtr<ThemeConstants> & themeConstants,const RefPtr<SwitchTheme> & theme) const85 void SwitchTheme::Builder::ParsePattern(const RefPtr<ThemeConstants>& themeConstants,
86     const RefPtr<SwitchTheme>& theme) const
87 {
88     RefPtr<ThemeStyle> switchPattern = themeConstants->GetPatternByName(THEME_PATTERN_SWITCH);
89     if (!switchPattern) {
90         LOGE("Pattern of switch is null, please check!");
91         return;
92     }
93     theme->width_ = switchPattern->GetAttr<Dimension>("switch_pattern_width", 0.0_vp);
94     theme->height_ = switchPattern->GetAttr<Dimension>("switch_pattern_height", 0.0_vp);
95     theme->hotZoneHorizontalPadding_ =
96         switchPattern->GetAttr<Dimension>("switch_hotzone_horizontal_padding", 0.0_vp);
97     theme->hotZoneVerticalPadding_ =
98         switchPattern->GetAttr<Dimension>("switch_hotzone_vertical_padding", 0.0_vp);
99     theme->hotZoneHorizontalSize_ =
100         switchPattern->GetAttr<Dimension>("switch_hotzone_horizontal_size", 6.0_vp);
101     theme->hotZoneVerticalSize_ =
102         switchPattern->GetAttr<Dimension>("switch_hotzone_vertical_size", 14.0_vp);
103     theme->aspectRatio_ = switchPattern->GetAttr<double>("switch_aspect_ratio", 0.0);
104     theme->backgroundSolid_ =
105         static_cast<bool>(switchPattern->GetAttr<double>("switch_inactive_background_solid", 0.0));
106     theme->defaultWidth_ = switchPattern->GetAttr<Dimension>("switch_default_width", 0.0_vp);
107     theme->defaultHeight_ = switchPattern->GetAttr<Dimension>("switch_default_height", 0.0_vp);
108     theme->needFocus_ = static_cast<bool>(switchPattern->GetAttr<double>("switch_need_focus", 0.0));
109     theme->borderWidth_ = switchPattern->GetAttr<Dimension>("switch_border_width", 0.0_vp);
110     theme->shadowColor_ = switchPattern->GetAttr<Color>("switch_shadow_color", Color());
111     theme->shadowWidth_ = switchPattern->GetAttr<Dimension>("switch_pattern_shadow_width", 0.0_vp);
112     theme->pointColor_ = switchPattern->GetAttr<Color>("fg_color_checked", Color::RED);
113     theme->activeColor_ = switchPattern->GetAttr<Color>("bg_color_checked", Color::RED);
114     theme->inactiveColor_ = switchPattern->GetAttr<Color>("bg_color_unchecked", Color::RED);
115     theme->focusColor_ = switchPattern->GetAttr<Color>("focus_border_color", Color::RED);
116     theme->hoverColor_ = switchPattern->GetAttr<Color>("hover_border_color", Color::RED);
117     theme->hoverRadius_ = switchPattern->GetAttr<Dimension>("hover_border_radius", 0.0_vp);
118     theme->inactivePointColor_ = switchPattern->GetAttr<Color>("fg_color_unchecked", Color::RED);
119     theme->clickEffectColor_ = switchPattern->GetAttr<Color>("click_effect_color", Color::RED);
120     theme->focusPaintPadding_ = switchPattern->GetAttr<Dimension>("focus_paint_padding", 0.0_vp);
121     theme->hoverDuration_ = switchPattern->GetAttr<double>("hover_animation_duration", 0.0);
122     theme->hoverToTouchDuration_ = switchPattern->GetAttr<double>("hover_to_press_animation_duration", 0.0);
123     theme->touchDuration_ = switchPattern->GetAttr<double>("touch_animation_duration", 0.0);
124     theme->colorAnimationDuration_ = switchPattern->GetAttr<double>("color_animation_duration", 0.0);
125     theme->pointAnimationDuration_ = switchPattern->GetAttr<double>("point_animation_duration", 0.0);
126     theme->interactiveHoverColor_ = switchPattern->GetAttr<Color>("interactive_hover", Color::RED);
127     theme->interactivePressedColor_ = switchPattern->GetAttr<Color>("interactive_pressed", Color::RED);
128 }
129 
ParseSubStylePattern(const RefPtr<ThemeConstants> & themeConstants,const RefPtr<SwitchTheme> & theme) const130 void SwitchTheme::Builder::ParseSubStylePattern(const RefPtr<ThemeConstants>& themeConstants,
131     const RefPtr<SwitchTheme>& theme) const
132 {
133     RefPtr<ThemeStyle> switchPattern = themeConstants->GetPatternByName(THEME_PATTERN_SWITCH);
134     if (!switchPattern) {
135         LOGE("Pattern of switch is null, please check!");
136         return;
137     }
138     theme->focusBoardWidth_ = switchPattern->GetAttr<Dimension>("switch_focus_board_width", 0.0_vp);
139     theme->focusBoardHeight_ = switchPattern->GetAttr<Dimension>("switch_focus_board_height", 0.0_vp);
140     theme->focusBoardRadius_ = switchPattern->GetAttr<Dimension>("switch_focus_board_radius", 0.0_vp);
141     theme->focusBoardColor_ = switchPattern->GetAttr<Color>("switch_focus_board_color", Color());
142     theme->focusedBGColorUnselected_ =
143         switchPattern->GetAttr<Color>("switch_focus_bgColor_unselected", Color());
144     theme->focusedPointColorUnselected_ =
145         switchPattern->GetAttr<Color>("switch_focus_pointColor_unselected", Color());
146     theme->pointColorUnchecked_ = switchPattern->GetAttr<Color>("switch_unchecked_pointColor", Color());
147     theme->isUseDiffPointColor_ =
148         static_cast<bool>(switchPattern->GetAttr<double>("switch_different_pointColor", 0.0));
149     theme->focusPadding_ = switchPattern->GetAttr<Dimension>("switch_focus_box_padding", 0.0_vp);
150     theme->switchOnText_ = switchPattern->GetAttr<std::string>("switch_on_text", "");
151     theme->switchOffText_ = switchPattern->GetAttr<std::string>("switch_off_text", "");
152 }
153 
SetCheckboxSize(const RefPtr<ThemeConstants> & themeConstants,const RefPtr<CheckboxTheme> & theme) const154 void CheckboxTheme::Builder::SetCheckboxSize(const RefPtr<ThemeConstants>& themeConstants,
155     const RefPtr<CheckboxTheme>& theme) const
156 {
157     RefPtr<ThemeStyle> checkboxPattern = themeConstants->GetPatternByName(THEME_PATTERN_CHECKBOX);
158     // width/height/borderRadius not exist in theme
159     theme->width_ = checkboxPattern->GetAttr<Dimension>("width", 26.0_vp);
160     theme->height_ = theme->width_;
161     theme->borderRadius_ = checkboxPattern->GetAttr<Dimension>("hover_border_radius", 4.0_vp);
162     theme->hotZoneHorizontalPadding_ =
163         checkboxPattern->GetAttr<Dimension>("hotzone_padding_horizontal", 11.0_vp);
164     theme->hotZoneVerticalPadding_ = theme->hotZoneHorizontalPadding_;
165 }
166 
167 } // namespace OHOS::Ace
168