1 /* 2 * Copyright (c) 2021 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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SLIDER_SLIDER_THEME_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SLIDER_SLIDER_THEME_H 18 19 #include "base/geometry/dimension.h" 20 #include "core/components/common/properties/color.h" 21 #include "core/components/theme/theme.h" 22 #include "core/components/theme/theme_constants.h" 23 #include "core/components/theme/theme_constants_defines.h" 24 25 namespace OHOS::Ace { 26 27 /** 28 * SliderTheme defines color and styles of SliderComponent. SliderTheme should be built 29 * using SliderTheme::Builder. 30 */ 31 class SliderTheme : public virtual Theme { 32 DECLARE_ACE_TYPE(SliderTheme, Theme); 33 34 public: 35 class Builder { 36 public: 37 Builder() = default; 38 ~Builder() = default; 39 40 static constexpr Color BLOCK_COLOR_PRESSED = Color(0x19182431); 41 static constexpr Color BLOCK_OUTER_EDGE_COLOR = Color(0x0A000000); 42 static constexpr Color BLOCK_SHADOW_COLOR = Color(0x26000000); 43 static constexpr Dimension BUBBLE_TO_CIRCLE_CENTER_DISTANCE = 20.0_vp; 44 static constexpr Dimension MEASURE_CONTENT_DEFAULT_WIDTH = 40.0_vp; 45 static constexpr Dimension OUTSET_HOT_BLOCK_SHADOW_WIDTH = 4.0_vp; 46 static constexpr Dimension INSET_HOT_BLOCK_SHADOW_WIDTH = 6.0_vp; 47 static constexpr Dimension FOCUS_SIDE_DISTANCE = 2.0_vp; 48 Build(const RefPtr<ThemeConstants> & themeConstants)49 RefPtr<SliderTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const 50 { 51 RefPtr<SliderTheme> theme = AceType::Claim(new SliderTheme()); 52 if (!themeConstants) { 53 return theme; 54 } 55 // init theme from global data 56 ParsePattern(themeConstants, theme); 57 return theme; 58 } 59 ParsePattern(const RefPtr<ThemeConstants> & themeConstants,const RefPtr<SliderTheme> & theme)60 void ParsePattern(const RefPtr<ThemeConstants>& themeConstants, const RefPtr<SliderTheme>& theme) const 61 { 62 RefPtr<ThemeStyle> pattern = themeConstants->GetPatternByName(THEME_PATTERN_SLIDER); 63 if (pattern) { 64 const double defaultMarkColorAplpa = 0.1; 65 theme->trackBgColor_ = pattern->GetAttr<Color>("track_bg_color", Color::RED); 66 theme->trackSelectedColor_ = pattern->GetAttr<Color>("track_color_selected", Color::RED); 67 theme->markerColor_ = pattern->GetAttr<Color>("marker_color", Color::RED) 68 .BlendOpacity(pattern->GetAttr<double>("marker_color_alpha", defaultMarkColorAplpa)); 69 theme->tipTextColor_ = pattern->GetAttr<Color>("tip_text_color", Color::RED); 70 theme->tipColor_ = pattern->GetAttr<Color>("tip_color", Color::RED); 71 theme->blockHoverColor_ = pattern->GetAttr<Color>("block_color_hovered", Color::RED); 72 theme->blockPressedColor_ = pattern->GetAttr<Color>("block_color_pressed", BLOCK_COLOR_PRESSED); 73 theme->blockOuterEdgeColor_ = 74 pattern->GetAttr<Color>("block_outer_edge_color", BLOCK_OUTER_EDGE_COLOR); 75 theme->bubbleToCircleCenterDistance_ = 76 pattern->GetAttr<Dimension>("bubble_to_circle_center_distance", BUBBLE_TO_CIRCLE_CENTER_DISTANCE); 77 theme->measureContentDefaultWidth_ = 78 pattern->GetAttr<Dimension>("measure_content_default_width", MEASURE_CONTENT_DEFAULT_WIDTH); 79 theme->outsetHotBlockShadowWidth_ = 80 pattern->GetAttr<Dimension>("outset_hot_block_shadow_width", OUTSET_HOT_BLOCK_SHADOW_WIDTH); 81 theme->insetHotBlockShadowWidth_ = 82 pattern->GetAttr<Dimension>("inset_hot_block_shadow_width", INSET_HOT_BLOCK_SHADOW_WIDTH); 83 theme->focusSideDistance_ = 84 pattern->GetAttr<Dimension>("focus_side_distance", FOCUS_SIDE_DISTANCE); 85 theme->layoutMaxLength_ = pattern->GetAttr<Dimension>("slider_max_length", .0_vp); 86 theme->hoverAnimationDuration_ = pattern->GetAttr<double>("hover_animation_duration", 0.0); 87 theme->pressAnimationDuration_ = pattern->GetAttr<double>("press_animation_duration", 0.0); 88 theme->moveAnimationDuration_ = pattern->GetAttr<double>("move_animation_duration", 0.0); 89 theme->outsetBlockSize_ = pattern->GetAttr<Dimension>("outset_block_size", 16.0_vp); 90 theme->outsetBlockHotSize_ = pattern->GetAttr<Dimension>("outset_block_hot_region_size", 40.0_vp); 91 theme->blockColor_ = pattern->GetAttr<Color>("block_color", Color(0xffffffff)); 92 theme->outsetTrackThickness_ = pattern->GetAttr<Dimension>("outset_track_thickness", 4.0_vp); 93 theme->insetTrackThickness_ = pattern->GetAttr<Dimension>("inset_track_thickness", 20.0_vp); 94 theme->insetBlockSize_ = pattern->GetAttr<Dimension>("inset_block_size", 12.0_vp); 95 theme->insetBlockHotSize_ = pattern->GetAttr<Dimension>("inset_block_hot_region_size", 32.0_vp); 96 theme->noneTrackThickness_ = pattern->GetAttr<Dimension>("none_track_thickness", 4.0_vp); 97 theme->noneBlockHotSize_ = pattern->GetAttr<Dimension>("none_block_hot_region_size", 40.0_vp); 98 theme->markerSize_ = pattern->GetAttr<Dimension>("marker_size", 4.0_vp); 99 theme->tipFontSize_ = pattern->GetAttr<Dimension>("tip_font_size", 14.0_fp); 100 theme->tipTextPadding_ = pattern->GetAttr<Dimension>("tip_text_padding_size", 8.0_vp); 101 theme->blockShadowColor_ = BLOCK_SHADOW_COLOR; 102 theme->selectedTxt_ = pattern->GetAttr<std::string>("slider_accessibility_selected", ""); 103 theme->unselectedTxt_ = pattern->GetAttr<std::string>("slider_accessibility_unselected", ""); 104 theme->unselectedDesc_ = pattern->GetAttr<std::string>("slider_accessibility_unselectedDesc", ""); 105 theme->disabledDesc_ = pattern->GetAttr<std::string>("slider_accessibility_disabledDesc", ""); 106 } else { 107 LOGW("find pattern of slider fail"); 108 } 109 } 110 }; 111 112 ~SliderTheme() override = default; 113 GetOutsetBlockSize()114 Dimension GetOutsetBlockSize() const 115 { 116 return outsetBlockSize_; 117 } 118 GetOutsetBlockHotSize()119 Dimension GetOutsetBlockHotSize() const 120 { 121 return outsetBlockHotSize_; 122 } 123 GetInsetBlockSize()124 Dimension GetInsetBlockSize() const 125 { 126 return insetBlockSize_; 127 } 128 GetInsetBlockHotSize()129 Dimension GetInsetBlockHotSize() const 130 { 131 return insetBlockHotSize_; 132 } 133 GetBlockHoverColor()134 Color GetBlockHoverColor() const 135 { 136 return blockHoverColor_; 137 } 138 GetBlockColor()139 Color GetBlockColor() const 140 { 141 return blockColor_; 142 } 143 GetInsetTrackThickness()144 Dimension GetInsetTrackThickness() const 145 { 146 return insetTrackThickness_; 147 } 148 GetOutsetTrackThickness()149 Dimension GetOutsetTrackThickness() const 150 { 151 return outsetTrackThickness_; 152 } 153 GetNoneBlockHotSize()154 Dimension GetNoneBlockHotSize() const 155 { 156 return noneBlockHotSize_; 157 } GetNoneTrackThickness()158 Dimension GetNoneTrackThickness() const 159 { 160 return noneTrackThickness_; 161 } 162 GetMarkerSize()163 Dimension GetMarkerSize() const 164 { 165 return markerSize_; 166 } 167 GetTipFontSize()168 Dimension GetTipFontSize() const 169 { 170 return tipFontSize_; 171 } 172 GetTipTextPadding()173 Dimension GetTipTextPadding() const 174 { 175 return tipTextPadding_; 176 } 177 GetBubbleToCircleCenterDistance()178 Dimension GetBubbleToCircleCenterDistance() const 179 { 180 return bubbleToCircleCenterDistance_; 181 } 182 GetMeasureContentDefaultWidth()183 Dimension GetMeasureContentDefaultWidth() const 184 { 185 return measureContentDefaultWidth_; 186 } 187 GetOutsetHotBlockShadowWidth()188 Dimension GetOutsetHotBlockShadowWidth() const 189 { 190 return outsetHotBlockShadowWidth_; 191 } 192 GetInsetHotBlockShadowWidth()193 Dimension GetInsetHotBlockShadowWidth() const 194 { 195 return insetHotBlockShadowWidth_; 196 } 197 GetBlockPressedColor()198 Color GetBlockPressedColor() const 199 { 200 return blockPressedColor_; 201 } 202 GetBlockOuterEdgeColor()203 Color GetBlockOuterEdgeColor() const 204 { 205 return blockOuterEdgeColor_; 206 } 207 GetTipColor()208 Color GetTipColor() const 209 { 210 return tipColor_; 211 } 212 GetTipTextColor()213 Color GetTipTextColor() const 214 { 215 return tipTextColor_; 216 } 217 GetMarkerColor()218 Color GetMarkerColor() const 219 { 220 return markerColor_; 221 } 222 GetTrackBgColor()223 Color GetTrackBgColor() const 224 { 225 return trackBgColor_; 226 } 227 GetTrackSelectedColor()228 Color GetTrackSelectedColor() const 229 { 230 return trackSelectedColor_; 231 } 232 GetBlockShadowColor()233 Color GetBlockShadowColor() const 234 { 235 return blockShadowColor_; 236 } 237 GetFocusSideDistance()238 Dimension GetFocusSideDistance() const 239 { 240 return focusSideDistance_; 241 } 242 GetLayoutMaxLength()243 Dimension GetLayoutMaxLength() const 244 { 245 return layoutMaxLength_; 246 } 247 GetHoverAnimationDuration()248 double GetHoverAnimationDuration() const 249 { 250 return hoverAnimationDuration_; 251 } 252 GetPressAnimationDuration()253 double GetPressAnimationDuration() const 254 { 255 return pressAnimationDuration_; 256 } 257 GetMoveAnimationDuration()258 double GetMoveAnimationDuration() const 259 { 260 return moveAnimationDuration_; 261 } GetSelectedTxt()262 std::string GetSelectedTxt() const 263 { 264 return selectedTxt_; 265 } GetUnselectedTxt()266 std::string GetUnselectedTxt() const 267 { 268 return unselectedTxt_; 269 } GetUnselectedDesc()270 std::string GetUnselectedDesc() const 271 { 272 return unselectedDesc_; 273 } GetDisabelDesc()274 std::string GetDisabelDesc() const 275 { 276 return disabledDesc_; 277 } 278 279 protected: 280 SliderTheme() = default; 281 282 private: 283 // outset slider mode 284 Dimension outsetBlockSize_; 285 Dimension outsetBlockHotSize_; 286 Dimension outsetTrackThickness_; 287 Dimension outsetHotBlockShadowWidth_; 288 289 // inset slide mode 290 Dimension insetBlockSize_; 291 Dimension insetBlockHotSize_; 292 Dimension insetTrackThickness_; 293 Dimension insetHotBlockShadowWidth_; 294 295 //none slider mode 296 Dimension noneBlockHotSize_; 297 Dimension noneTrackThickness_; 298 299 // common 300 Dimension markerSize_; 301 Dimension tipFontSize_; 302 Dimension tipTextPadding_; 303 Dimension bubbleToCircleCenterDistance_; 304 Dimension measureContentDefaultWidth_; 305 Color blockColor_; 306 Color blockHoverColor_; 307 Color blockPressedColor_; 308 Color blockOuterEdgeColor_; 309 Color tipColor_; 310 Color tipTextColor_; 311 Color markerColor_; 312 Color trackBgColor_; 313 Color trackSelectedColor_; 314 Color blockShadowColor_; 315 316 // others 317 Dimension focusSideDistance_; 318 Dimension layoutMaxLength_; 319 double hoverAnimationDuration_ = 0.0; 320 double pressAnimationDuration_ = 0.0; 321 double moveAnimationDuration_ = 0.0; 322 323 // accessibility 324 std::string selectedTxt_ = ""; 325 std::string unselectedTxt_ = ""; 326 std::string unselectedDesc_ = ""; 327 std::string disabledDesc_ = ""; 328 }; 329 330 } // namespace OHOS::Ace 331 332 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SLIDER_SLIDER_THEME_H 333