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_SLIDER_RENDER_BLOCK_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SLIDER_RENDER_BLOCK_H
18 
19 #include "core/components/slider/block_component.h"
20 #include "core/pipeline/base/render_node.h"
21 
22 namespace OHOS::Ace {
23 
24 class RenderBlock : public RenderNode {
25     DECLARE_ACE_TYPE(RenderBlock, RenderNode);
26 
27 public:
28     static RefPtr<RenderNode> Create();
29 
30     void Update(const RefPtr<Component>& component) override;
31 
32     void PerformLayout() override;
33 
GetBlockColor()34     const Color& GetBlockColor() const
35     {
36         return blockColor_;
37     }
38 
GetHoverColor()39     const Color& GetHoverColor() const
40     {
41         return hoverColor_;
42     }
43 
SetHoverColor(const Color & hoverColor)44     void SetHoverColor(const Color& hoverColor)
45     {
46         hoverColor_ = hoverColor;
47     }
48 
49     Size Measure();
50 
SetFocus(bool focus)51     void SetFocus(bool focus)
52     {
53         isFocus_ = focus;
54     }
55 
GetFocus()56     bool GetFocus() const
57     {
58         return isFocus_;
59     }
60 
SetRadiusScale(double radiusScale)61     void SetRadiusScale(double radiusScale)
62     {
63         if (radiusScale >= 1.0) {
64             radiusScale_ = radiusScale;
65         }
66     }
67 
GetBlockSize()68     const Dimension& GetBlockSize() const
69     {
70         return blockSize_;
71     }
72 
GetHotRegionWidth()73     const Dimension& GetHotRegionWidth() const
74     {
75         return hotRegionWidth_;
76     }
77 
GetHotRegionHeight()78     const Dimension& GetHotRegionHeight() const
79     {
80         return hotRegionHeight_;
81     }
82 
SetHover(bool isHover)83     void SetHover(bool isHover)
84     {
85         isHover_ = isHover;
86     }
87 
SetPress(bool isPress)88     void SetPress(bool isPress)
89     {
90         isPress_ = isPress;
91     }
92 
GetMode()93     SliderMode GetMode() const
94     {
95         return mode_;
96     }
97 
SetMode(SliderMode mode)98     void SetMode(SliderMode mode)
99     {
100         mode_ = mode;
101     }
102 
103 protected:
104     bool isFocus_ = false;
105     bool isHover_ = false;
106     bool isPress_ = false;
107     double radiusScale_ = 1.0;
108     Dimension blockSize_;
109     Dimension hotRegionWidth_;
110     Dimension hotRegionHeight_;
111 
112 private:
113     Color blockColor_;
114     Color hoverColor_;
115     SliderMode mode_ = SliderMode::OUTSET;
116 };
117 
118 } // namespace OHOS::Ace
119 
120 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SLIDER_RENDER_BLOCK_H
121