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 return value; 53 } 54 Reset()55 void Reset() override 56 { 57 LinearLayoutProperty::Reset(); 58 ResetDefaultPickerItemHeight(); 59 ResetGradientHeight(); 60 ResetSelected(); 61 ResetValue(); 62 ResetSelecteds(); 63 ResetValues(); 64 ResetSelectedIndex(); 65 ResetDisappearTextStyle(); 66 ResetTextStyle(); 67 ResetSelectedTextStyle(); 68 ResetCanLoop(); 69 ResetDivider(); 70 } 71 ToJsonValue(std::unique_ptr<JsonValue> & json,const InspectorFilter & filter)72 void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override 73 { 74 LayoutProperty::ToJsonValue(json, filter); 75 /* no fixed attr below, just return */ 76 if (filter.IsFastFilter()) { 77 return; 78 } 79 json->PutExtAttr("defaultPickerItemHeight", 80 GetDefaultPickerItemHeightValue(Dimension(0)).ToString().c_str(), filter); 81 json->Put("gradientHeight", GetGradientHeightValue(Dimension(0)).ToString().c_str()); 82 json->PutExtAttr("selected", std::to_string(GetSelectedValue(0)).c_str(), filter); 83 json->PutExtAttr("value", GetValueValue("").c_str(), filter); 84 if (propDivider_.has_value()) { 85 auto divider = JsonUtil::Create(true); 86 divider->Put("strokeWidth", propDivider_.value().strokeWidth.ToString().c_str()); 87 divider->Put("startMargin", propDivider_.value().startMargin.ToString().c_str()); 88 divider->Put("endMargin", propDivider_.value().endMargin.ToString().c_str()); 89 divider->Put("color", propDivider_.value().color.ColorToString().c_str()); 90 json->PutExtAttr("divider", divider, filter); 91 } else { 92 auto divider = JsonUtil::Create(true); 93 json->PutExtAttr("divider", divider, filter); 94 } 95 96 auto jsonArraySelected = JsonUtil::CreateArray(true); 97 auto arraySelected = CloneSelecteds().value_or(std::vector<uint32_t>()); 98 for (uint32_t i = 0; i < arraySelected.size(); i++) { 99 auto index = std::to_string(i); 100 jsonArraySelected->Put(index.c_str(), std::to_string(arraySelected[i]).c_str()); 101 } 102 json->PutExtAttr("selecteds", jsonArraySelected, filter); 103 104 auto jsonArraySelectedIndex = JsonUtil::CreateArray(true); 105 auto arraySelectedIndex = CloneSelecteds().value_or(std::vector<uint32_t>()); 106 for (uint32_t i = 0; i < arraySelectedIndex.size(); i++) { 107 auto index = std::to_string(i); 108 jsonArraySelectedIndex->Put(index.c_str(), std::to_string(arraySelectedIndex[i]).c_str()); 109 } 110 json->PutExtAttr("selectedIndex", jsonArraySelectedIndex, filter); 111 112 auto jsonArrayValue = JsonUtil::CreateArray(true); 113 auto arrayValue = CloneValues().value_or(std::vector<std::string>()); 114 for (uint32_t i = 0; i < arrayValue.size(); i++) { 115 auto index = std::to_string(i); 116 jsonArrayValue->Put(index.c_str(), arrayValue[i].c_str()); 117 } 118 json->PutExtAttr("values", jsonArrayValue, filter); 119 120 auto disappearFont = JsonUtil::Create(true); 121 disappearFont->Put("size", GetDisappearFontSizeValue(Dimension(0)).ToString().c_str()); 122 disappearFont->Put("weight", V2::ConvertWrapFontWeightToStirng( 123 GetDisappearWeight().value_or(FontWeight::NORMAL)).c_str()); 124 auto disappearTextStyle = JsonUtil::Create(true); 125 disappearTextStyle->Put("color", GetDisappearColor().value_or(Color::BLACK).ColorToString().c_str()); 126 disappearTextStyle->Put("font", disappearFont); 127 json->PutExtAttr("disappearTextStyle", disappearTextStyle, filter); 128 129 auto normalFont = JsonUtil::Create(true); 130 normalFont->Put("size", GetFontSizeValue(Dimension(0)).ToString().c_str()); 131 normalFont->Put("weight", V2::ConvertWrapFontWeightToStirng(GetWeight().value_or(FontWeight::NORMAL)).c_str()); 132 auto normalTextStyle = JsonUtil::Create(true); 133 normalTextStyle->Put("color", GetColor().value_or(Color::BLACK).ColorToString().c_str()); 134 normalTextStyle->Put("font", normalFont); 135 json->PutExtAttr("textStyle", normalTextStyle, filter); 136 137 auto selectedFont = JsonUtil::Create(true); 138 selectedFont->Put("size", GetSelectedFontSizeValue(Dimension(0)).ToString().c_str()); 139 selectedFont->Put("weight", V2::ConvertWrapFontWeightToStirng( 140 GetSelectedWeight().value_or(FontWeight::NORMAL)).c_str()); 141 auto selectedTextStyle = JsonUtil::Create(true); 142 selectedTextStyle->Put("color", GetSelectedColor().value_or(Color::BLACK).ColorToString().c_str()); 143 selectedTextStyle->Put("font", selectedFont); 144 json->PutExtAttr("selectedTextStyle", selectedTextStyle, filter); 145 auto canLoop = GetCanLoopValue(); 146 json->PutExtAttr("canLoop", canLoop ? "true" : "false", filter); 147 } 148 149 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(DefaultPickerItemHeight, Dimension, PROPERTY_UPDATE_MEASURE); 150 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(GradientHeight, Dimension, PROPERTY_UPDATE_MEASURE); 151 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(CanLoop, bool, PROPERTY_UPDATE_MEASURE); 152 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Selected, uint32_t, PROPERTY_UPDATE_MEASURE); 153 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Value, std::string, PROPERTY_UPDATE_MEASURE); 154 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Selecteds, std::vector<uint32_t>, PROPERTY_UPDATE_MEASURE); 155 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Values, std::vector<std::string>, PROPERTY_UPDATE_MEASURE); 156 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(SelectedIndex, std::vector<uint32_t>, PROPERTY_UPDATE_MEASURE); 157 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Divider, ItemDivider, PROPERTY_UPDATE_MEASURE); 158 159 ACE_DEFINE_PROPERTY_GROUP(DisappearTextStyle, FontStyle); 160 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 161 DisappearTextStyle, FontSize, DisappearFontSize, Dimension, PROPERTY_UPDATE_MEASURE); 162 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 163 DisappearTextStyle, TextColor, DisappearColor, Color, PROPERTY_UPDATE_MEASURE_SELF); 164 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 165 DisappearTextStyle, FontWeight, DisappearWeight, FontWeight, PROPERTY_UPDATE_MEASURE); 166 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 167 DisappearTextStyle, FontFamily, DisappearFontFamily, std::vector<std::string>, PROPERTY_UPDATE_MEASURE); 168 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 169 DisappearTextStyle, ItalicFontStyle, DisappearFontStyle, Ace::FontStyle, PROPERTY_UPDATE_MEASURE); 170 171 ACE_DEFINE_PROPERTY_GROUP(TextStyle, FontStyle); 172 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(TextStyle, FontSize, FontSize, Dimension, PROPERTY_UPDATE_MEASURE); 173 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(TextStyle, TextColor, Color, Color, PROPERTY_UPDATE_MEASURE_SELF); 174 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(TextStyle, FontWeight, Weight, FontWeight, PROPERTY_UPDATE_MEASURE); 175 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 176 TextStyle, FontFamily, FontFamily, std::vector<std::string>, PROPERTY_UPDATE_MEASURE); 177 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 178 TextStyle, ItalicFontStyle, FontStyle, Ace::FontStyle, PROPERTY_UPDATE_MEASURE); 179 180 ACE_DEFINE_PROPERTY_GROUP(SelectedTextStyle, FontStyle); 181 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 182 SelectedTextStyle, FontSize, SelectedFontSize, Dimension, PROPERTY_UPDATE_MEASURE); 183 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 184 SelectedTextStyle, TextColor, SelectedColor, Color, PROPERTY_UPDATE_MEASURE_SELF); 185 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 186 SelectedTextStyle, FontWeight, SelectedWeight, FontWeight, PROPERTY_UPDATE_MEASURE); 187 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 188 SelectedTextStyle, FontFamily, SelectedFontFamily, std::vector<std::string>, PROPERTY_UPDATE_MEASURE); 189 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 190 SelectedTextStyle, ItalicFontStyle, SelectedFontStyle, Ace::FontStyle, PROPERTY_UPDATE_MEASURE); 191 private: 192 ACE_DISALLOW_COPY_AND_MOVE(TextPickerLayoutProperty); 193 }; 194 } // namespace OHOS::Ace::NG 195 196 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_PICKER_TEXT_PICKER_LAYOUT_PROPERTY_H 197