• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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_INTERFACES_INNER_API_ACE_KIT_INCLUDE_VIEW_LAYOUT_LAYOUT_ALGORITHM_H
17 #define FOUNDATION_ACE_INTERFACES_INNER_API_ACE_KIT_INCLUDE_VIEW_LAYOUT_LAYOUT_ALGORITHM_H
18 
19 #include <functional>
20 #include <optional>
21 
22 #include "ui/base/ace_type.h"
23 #include "ui/base/geometry/ng/size_t.h"
24 #include "ui/view/frame_node.h"
25 #include "ui/view/layout/layout_info.h"
26 
27 namespace OHOS::Ace::NG {
28 template<class T>
29 struct LayoutConstraintT;
30 }
31 
32 namespace OHOS::Ace::Kit {
33 
34 class LayoutAlgorithm : public AceType {
35     DECLARE_ACE_TYPE(LayoutAlgorithm, AceType);
36 
37 public:
LayoutAlgorithm(const WeakPtr<FrameNode> & host)38     explicit LayoutAlgorithm(const WeakPtr<FrameNode>& host) : host_(host) {}
39     virtual ~LayoutAlgorithm() = default;
40 
Measure(const Kit::LayoutConstraintInfo & contentConstraint)41     virtual void Measure(const Kit::LayoutConstraintInfo& contentConstraint) {}
42 
Layout()43     virtual void Layout() {}
44 
MeasureContent(const NG::LayoutConstraintT<float> & contentConstraint)45     virtual std::optional<NG::SizeF> MeasureContent(const NG::LayoutConstraintT<float>& contentConstraint)
46     {
47         return std::nullopt;
48     }
49 
SetLayoutConstraint(const Kit::LayoutConstraintInfo & contentConstraint)50     virtual void SetLayoutConstraint(const Kit::LayoutConstraintInfo& contentConstraint)
51     {
52         layoutConstraintInfo_ = contentConstraint;
53     }
54 
GetLayoutConstraint()55     virtual const LayoutConstraintInfo& GetLayoutConstraint() const
56     {
57         return layoutConstraintInfo_;
58     }
59 
60 protected:
61     WeakPtr<FrameNode> host_;
62     LayoutConstraintInfo layoutConstraintInfo_;
63 };
64 
65 } // namespace OHOS::Ace::Kit
66 
67 #endif
68