1 /* 2 * Copyright (c) 2023 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_CALENDAR_PICKER_CALENDAR_PICKER_LAYOUT_PROPERTY_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_CALENDAR_PICKER_CALENDAR_PICKER_LAYOUT_PROPERTY_H 18 19 #include <string> 20 21 #include "core/components/calendar/calendar_theme.h" 22 #include "core/components/common/properties/color.h" 23 #include "core/components_ng/base/inspector_filter.h" 24 #include "core/components_ng/layout/layout_property.h" 25 #include "core/components_ng/pattern/calendar_picker/calendar_type_define.h" 26 #include "core/components_ng/pattern/linear_layout/linear_layout_property.h" 27 #include "core/components_ng/pattern/text/text_styles.h" 28 #include "core/components_v2/inspector/utils.h" 29 30 namespace OHOS::Ace::NG { 31 class ACE_EXPORT CalendarPickerLayoutProperty : public LinearLayoutProperty { 32 DECLARE_ACE_TYPE(CalendarPickerLayoutProperty, LinearLayoutProperty); 33 34 public: CalendarPickerLayoutProperty()35 CalendarPickerLayoutProperty() : LinearLayoutProperty(false) {}; 36 ~CalendarPickerLayoutProperty() override = default; 37 Reset()38 void Reset() override 39 { 40 LinearLayoutProperty::Reset(); 41 ResetDialogAlignType(); 42 ResetDialogOffset(); 43 ResetTextStyle(); 44 } 45 ToJsonValue(std::unique_ptr<JsonValue> & json,const InspectorFilter & filter)46 void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const override 47 { 48 LayoutProperty::ToJsonValue(json, filter); 49 /* no fixed attr below, just return */ 50 if (filter.IsFastFilter()) { 51 return; 52 } 53 auto pipeline = PipelineBase::GetCurrentContext(); 54 CHECK_NULL_VOID(pipeline); 55 RefPtr<CalendarTheme> calendarTheme = pipeline->GetTheme<CalendarTheme>(); 56 CHECK_NULL_VOID(calendarTheme); 57 auto dialogALignType = GetDialogAlignType().value_or(CalendarEdgeAlign::EDGE_ALIGN_END); 58 std::string alignType = "CalendarAlign.END"; 59 switch (dialogALignType) { 60 case CalendarEdgeAlign::EDGE_ALIGN_START: 61 alignType = "CalendarAlign.START"; 62 break; 63 case CalendarEdgeAlign::EDGE_ALIGN_CENTER: 64 alignType = "CalendarAlign.CENTER"; 65 break; 66 default: 67 break; 68 } 69 auto dialogOffset = GetDialogOffset().value_or(DimensionOffset()); 70 auto jsonDialogAlign = JsonUtil::Create(true); 71 CHECK_NULL_VOID(jsonDialogAlign); 72 jsonDialogAlign->Put("alignType", alignType.c_str()); 73 auto jsonOffset = JsonUtil::Create(true); 74 CHECK_NULL_VOID(jsonOffset); 75 jsonOffset->Put("dx", dialogOffset.GetX().ToString().c_str()); 76 jsonOffset->Put("dy", dialogOffset.GetY().ToString().c_str()); 77 jsonDialogAlign->Put("offset", jsonOffset); 78 json->PutExtAttr("edgeAlign", jsonDialogAlign, filter); 79 80 auto font = JsonUtil::Create(true); 81 CHECK_NULL_VOID(font); 82 font->Put("size", GetFontSize().value_or(calendarTheme->GetEntryFontSize()).ToString().c_str()); 83 font->Put("weight", V2::ConvertWrapFontWeightToStirng(GetWeight().value_or(FontWeight::NORMAL)).c_str()); 84 auto textStyle = JsonUtil::Create(true); 85 CHECK_NULL_VOID(textStyle); 86 textStyle->Put("color", GetColor().value_or(calendarTheme->GetEntryFontColor()).ColorToString().c_str()); 87 textStyle->Put("font", font); 88 json->PutExtAttr("textStyle", textStyle, filter); 89 } 90 91 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(DialogAlignType, CalendarEdgeAlign, PROPERTY_UPDATE_MEASURE); 92 ACE_DEFINE_PROPERTY_ITEM_WITHOUT_GROUP(DialogOffset, DimensionOffset, PROPERTY_UPDATE_MEASURE); 93 94 ACE_DEFINE_PROPERTY_GROUP(TextStyle, FontStyle); 95 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(TextStyle, FontSize, FontSize, Dimension, PROPERTY_UPDATE_MEASURE); 96 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(TextStyle, TextColor, Color, Color, PROPERTY_UPDATE_MEASURE_SELF); 97 ACE_DEFINE_PROPERTY_ITEM_WITH_GROUP_ITEM(TextStyle, FontWeight, Weight, FontWeight, PROPERTY_UPDATE_MEASURE); 98 99 protected: Clone()100 RefPtr<LayoutProperty> Clone() const override 101 { 102 auto value = MakeRefPtr<CalendarPickerLayoutProperty>(); 103 value->LayoutProperty::UpdateLayoutProperty(AceType::DynamicCast<LayoutProperty>(this)); 104 value->propDialogAlignType_ = CloneDialogAlignType(); 105 value->propDialogOffset_ = CloneDialogOffset(); 106 value->propTextStyle_ = CloneTextStyle(); 107 return value; 108 } 109 110 private: 111 ACE_DISALLOW_COPY_AND_MOVE(CalendarPickerLayoutProperty); 112 }; 113 } // namespace OHOS::Ace::NG 114 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_CALENDAR_PICKER_CALENDAR_PICKER_LAYOUT_PROPERTY_H 115