1 /* 2 * Copyright (c) 2022-2024 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_TEXT_PICKER_TEXT_PICKER_LAYOUT_PROPERTY_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_PICKER_TEXT_PICKER_LAYOUT_PROPERTY_H 18 19 #include "base/geometry/dimension.h" 20 #include "core/components/common/layout/constants.h" 21 #include "core/components_ng/base/inspector_filter.h" 22 #include "core/components_ng/layout/layout_property.h" 23 #include "core/components_ng/pattern/linear_layout/linear_layout_property.h" 24 #include "core/components_ng/pattern/text/text_styles.h" 25 #include "core/components_ng/pattern/text_picker/textpicker_layout_property.h" 26 #include "core/components_ng/pattern/text_picker/textpicker_properties.h" 27 #include "core/components_ng/property/property.h" 28 namespace OHOS::Ace::NG { 29 class ACE_EXPORT TextPickerLayoutProperty : public LinearLayoutProperty { 30 DECLARE_ACE_TYPE(TextPickerLayoutProperty, LinearLayoutProperty); 31 32 public: TextPickerLayoutProperty()33 TextPickerLayoutProperty() : LinearLayoutProperty(false) {}; 34 ~TextPickerLayoutProperty() override = default; 35 Clone()36 RefPtr<LayoutProperty> Clone() const override 37 { 38 auto value = MakeRefPtr<TextPickerLayoutProperty>(); 39 value->LayoutProperty::UpdateLayoutProperty(DynamicCast<LayoutProperty>(this)); 40 value->propDefaultPickerItemHeight_ = CloneDefaultPickerItemHeight(); 41 value->propGradientHeight_ = CloneGradientHeight(); 42 value->propSelected_ = CloneSelected(); 43 value->propValue_ = CloneValue(); 44 value->propSelecteds_ = CloneSelecteds(); 45 value->propValues_ = CloneValues(); 46 value->propSelectedIndex_ = CloneSelectedIndex(); 47 value->propDisappearTextStyle_ = CloneDisappearTextStyle(); 48 value->propTextStyle_ = CloneTextStyle(); 49 value->propSelectedTextStyle_ = CloneSelectedTextStyle(); 50 value->propCanLoop_ = CloneCanLoop(); 51 value->propDivider_ = CloneDivider(); 52 value->propDisableTextStyleAnimation_ = CloneDisableTextStyleAnimation(); 53 value->propDefaultTextStyle_ = CloneDefaultTextStyle(); 54 value->propDefaultTextOverflow_ = CloneDefaultTextOverflow(); 55 return value; 56 } 57 Reset()58 void Reset() override 59 { 60 LinearLayoutProperty::Reset(); 61 ResetDefaultPickerItemHeight(); 62 ResetGradientHeight(); 63 ResetSelected(); 64 ResetValue(); 65 ResetSelecteds(); 66 ResetValues(); 67 ResetSelectedIndex(); 68 ResetDisappearTextStyle(); 69 ResetTextStyle(); 70 ResetSelectedTextStyle(); 71 ResetCanLoop(); 72 ResetDivider(); 73 ResetDisableTextStyleAnimation(); 74 ResetDefaultTextStyle(); 75 ResetDefaultTextOverflow(); 76 } 77 ToJsonValue(std::unique_ptr<JsonValue> & json,const InspectorFilter & filter)78 void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override 79 { 80 LayoutProperty::ToJsonValue(json, filter); 81 /* no fixed attr below, just return */ 82 if (filter.IsFastFilter()) { 83 return; 84 } 85 json->PutExtAttr("defaultPickerItemHeight", 86 GetDefaultPickerItemHeightValue(Dimension(0)).ToString().c_str(), filter); 87 json->Put("gradientHeight", GetGradientHeightValue(Dimension(0)).ToString().c_str()); 88 json->PutExtAttr("selected", std::to_string(GetSelectedValue(0)).c_str(), filter); 89 json->PutExtAttr("value", GetValueValue("").c_str(), filter); 90 if (propDivider_.has_value()) { 91 auto divider = JsonUtil::Create(true); 92 divider->Put("strokeWidth", propDivider_.value().strokeWidth.ToString().c_str()); 93 divider->Put("startMargin", propDivider_.value().startMargin.ToString().c_str()); 94 divider->Put("endMargin", propDivider_.value().endMargin.ToString().c_str()); 95 divider->Put("color", propDivider_.value().color.ColorToString().c_str()); 96 json->PutExtAttr("divider", divider, filter); 97 } else { 98 auto divider = JsonUtil::Create(true); 99 json->PutExtAttr("divider", divider, filter); 100 } 101 102 auto jsonArraySelected = JsonUtil::CreateArray(true); 103 auto arraySelected = CloneSelecteds().value_or(std::vector<uint32_t>()); 104 for (uint32_t i = 0; i < arraySelected.size(); i++) { 105 auto index = std::to_string(i); 106 jsonArraySelected->Put(index.c_str(), std::to_string(arraySelected[i]).c_str()); 107 } 108 json->PutExtAttr("selecteds", jsonArraySelected, filter); 109 110 auto jsonArraySelectedIndex = JsonUtil::CreateArray(true); 111 auto arraySelectedIndex = CloneSelecteds().value_or(std::vector<uint32_t>()); 112 for (uint32_t i = 0; i < arraySelectedIndex.size(); i++) { 113 auto index = std::to_string(i); 114 jsonArraySelectedIndex->Put(index.c_str(), std::to_string(arraySelectedIndex[i]).c_str()); 115 } 116 json->PutExtAttr("selectedIndex", jsonArraySelectedIndex, filter); 117 118 auto jsonArrayValue = JsonUtil::CreateArray(true); 119 auto arrayValue = CloneValues().value_or(std::vector<std::string>()); 120 for (uint32_t i = 0; i < arrayValue.size(); i++) { 121 auto index = std::to_string(i); 122 jsonArrayValue->Put(index.c_str(), arrayValue[i].c_str()); 123 } 124 json->PutExtAttr("values", jsonArrayValue, filter); 125 126 auto disappearFont = JsonUtil::Create(true); 127 disappearFont->Put("size", GetDisappearFontSizeValue(Dimension(0)).ToString().c_str()); 128 disappearFont->Put("weight", V2::ConvertWrapFontWeightToStirng( 129 GetDisappearWeight().value_or(FontWeight::NORMAL)).c_str()); 130 auto disappearTextStyle = JsonUtil::Create(true); 131 disappearTextStyle->Put("color", GetDisappearColor().value_or(Color::BLACK).ColorToString().c_str()); 132 disappearTextStyle->Put("font", disappearFont); 133 json->PutExtAttr("disappearTextStyle", disappearTextStyle, filter); 134 135 auto normalFont = JsonUtil::Create(true); 136 normalFont->Put("size", GetFontSizeValue(Dimension(0)).ToString().c_str()); 137 normalFont->Put("weight", V2::ConvertWrapFontWeightToStirng(GetWeight().value_or(FontWeight::NORMAL)).c_str()); 138 auto normalTextStyle = JsonUtil::Create(true); 139 normalTextStyle->Put("color", GetColor().value_or(Color::BLACK).ColorToString().c_str()); 140 normalTextStyle->Put("font", normalFont); 141 json->PutExtAttr("textStyle", normalTextStyle, filter); 142 143 auto selectedFont = JsonUtil::Create(true); 144 selectedFont->Put("size", GetSelectedFontSizeValue(Dimension(0)).ToString().c_str()); 145 selectedFont->Put("weight", V2::ConvertWrapFontWeightToStirng( 146 GetSelectedWeight().value_or(FontWeight::NORMAL)).c_str()); 147 auto selectedTextStyle = JsonUtil::Create(true); 148 selectedTextStyle->Put("color", GetSelectedColor().value_or(Color::BLACK).ColorToString().c_str()); 149 selectedTextStyle->Put("font", selectedFont); 150 json->PutExtAttr("selectedTextStyle", selectedTextStyle, filter); 151 auto canLoop = GetCanLoopValue(); 152 json->PutExtAttr("canLoop", canLoop ? "true" : "false", filter); 153 154 auto isDisableTextStyleAnimation = GetDisableTextStyleAnimation().value_or(false); 155 json->PutExtAttr("disableTextStyleAnimation", isDisableTextStyleAnimation ? "true" : "false", filter); 156 157 auto defaultFont = JsonUtil::Create(true); 158 defaultFont->Put("size", GetDefaultFontSizeValue(Dimension(0)).ToString().c_str()); 159 defaultFont->Put("weight", V2::ConvertWrapFontWeightToStirng( 160 GetDefaultWeight().value_or(FontWeight::NORMAL)).c_str()); 161 auto defaultTextStyle = JsonUtil::Create(true); 162 defaultTextStyle->Put("color", GetDefaultColor().value_or(Color::BLACK).ColorToString().c_str()); 163 defaultTextStyle->Put("minFontSize", GetDefaultMinFontSize().value_or(Dimension()).ToString().c_str()); 164 defaultTextStyle->Put("maxFontSize", GetDefaultMaxFontSize().value_or(Dimension()).ToString().c_str()); 165 defaultTextStyle->Put("overflow", 166 V2::ConvertWrapTextOverflowToString(GetDefaultTextOverflow().value_or(TextOverflow::CLIP)).c_str()); 167 defaultTextStyle->Put("font", defaultFont); 168 json->PutExtAttr("defaultTextStyle", defaultTextStyle, filter); 169 } 170 171 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(DefaultPickerItemHeight, Dimension, PROPERTY_UPDATE_MEASURE); 172 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(GradientHeight, Dimension, PROPERTY_UPDATE_MEASURE); 173 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(CanLoop, bool, PROPERTY_UPDATE_MEASURE); 174 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Selected, uint32_t, PROPERTY_UPDATE_MEASURE); 175 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Value, std::string, PROPERTY_UPDATE_MEASURE); 176 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Selecteds, std::vector<uint32_t>, PROPERTY_UPDATE_MEASURE); 177 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Values, std::vector<std::string>, PROPERTY_UPDATE_MEASURE); 178 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(SelectedIndex, std::vector<uint32_t>, PROPERTY_UPDATE_MEASURE); 179 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Divider, ItemDivider, PROPERTY_UPDATE_MEASURE); 180 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(DisableTextStyleAnimation, bool, PROPERTY_UPDATE_MEASURE); 181 182 ACE_DEFINE_PROPERTY_GROUP(DisappearTextStyle, FontStyle); 183 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 184 DisappearTextStyle, FontSize, DisappearFontSize, Dimension, PROPERTY_UPDATE_MEASURE); 185 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 186 DisappearTextStyle, TextColor, DisappearColor, Color, PROPERTY_UPDATE_MEASURE_SELF); 187 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 188 DisappearTextStyle, FontWeight, DisappearWeight, FontWeight, PROPERTY_UPDATE_MEASURE); 189 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 190 DisappearTextStyle, FontFamily, DisappearFontFamily, std::vector<std::string>, PROPERTY_UPDATE_MEASURE); 191 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 192 DisappearTextStyle, ItalicFontStyle, DisappearFontStyle, Ace::FontStyle, PROPERTY_UPDATE_MEASURE); 193 194 ACE_DEFINE_PROPERTY_GROUP(TextStyle, FontStyle); 195 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(TextStyle, FontSize, FontSize, Dimension, PROPERTY_UPDATE_MEASURE); 196 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(TextStyle, TextColor, Color, Color, PROPERTY_UPDATE_MEASURE_SELF); 197 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(TextStyle, FontWeight, Weight, FontWeight, PROPERTY_UPDATE_MEASURE); 198 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 199 TextStyle, FontFamily, FontFamily, std::vector<std::string>, PROPERTY_UPDATE_MEASURE); 200 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 201 TextStyle, ItalicFontStyle, FontStyle, Ace::FontStyle, PROPERTY_UPDATE_MEASURE); 202 203 ACE_DEFINE_PROPERTY_GROUP(SelectedTextStyle, FontStyle); 204 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 205 SelectedTextStyle, FontSize, SelectedFontSize, Dimension, PROPERTY_UPDATE_MEASURE); 206 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 207 SelectedTextStyle, TextColor, SelectedColor, Color, PROPERTY_UPDATE_MEASURE_SELF); 208 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 209 SelectedTextStyle, FontWeight, SelectedWeight, FontWeight, PROPERTY_UPDATE_MEASURE); 210 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 211 SelectedTextStyle, FontFamily, SelectedFontFamily, std::vector<std::string>, PROPERTY_UPDATE_MEASURE); 212 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 213 SelectedTextStyle, ItalicFontStyle, SelectedFontStyle, Ace::FontStyle, PROPERTY_UPDATE_MEASURE); 214 215 ACE_DEFINE_PROPERTY_GROUP(DefaultTextStyle, FontStyle); 216 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 217 DefaultTextStyle, FontSize, DefaultFontSize, Dimension, PROPERTY_UPDATE_MEASURE); 218 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 219 DefaultTextStyle, TextColor, DefaultColor, Color, PROPERTY_UPDATE_MEASURE_SELF); 220 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 221 DefaultTextStyle, FontWeight, DefaultWeight, FontWeight, PROPERTY_UPDATE_MEASURE); 222 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 223 DefaultTextStyle, FontFamily, DefaultFontFamily, std::vector<std::string>, PROPERTY_UPDATE_MEASURE); 224 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 225 DefaultTextStyle, ItalicFontStyle, DefaultFontStyle, Ace::FontStyle, PROPERTY_UPDATE_MEASURE); 226 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 227 DefaultTextStyle, AdaptMinFontSize, DefaultMinFontSize, Dimension, PROPERTY_UPDATE_MEASURE); 228 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 229 DefaultTextStyle, AdaptMaxFontSize, DefaultMaxFontSize, Dimension, PROPERTY_UPDATE_MEASURE); 230 231 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(DefaultTextOverflow, TextOverflow, PROPERTY_UPDATE_MEASURE); 232 private: 233 ACE_DISALLOW_COPY_AND_MOVE(TextPickerLayoutProperty); 234 }; 235 } // namespace OHOS::Ace::NG 236 237 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_PICKER_TEXT_PICKER_LAYOUT_PROPERTY_H 238