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_RADIO_RADIO_PAINT_PROPERTY_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_RADIO_RADIO_PAINT_PROPERTY_H 18 19 #include "core/common/container.h" 20 #include "core/components/common/properties/color.h" 21 #include "core/components_ng/base/inspector_filter.h" 22 #include "core/components_ng/render/paint_property.h" 23 24 namespace OHOS::Ace::NG { 25 26 class RadioPaintProperty : public PaintProperty { 27 DECLARE_ACE_TYPE(RadioPaintProperty, PaintProperty) 28 29 public: 30 RadioPaintProperty() = default; 31 ~RadioPaintProperty() override = default; 32 Clone()33 RefPtr<PaintProperty> Clone() const override 34 { 35 auto paintProperty = MakeRefPtr<RadioPaintProperty>(); 36 paintProperty->UpdatePaintProperty(this); 37 paintProperty->propRadioCheck_ = CloneRadioCheck(); 38 paintProperty->propRadioCheckedBackgroundColor_ = CloneRadioCheckedBackgroundColor(); 39 paintProperty->propRadioUncheckedBorderColor_ = CloneRadioUncheckedBorderColor(); 40 paintProperty->propRadioIndicatorColor_ = CloneRadioIndicatorColor(); 41 paintProperty->propRadioIndicator_ = CloneRadioIndicator(); 42 return paintProperty; 43 } 44 Reset()45 void Reset() override 46 { 47 PaintProperty::Reset(); 48 ResetRadioCheck(); 49 ResetRadioCheckedBackgroundColor(); 50 ResetRadioUncheckedBorderColor(); 51 ResetRadioIndicatorColor(); 52 ResetRadioIndicator(); 53 } 54 ToJsonValue(std::unique_ptr<JsonValue> & json,const InspectorFilter & filter)55 void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override 56 { 57 PaintProperty::ToJsonValue(json, filter); 58 /* no fixed attr below, just return */ 59 if (filter.IsFastFilter()) { 60 return; 61 } 62 auto pipeline = PipelineBase::GetCurrentContext(); 63 CHECK_NULL_VOID(pipeline); 64 auto radioTheme = pipeline->GetTheme<RadioTheme>(); 65 json->PutExtAttr("checked", GetRadioCheck().value_or(false) ? "true" : "false", filter); 66 auto jsonValue = JsonUtil::Create(true); 67 jsonValue->Put("checkedBackgroundColor", 68 GetRadioCheckedBackgroundColor().value_or(radioTheme->GetActiveColor()).ColorToString().c_str()); 69 jsonValue->Put("uncheckedBorderColor", 70 GetRadioUncheckedBorderColor().value_or(radioTheme->GetInactiveColor()).ColorToString().c_str()); 71 jsonValue->Put( 72 "indicatorColor", GetRadioIndicatorColor().value_or(radioTheme->GetPointColor()).ColorToString().c_str()); 73 if (Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_TWELVE)) { 74 static const char* INDICATRO_TYPE[] = { "TICK", "DOT", "CUSTOM" }; 75 json->PutExtAttr("indicatorType", 76 INDICATRO_TYPE[static_cast<int32_t>(GetRadioIndicator().value_or(0))], filter); 77 } 78 json->PutExtAttr("radioStyle", jsonValue->ToString().c_str(), filter); 79 } 80 81 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(RadioCheck, bool, PROPERTY_UPDATE_RENDER); 82 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(RadioCheckedBackgroundColor, Color, PROPERTY_UPDATE_RENDER); 83 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(RadioUncheckedBorderColor, Color, PROPERTY_UPDATE_RENDER); 84 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(RadioIndicatorColor, Color, PROPERTY_UPDATE_RENDER); 85 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(RadioIndicator, int32_t, PROPERTY_UPDATE_RENDER); 86 }; 87 } // namespace OHOS::Ace::NG 88 89 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_RADIO_RADIO_PAINT_PROPERTY_H 90