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 value->propDigitalCrownSensitivity_ = CloneDigitalCrownSensitivity(); 56 return value; 57 } 58 Reset()59 void Reset() override 60 { 61 LinearLayoutProperty::Reset(); 62 ResetDefaultPickerItemHeight(); 63 ResetGradientHeight(); 64 ResetSelected(); 65 ResetValue(); 66 ResetSelecteds(); 67 ResetValues(); 68 ResetSelectedIndex(); 69 ResetDisappearTextStyle(); 70 ResetTextStyle(); 71 ResetSelectedTextStyle(); 72 ResetCanLoop(); 73 ResetDivider(); 74 ResetDisableTextStyleAnimation(); 75 ResetDefaultTextStyle(); 76 ResetDefaultTextOverflow(); 77 ResetDigitalCrownSensitivity(); 78 } 79 ToJsonValue(std::unique_ptr<JsonValue> & json,const InspectorFilter & filter)80 void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override 81 { 82 LayoutProperty::ToJsonValue(json, filter); 83 /* no fixed attr below, just return */ 84 if (filter.IsFastFilter()) { 85 return; 86 } 87 json->PutExtAttr("defaultPickerItemHeight", 88 GetDefaultPickerItemHeightValue(Dimension(0)).ToString().c_str(), filter); 89 json->PutExtAttr("gradientHeight", GetGradientHeightValue(Dimension(0)).ToString().c_str(), filter); 90 json->PutExtAttr("selected", std::to_string(GetSelectedValue(0)).c_str(), filter); 91 json->PutExtAttr("value", GetValueValue("").c_str(), filter); 92 Color defaultDisappearColor = Color::BLACK; 93 Color defaultNormalColor = Color::BLACK; 94 Color defaultSelectColor = Color::BLACK; 95 auto pipeline = PipelineBase::GetCurrentContext(); 96 auto frameNode = GetHost(); 97 if (pipeline && frameNode) { 98 auto pickerTheme = pipeline->GetTheme<PickerTheme>(frameNode->GetThemeScopeId()); 99 if (pickerTheme) { 100 defaultDisappearColor = pickerTheme->GetDisappearOptionStyle().GetTextColor(); 101 defaultNormalColor = pickerTheme->GetOptionStyle(false, false).GetTextColor(); 102 defaultSelectColor = pickerTheme->GetOptionStyle(true, false).GetTextColor(); 103 } 104 } 105 if (propDivider_.has_value()) { 106 auto divider = JsonUtil::Create(true); 107 divider->Put("strokeWidth", propDivider_.value().strokeWidth.ToString().c_str()); 108 divider->Put("startMargin", propDivider_.value().startMargin.ToString().c_str()); 109 divider->Put("endMargin", propDivider_.value().endMargin.ToString().c_str()); 110 divider->Put("color", propDivider_.value().color.ColorToString().c_str()); 111 json->PutExtAttr("divider", divider, filter); 112 } else { 113 auto divider = JsonUtil::Create(true); 114 json->PutExtAttr("divider", divider, filter); 115 } 116 117 auto jsonArraySelected = JsonUtil::CreateArray(true); 118 auto arraySelected = CloneSelecteds().value_or(std::vector<uint32_t>()); 119 for (uint32_t i = 0; i < arraySelected.size(); i++) { 120 auto index = std::to_string(i); 121 jsonArraySelected->Put(index.c_str(), std::to_string(arraySelected[i]).c_str()); 122 } 123 json->PutExtAttr("selecteds", jsonArraySelected, filter); 124 125 auto jsonArraySelectedIndex = JsonUtil::CreateArray(true); 126 auto arraySelectedIndex = CloneSelecteds().value_or(std::vector<uint32_t>()); 127 for (uint32_t i = 0; i < arraySelectedIndex.size(); i++) { 128 auto index = std::to_string(i); 129 jsonArraySelectedIndex->Put(index.c_str(), std::to_string(arraySelectedIndex[i]).c_str()); 130 } 131 json->PutExtAttr("selectedIndex", jsonArraySelectedIndex, filter); 132 133 auto jsonArrayValue = JsonUtil::CreateArray(true); 134 auto arrayValue = CloneValues().value_or(std::vector<std::string>()); 135 for (uint32_t i = 0; i < arrayValue.size(); i++) { 136 auto index = std::to_string(i); 137 jsonArrayValue->Put(index.c_str(), arrayValue[i].c_str()); 138 } 139 json->PutExtAttr("values", jsonArrayValue, filter); 140 141 auto disappearFont = JsonUtil::Create(true); 142 disappearFont->Put("size", GetDisappearFontSizeValue(Dimension(0)).ToString().c_str()); 143 disappearFont->Put("weight", V2::ConvertWrapFontWeightToStirng( 144 GetDisappearWeight().value_or(FontWeight::NORMAL)).c_str()); 145 auto disappearTextStyle = JsonUtil::Create(true); 146 disappearTextStyle->Put("color", GetDisappearColor().value_or(defaultDisappearColor).ColorToString().c_str()); 147 disappearTextStyle->Put("font", disappearFont); 148 json->PutExtAttr("disappearTextStyle", disappearTextStyle, filter); 149 150 auto normalFont = JsonUtil::Create(true); 151 normalFont->Put("size", GetFontSizeValue(Dimension(0)).ToString().c_str()); 152 normalFont->Put("weight", V2::ConvertWrapFontWeightToStirng(GetWeight().value_or(FontWeight::NORMAL)).c_str()); 153 auto normalTextStyle = JsonUtil::Create(true); 154 normalTextStyle->Put("color", GetColor().value_or(defaultNormalColor).ColorToString().c_str()); 155 normalTextStyle->Put("font", normalFont); 156 json->PutExtAttr("textStyle", normalTextStyle, filter); 157 158 auto selectedFont = JsonUtil::Create(true); 159 selectedFont->Put("size", GetSelectedFontSizeValue(Dimension(0)).ToString().c_str()); 160 selectedFont->Put("weight", V2::ConvertWrapFontWeightToStirng( 161 GetSelectedWeight().value_or(FontWeight::NORMAL)).c_str()); 162 auto selectedTextStyle = JsonUtil::Create(true); 163 selectedTextStyle->Put("color", GetSelectedColor().value_or(defaultSelectColor).ColorToString().c_str()); 164 selectedTextStyle->Put("font", selectedFont); 165 json->PutExtAttr("selectedTextStyle", selectedTextStyle, filter); 166 auto canLoop = GetCanLoopValue(); 167 json->PutExtAttr("canLoop", canLoop ? "true" : "false", filter); 168 169 auto isDisableTextStyleAnimation = GetDisableTextStyleAnimation().value_or(false); 170 json->PutExtAttr("disableTextStyleAnimation", isDisableTextStyleAnimation ? "true" : "false", filter); 171 172 auto defaultFont = JsonUtil::Create(true); 173 defaultFont->Put("size", GetDefaultFontSizeValue(Dimension(0)).ToString().c_str()); 174 defaultFont->Put("weight", V2::ConvertWrapFontWeightToStirng( 175 GetDefaultWeight().value_or(FontWeight::NORMAL)).c_str()); 176 auto defaultTextStyle = JsonUtil::Create(true); 177 defaultTextStyle->Put("color", GetDefaultColor().value_or(Color::BLACK).ColorToString().c_str()); 178 defaultTextStyle->Put("minFontSize", GetDefaultMinFontSize().value_or(Dimension()).ToString().c_str()); 179 defaultTextStyle->Put("maxFontSize", GetDefaultMaxFontSize().value_or(Dimension()).ToString().c_str()); 180 defaultTextStyle->Put("overflow", 181 V2::ConvertWrapTextOverflowToString(GetDefaultTextOverflow().value_or(TextOverflow::CLIP)).c_str()); 182 defaultTextStyle->Put("font", defaultFont); 183 json->PutExtAttr("defaultTextStyle", defaultTextStyle, filter); 184 auto crownSensitivity = GetDigitalCrownSensitivity(); 185 json->PutExtAttr("digitalCrownSensitivity", 186 std::to_string(crownSensitivity.value_or(DEFAULT_CROWNSENSITIVITY)).c_str(), filter); 187 } 188 189 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(DefaultPickerItemHeight, Dimension, PROPERTY_UPDATE_MEASURE); 190 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(GradientHeight, Dimension, PROPERTY_UPDATE_MEASURE); 191 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(CanLoop, bool, PROPERTY_UPDATE_MEASURE); 192 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(DigitalCrownSensitivity, int32_t, PROPERTY_UPDATE_MEASURE); 193 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Selected, uint32_t, PROPERTY_UPDATE_MEASURE); 194 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Value, std::string, PROPERTY_UPDATE_MEASURE); 195 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Selecteds, std::vector<uint32_t>, PROPERTY_UPDATE_MEASURE); 196 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Values, std::vector<std::string>, PROPERTY_UPDATE_MEASURE); 197 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(SelectedIndex, std::vector<uint32_t>, PROPERTY_UPDATE_MEASURE); 198 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(Divider, ItemDivider, PROPERTY_UPDATE_MEASURE); 199 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(DisableTextStyleAnimation, bool, PROPERTY_UPDATE_MEASURE); 200 201 ACE_DEFINE_PROPERTY_GROUP(DisappearTextStyle, FontStyle); 202 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 203 DisappearTextStyle, FontSize, DisappearFontSize, Dimension, PROPERTY_UPDATE_MEASURE); 204 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 205 DisappearTextStyle, TextColor, DisappearColor, Color, PROPERTY_UPDATE_MEASURE_SELF); 206 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 207 DisappearTextStyle, FontWeight, DisappearWeight, FontWeight, PROPERTY_UPDATE_MEASURE); 208 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 209 DisappearTextStyle, FontFamily, DisappearFontFamily, std::vector<std::string>, PROPERTY_UPDATE_MEASURE); 210 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 211 DisappearTextStyle, ItalicFontStyle, DisappearFontStyle, Ace::FontStyle, PROPERTY_UPDATE_MEASURE); 212 213 ACE_DEFINE_PROPERTY_GROUP(TextStyle, FontStyle); 214 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(TextStyle, FontSize, FontSize, Dimension, PROPERTY_UPDATE_MEASURE); 215 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(TextStyle, TextColor, Color, Color, PROPERTY_UPDATE_MEASURE_SELF); 216 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(TextStyle, FontWeight, Weight, FontWeight, PROPERTY_UPDATE_MEASURE); 217 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 218 TextStyle, FontFamily, FontFamily, std::vector<std::string>, PROPERTY_UPDATE_MEASURE); 219 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 220 TextStyle, ItalicFontStyle, FontStyle, Ace::FontStyle, PROPERTY_UPDATE_MEASURE); 221 222 ACE_DEFINE_PROPERTY_GROUP(SelectedTextStyle, FontStyle); 223 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 224 SelectedTextStyle, FontSize, SelectedFontSize, Dimension, PROPERTY_UPDATE_MEASURE); 225 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 226 SelectedTextStyle, TextColor, SelectedColor, Color, PROPERTY_UPDATE_MEASURE_SELF); 227 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 228 SelectedTextStyle, FontWeight, SelectedWeight, FontWeight, PROPERTY_UPDATE_MEASURE); 229 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 230 SelectedTextStyle, FontFamily, SelectedFontFamily, std::vector<std::string>, PROPERTY_UPDATE_MEASURE); 231 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 232 SelectedTextStyle, ItalicFontStyle, SelectedFontStyle, Ace::FontStyle, PROPERTY_UPDATE_MEASURE); 233 234 ACE_DEFINE_PROPERTY_GROUP(DefaultTextStyle, FontStyle); 235 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 236 DefaultTextStyle, FontSize, DefaultFontSize, Dimension, PROPERTY_UPDATE_MEASURE); 237 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 238 DefaultTextStyle, TextColor, DefaultColor, Color, PROPERTY_UPDATE_MEASURE_SELF); 239 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 240 DefaultTextStyle, FontWeight, DefaultWeight, FontWeight, PROPERTY_UPDATE_MEASURE); 241 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 242 DefaultTextStyle, FontFamily, DefaultFontFamily, std::vector<std::string>, PROPERTY_UPDATE_MEASURE); 243 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 244 DefaultTextStyle, ItalicFontStyle, DefaultFontStyle, Ace::FontStyle, PROPERTY_UPDATE_MEASURE); 245 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 246 DefaultTextStyle, AdaptMinFontSize, DefaultMinFontSize, Dimension, PROPERTY_UPDATE_MEASURE); 247 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM( 248 DefaultTextStyle, AdaptMaxFontSize, DefaultMaxFontSize, Dimension, PROPERTY_UPDATE_MEASURE); 249 250 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(DefaultTextOverflow, TextOverflow, PROPERTY_UPDATE_MEASURE); 251 private: 252 ACE_DISALLOW_COPY_AND_MOVE(TextPickerLayoutProperty); 253 }; 254 } // namespace OHOS::Ace::NG 255 256 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_PICKER_TEXT_PICKER_LAYOUT_PROPERTY_H 257