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_PATTERN_SWITCH_SWITCH_LAYOUT_ALGORITHM_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SWITCH_SWITCH_LAYOUT_ALGORITHM_H 18 19 #include "core/components_ng/base/ui_node.h" 20 #include "core/components_ng/layout/box_layout_algorithm.h" 21 #include "core/components_ng/layout/layout_wrapper.h" 22 #include "core/components_ng/property/layout_policy_property.h" 23 24 namespace OHOS::Ace::NG { 25 class ACE_EXPORT SwitchLayoutAlgorithm : public BoxLayoutAlgorithm { 26 DECLARE_ACE_TYPE(SwitchLayoutAlgorithm, BoxLayoutAlgorithm); 27 28 public: 29 SwitchLayoutAlgorithm() = default; 30 31 ~SwitchLayoutAlgorithm() override = default; 32 33 std::optional<SizeF> MeasureContent( 34 const LayoutConstraintF& contentConstraint, LayoutWrapper* layoutWrapper) override; 35 36 void Measure(LayoutWrapper* layoutWrapper) override; 37 OnReset()38 void OnReset() override {} 39 GetHeight()40 float GetHeight() const 41 { 42 return height_; 43 } 44 GetWidth()45 float GetWidth() const 46 { 47 return width_; 48 } 49 50 void LayoutPolicyIsMatchParent(const LayoutConstraintF& contentConstraint, 51 std::optional<NG::LayoutPolicyProperty> layoutPolicy, float& frameWidth, float& frameHeight); 52 53 private: 54 void CalcHeightAndWidth( 55 const RefPtr<FrameNode>& host, float& height, float& width, float frameHeight, float frameWidth); 56 57 ACE_DISALLOW_COPY_AND_MOVE(SwitchLayoutAlgorithm); 58 float width_ = 0.0f; 59 float height_ = 0.0f; 60 }; 61 } // namespace OHOS::Ace::NG 62 63 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SWITCH_SWITCH_LAYOUT_ALGORITHM_H 64