1 /* 2 * Copyright (c) 2022 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_PATTERN_RATING_RATING_PROPERTY_GROUP_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_RATING_RATING_PROPERTY_GROUP_H 18 19 #include "base/geometry/ng/size_t.h" 20 #include "base/resource/internal_resource.h" 21 #include "core/components_ng/base/inspector_filter.h" 22 #include "core/components_ng/property/property.h" 23 #include "core/image/image_source_info.h" 24 #include "core/pipeline/base/constants.h" 25 26 namespace OHOS::Ace::NG { 27 struct RatingPropertyGroup { 28 ACE_DEFINE_PROPERTY_GROUP_ITEM(Indicator, bool); 29 ACE_DEFINE_PROPERTY_GROUP_ITEM(Stars, int32_t); 30 31 ACE_DEFINE_PROPERTY_GROUP_ITEM(ForegroundImageSourceInfo, ImageSourceInfo); 32 ACE_DEFINE_PROPERTY_GROUP_ITEM(SecondaryImageSourceInfo, ImageSourceInfo); 33 ACE_DEFINE_PROPERTY_GROUP_ITEM(BackgroundImageSourceInfo, ImageSourceInfo); 34 ToJsonValueRatingPropertyGroup35 void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const 36 { 37 /* no fixed attr below, just return */ 38 if (filter.IsFastFilter()) { 39 return; 40 } 41 json->PutExtAttr("indicator", GetIndicator().value_or(false) ? "true" : "false", filter); 42 json->PutExtAttr("stars", std::to_string(GetStars().value_or(DEFAULT_RATING_STAR_NUM)).c_str(), filter); 43 auto jsonStarStyle = JsonUtil::Create(true); 44 jsonStarStyle->Put("backgroundUri", propBackgroundImageSourceInfo.value_or(ImageSourceInfo()).GetSrc().c_str()); 45 jsonStarStyle->Put("foregroundUri", propForegroundImageSourceInfo.value_or(ImageSourceInfo()).GetSrc().c_str()); 46 jsonStarStyle->Put("secondaryUri", propSecondaryImageSourceInfo.value_or(ImageSourceInfo()).GetSrc().c_str()); 47 json->PutExtAttr("starStyle", jsonStarStyle->ToString().c_str(), filter); 48 } 49 }; 50 51 } // namespace OHOS::Ace::NG 52 53 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_RATING_RATING_PROPERTY_GROUP_H 54