1 /*
2  * Copyright (c) 2021-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_BASE_MEASURABLE_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_MEASURABLE_H
18 
19 #include "base/memory/ace_type.h"
20 #include "frameworks/base/geometry/animatable_dimension.h"
21 
22 namespace OHOS::Ace {
23 
24 class Measurable : public virtual AceType {
25     DECLARE_ACE_TYPE(Measurable, AceType);
26 
27 public:
GetWidth()28     virtual const AnimatableDimension& GetWidth() const
29     {
30         return width_;
31     }
32 
33     virtual void SetWidth(const Dimension& dimension, const AnimationOption& option = AnimationOption())
34     {
35         width_ = AnimatableDimension(dimension, option);
36     }
37 
38     virtual void SetWidth(const CalcDimension& dimension, const AnimationOption& option = AnimationOption())
39     {
40         width_ = AnimatableDimension(dimension, option);
41     }
42 
43     virtual void SetWidth(double width, DimensionUnit unit = DimensionUnit::PX)
44     {
45         width_ = AnimatableDimension(width, unit);
46     }
47 
48     virtual void SetWidth(std::string width, DimensionUnit unit = DimensionUnit::CALC)
49     {
50         width_ = AnimatableDimension(width, unit);
51     }
52 
SetWidth(const AnimatableDimension & dimension)53     virtual void SetWidth(const AnimatableDimension& dimension)
54     {
55         width_ = dimension;
56     }
57 
GetHeight()58     virtual const AnimatableDimension& GetHeight() const
59     {
60         return height_;
61     }
62 
63     virtual void SetHeight(const Dimension& dimension, const AnimationOption& option = AnimationOption())
64     {
65         height_ = AnimatableDimension(dimension, option);
66     }
67 
68     virtual void SetHeight(const CalcDimension& dimension, const AnimationOption& option = AnimationOption())
69     {
70         height_ = AnimatableDimension(dimension, option);
71     }
72 
73     virtual void SetHeight(double height, DimensionUnit unit = DimensionUnit::PX)
74     {
75         height_ = AnimatableDimension(height, unit);
76     }
77 
78     virtual void SetHeight(std::string height, DimensionUnit unit = DimensionUnit::CALC)
79     {
80         height_ = AnimatableDimension(height, unit);
81     }
82 
SetHeight(const AnimatableDimension & dimension)83     virtual void SetHeight(const AnimatableDimension& dimension)
84     {
85         height_ = dimension;
86     }
87 
88 protected:
89     AnimatableDimension width_ {-1.0, DimensionUnit::PX};
90     AnimatableDimension height_ {-1.0, DimensionUnit::PX};
91 };
92 
93 }  // namespace OHOS::Ace
94 
95 #endif  // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BASE_MEASURABLE_H