1 /* 2 * Copyright (c) 2022 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_PROPERTIES_OVERLAY_PROPERTY_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PROPERTIES_OVERLAY_PROPERTY_H 18 19 #include <memory> 20 21 #include "base/geometry/dimension.h" 22 #include "base/geometry/ng/offset_t.h" 23 #include "core/components/common/properties/alignment.h" 24 #include "core/components_ng/base/inspector_filter.h" 25 #include "core/components_ng/property/property.h" 26 27 namespace OHOS::Ace::NG { 28 29 struct OverlayOptions { 30 OverlayOptions() = default; 31 ~OverlayOptions() = default; 32 std::string content; 33 Alignment align; 34 Dimension x; 35 Dimension y; 36 37 bool operator==(const OverlayOptions& value) const 38 { 39 return (content.compare(value.content) == 0) && (align == value.align) && 40 (x == value.x) && (y == value.y); 41 } 42 ToJsonValueOverlayOptions43 void ToJsonValue(std::unique_ptr<JsonValue>& json, const InspectorFilter& filter) const 44 { 45 /* no fixed attr below, just return */ 46 if (filter.IsFastFilter()) { 47 return; 48 } 49 auto jsonOverlay = JsonUtil::Create(true); 50 jsonOverlay->Put("title", content.c_str()); 51 auto jsonOptions = JsonUtil::Create(true); 52 // should get TextDirection 53 jsonOptions->Put("align", align.GetAlignmentStr(TextDirection::LTR).c_str()); 54 auto jsonOffset = JsonUtil::Create(true); 55 jsonOffset->Put("x", x.ToString().c_str()); 56 jsonOffset->Put("y", y.ToString().c_str()); 57 jsonOptions->Put("offset", jsonOffset); 58 jsonOverlay->Put("options", jsonOptions); 59 json->PutExtAttr("overlay", jsonOverlay, filter); 60 } 61 }; 62 63 } // namespace OHOS::Ace::NG 64 65 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PROPERTIES_OVERLAY_PROPERTY_H 66