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