1 /* 2 * Copyright (c) 2021-2023 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_NG_PATTERNS_RATING_RATING_MODEL_NG_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_RATING_RATING_MODEL_NG_H 18 19 #include "core/common/resource/resource_object.h" 20 #include "core/components_ng/base/common_configuration.h" 21 #include "core/components_ng/pattern/rating/rating_model.h" 22 #include "core/components_ng/base/frame_node.h" 23 24 namespace OHOS::Ace::NG { 25 class RatingConfiguration : public CommonConfiguration { 26 public: RatingConfiguration(int32_t starNum,bool isIndicator,double rating,double stepSize,bool enabled)27 RatingConfiguration(int32_t starNum, bool isIndicator, double rating, double stepSize, bool enabled) 28 : CommonConfiguration(enabled), starNum_(starNum), isIndicator_(isIndicator), 29 rating_(rating), stepSize_(stepSize) {} 30 int32_t starNum_; 31 bool isIndicator_; 32 double rating_; 33 double stepSize_; 34 }; 35 using RatingMakeCallback = 36 std::function<RefPtr<FrameNode>(const RatingConfiguration& ratingConfiguration)>; 37 class ACE_EXPORT RatingModelNG : public OHOS::Ace::RatingModel { 38 public: 39 void Create(double rating = .0, bool indicator = false) override; 40 void SetRatingScore(double value) override; 41 void SetIndicator(bool value) override; 42 void SetStars(int32_t value) override; 43 void SetStepSize(double value) override; 44 void SetForegroundSrc(const std::string& value, bool flag = false) override; 45 void SetSecondarySrc(const std::string& value, bool flag = false) override; 46 void SetBackgroundSrc(const std::string& value, bool flag = false) override; 47 void SetOnChange(RatingChangeEvent&& onChange) override; 48 void SetOnChangeEvent(RatingChangeEvent&& onChangeEvent) override; 49 void CreateWithMediaResourceObj(const RefPtr<ResourceObject>& resObj, const RatingUriType ratingUriType) override; 50 51 static void CreateWithMediaResourceObj( 52 FrameNode* frameNode, const RefPtr<ResourceObject>& resObj, const RatingUriType ratingUriType); 53 static RefPtr<FrameNode> CreateFrameNode(int32_t nodeId); 54 static void SetStars(FrameNode* frameNode, int32_t value); 55 static void SetStepSize(FrameNode* frameNode, double value); 56 static void SetForegroundSrc(FrameNode* frameNode, const std::string& value, bool flag = false); 57 static void SetSecondarySrc(FrameNode* frameNode, const std::string& value, bool flag = false); 58 static void SetBackgroundSrc(FrameNode* frameNode, const std::string& value, bool flag = false); 59 static void SetBuilderFunc(FrameNode* frameNode, NG::RatingMakeCallback&& jsMake); 60 static void SetChangeValue(FrameNode* frameNode, double value); 61 static void SetRatingOptions(FrameNode* frameNode, double rating = .0, bool indicator = false); 62 static void SetOnChange(FrameNode* frameNode, RatingChangeEvent&& onChange); 63 64 private: 65 static std::string StringTypeToStr(const RatingUriType ratingUriType); 66 static void UpdateStarStyleImage(FrameNode* frameNode, const RatingUriType& ratingUriType, 67 const std::string& result); 68 }; 69 } // namespace OHOS::Ace::NG 70 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_RATING_RATING_MODEL_NG_H 71