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/components_ng/base/common_configuration.h" 20 #include "core/components_ng/pattern/rating/rating_model.h" 21 #include "core/components_ng/base/frame_node.h" 22 23 namespace OHOS::Ace::NG { 24 class RatingConfiguration : public CommonConfiguration { 25 public: RatingConfiguration(int32_t starNum,bool isIndicator,double rating,double stepSize,bool enabled)26 RatingConfiguration(int32_t starNum, bool isIndicator, double rating, double stepSize, bool enabled) 27 : CommonConfiguration(enabled), starNum_(starNum), isIndicator_(isIndicator), 28 rating_(rating), stepSize_(stepSize) {} 29 int32_t starNum_; 30 bool isIndicator_; 31 double rating_; 32 double stepSize_; 33 }; 34 using RatingMakeCallback = 35 std::function<RefPtr<FrameNode>(const RatingConfiguration& ratingConfiguration)>; 36 class ACE_EXPORT RatingModelNG : public OHOS::Ace::RatingModel { 37 public: 38 void Create(double rating = .0, bool indicator = false) override; 39 void SetRatingScore(double value) override; 40 void SetIndicator(bool value) override; 41 void SetStars(int32_t value) override; 42 void SetStepSize(double value) override; 43 void SetForegroundSrc(const std::string& value, bool flag = false) override; 44 void SetSecondarySrc(const std::string& value, bool flag = false) override; 45 void SetBackgroundSrc(const std::string& value, bool flag = false) override; 46 void SetOnChange(ChangeEvent&& onChange) override; 47 void SetOnChangeEvent(ChangeEvent&& onChangeEvent) override; 48 49 static void SetStars(FrameNode* frameNode, int32_t value); 50 static void SetStepSize(FrameNode* frameNode, double value); 51 static void SetForegroundSrc(FrameNode* frameNode, const std::string& value, bool flag = false); 52 static void SetSecondarySrc(FrameNode* frameNode, const std::string& value, bool flag = false); 53 static void SetBackgroundSrc(FrameNode* frameNode, const std::string& value, bool flag = false); 54 static void SetBuilderFunc(FrameNode* frameNode, NG::RatingMakeCallback&& jsMake); 55 static void SetChangeValue(FrameNode* frameNode, double value); 56 }; 57 } // namespace OHOS::Ace::NG 58 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_RATING_RATING_MODEL_NG_H 59