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_OPTION_OPTION_PAINT_PROPERTY_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_OPTION_OPTION_PAINT_PROPERTY_H 18 19 #include "core/components/common/properties/color.h" 20 #include "core/components/common/properties/text_style.h" 21 #include "core/components_ng/base/inspector_filter.h" 22 #include "core/components_ng/pattern/select/select_properties.h" 23 #include "core/components_ng/render/paint_property.h" 24 25 namespace OHOS::Ace::NG { 26 27 // PaintProperty are used to set paint properties. 28 class ACE_EXPORT OptionPaintProperty : public PaintProperty { 29 DECLARE_ACE_TYPE(OptionPaintProperty, PaintProperty) 30 31 public: 32 OptionPaintProperty() = default; 33 ~OptionPaintProperty() override = default; 34 Clone()35 RefPtr<PaintProperty> Clone() const override 36 { 37 auto paintProperty = MakeRefPtr<OptionPaintProperty>(); 38 paintProperty->propHover_ = CloneHover(); 39 paintProperty->propPress_ = ClonePress(); 40 paintProperty->propNeedDivider_ = CloneNeedDivider(); 41 paintProperty->propHasIcon_ = CloneHasIcon(); 42 paintProperty->propDivider_ = CloneDivider(); 43 44 return paintProperty; 45 } 46 Reset()47 void Reset() override 48 { 49 PaintProperty::Reset(); 50 ResetHover(); 51 ResetPress(); 52 ResetNeedDivider(); 53 ResetHasIcon(); 54 ResetDivider(); 55 } 56 57 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Hover, bool, PROPERTY_UPDATE_RENDER); 58 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Press, bool, PROPERTY_UPDATE_RENDER); 59 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(NeedDivider, bool, PROPERTY_UPDATE_RENDER); 60 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(HasIcon, bool, PROPERTY_UPDATE_RENDER); 61 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(SelectModifiedWidth, float, PROPERTY_UPDATE_MEASURE); 62 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Divider, SelectDivider, PROPERTY_UPDATE_RENDER); 63 ToJsonValue(std::unique_ptr<JsonValue> & json,const InspectorFilter & filter)64 void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override 65 { 66 PaintProperty::ToJsonValue(json, filter); 67 /* no fixed attr below, just return */ 68 if (filter.IsFastFilter()) { 69 return; 70 } 71 json->PutExtAttr("hover", propHover_.value_or(false) ? "true" : "false", filter); 72 json->PutExtAttr("needDivider", propNeedDivider_.value_or(true) ? "true" : "false", filter); 73 json->PutExtAttr("hasIcon", propHasIcon_.value_or(false) ? "true" : "false", filter); 74 } 75 76 ACE_DISALLOW_COPY_AND_MOVE(OptionPaintProperty); 77 SetIdealWidthForWeb(int32_t width)78 void SetIdealWidthForWeb(int32_t width) 79 { 80 idealWidth_ = width; 81 } 82 GetIdealWidthForWeb()83 float GetIdealWidthForWeb() const 84 { 85 return idealWidth_; 86 } 87 private: 88 float idealWidth_ = -1; 89 }; 90 91 } // namespace OHOS::Ace::NG 92 93 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_OPTION_OPTION_PAINT_PROPERTY_H 94