• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_SLIDER_COMPONENT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SLIDER_SLIDER_COMPONENT_H
18 
19 #include <string>
20 
21 #include "core/components/box/box_component.h"
22 #include "core/components/common/properties/color.h"
23 #include "core/components/common/properties/progress_data.h"
24 #include "core/components/common/rotation/rotation_controller.h"
25 #include "core/components/slider/block_component.h"
26 #include "core/components/slider/slider_theme.h"
27 #include "core/components/track/track_component.h"
28 #include "core/pipeline/base/component_group.h"
29 #include "core/pipeline/base/element.h"
30 #include "core/pipeline/base/render_component.h"
31 #include "core/components_v2/common/common_def.h"
32 
33 namespace OHOS::Ace {
34 
35 constexpr double HALF = 0.5;
36 
37 // The slider component manages the step, value, min, max, selectColor and padding.
38 class ACE_EXPORT SliderComponent : public RenderComponent {
39     DECLARE_ACE_TYPE(SliderComponent, RenderComponent);
40 
41 public:
42     SliderComponent(double value, double step, double min, double max);
43     ~SliderComponent() override = default;
44 
45     RefPtr<Element> CreateElement() override;
46     RefPtr<RenderNode> CreateRenderNode() override;
47 
48     void SetThemeStyle(const RefPtr<SliderTheme>& theme);
49     void InitStyle(const RefPtr<SliderTheme>& theme);
50 
GetMinValue()51     double GetMinValue() const
52     {
53         return data_.GetMinValue();
54     }
55 
GetMaxValue()56     double GetMaxValue() const
57     {
58         return data_.GetMaxValue();
59     }
60 
GetStep()61     double GetStep() const
62     {
63         return data_.GetStepValue();
64     }
65 
GetValue()66     double GetValue() const
67     {
68         return data_.GetValue();
69     }
70 
GetTrack()71     RefPtr<TrackComponent> GetTrack() const
72     {
73         return track_;
74     }
75 
GetBlock()76     RefPtr<BlockComponent> GetBlock() const
77     {
78         return block_;
79     }
80 
GetOnMoveEndEventId()81     const EventMarker& GetOnMoveEndEventId() const
82     {
83         return onMoveEndEventId_;
84     }
85 
SetOnMoveEndEventId(const EventMarker & methodId)86     void SetOnMoveEndEventId(const EventMarker& methodId)
87     {
88         onMoveEndEventId_ = methodId;
89     }
90 
GetOnMovingEventId()91     const EventMarker& GetOnMovingEventId() const
92     {
93         return onMovingEventId_;
94     }
95 
SetOnMovingEventId(const EventMarker & methodId)96     void SetOnMovingEventId(const EventMarker& methodId)
97     {
98         onMovingEventId_ = methodId;
99     }
100 
SetBlock(const RefPtr<BlockComponent> & block)101     void SetBlock(const RefPtr<BlockComponent>& block)
102     {
103         block_ = block;
104     }
105 
SetTrack(const RefPtr<TrackComponent> & track)106     void SetTrack(const RefPtr<TrackComponent>& track)
107     {
108         track_ = track;
109     }
110 
SetCurrentValue(const double newValue)111     void SetCurrentValue(const double newValue)
112     {
113         data_.SetValue(newValue);
114     }
115 
SetMinValue(const double minValue)116     void SetMinValue(const double minValue)
117     {
118         data_.SetMinValue(minValue);
119     }
120 
SetMaxValue(const double minValue)121     void SetMaxValue(const double minValue)
122     {
123         data_.SetMaxValue(minValue);
124     }
125 
SetStepValue(const double minValue)126     void SetStepValue(const double minValue)
127     {
128         data_.SetStepValue(minValue);
129     }
130 
MoveSteps(const int32_t num)131     double MoveSteps(const int32_t num)
132     {
133         return data_.MoveSteps(num);
134     }
135 
SetTextDirection(TextDirection direction)136     void SetTextDirection(TextDirection direction) override
137     {
138         RenderComponent::SetTextDirection(direction);
139         track_->SetTextDirection(direction);
140     }
141 
GetRotationController()142     const RefPtr<RotationController>& GetRotationController() const
143     {
144         return rotationController_;
145     }
146 
SetDisable(bool disable)147     void SetDisable(bool disable)
148     {
149         isDisable_ = disable;
150     }
151 
GetDisable()152     bool GetDisable() const
153     {
154         return isDisable_;
155     }
156 
GetSliderMode()157     SliderMode GetSliderMode() const
158     {
159         return mode_;
160     }
161 
SetSliderMode(SliderMode mode)162     void SetSliderMode(SliderMode mode)
163     {
164         mode_ = mode;
165     }
166 
SetShowTips(bool showTips)167     void SetShowTips(bool showTips)
168     {
169         showTips_ = showTips;
170     }
171 
NeedShowTips()172     bool NeedShowTips() const
173     {
174         return showTips_;
175     }
176 
SetShowSteps(bool showSteps)177     void SetShowSteps(bool showSteps)
178     {
179         showSteps_ = showSteps;
180     }
181 
NeedShowSteps()182     bool NeedShowSteps() const
183     {
184         return showSteps_;
185     }
186 
SetDirection(Axis axis)187     void SetDirection(Axis axis)
188     {
189         axis_ = axis;
190         track_->SetDirection(axis_);
191     }
192 
GetDirection()193     Axis GetDirection() const
194     {
195         return axis_;
196     }
197 
IsReverse()198     bool IsReverse() const
199     {
200         return isReverse_;
201     }
202 
SetReverse(bool isReverse)203     void SetReverse(bool isReverse)
204     {
205         isReverse_ = isReverse;
206         track_->SetReverse(isReverse_);
207     }
208 
GetThickness()209     const Dimension& GetThickness() const
210     {
211         return thickness_;
212     }
213 
SetThickness(const Dimension & thickness)214     void SetThickness(const Dimension& thickness)
215     {
216         thickness_ = thickness;
217     }
218 
219     ACE_DEFINE_COMPONENT_EVENT(OnChange, void(double,int));
220 
221 private:
222     ProgressData data_;
223     RefPtr<BlockComponent> block_;
224     RefPtr<TrackComponent> track_;
225     EventMarker onMoveEndEventId_;
226     EventMarker onMovingEventId_;
227     bool isDisable_ = false;
228     bool showTips_ = false;
229     bool showSteps_ = false;
230     bool isReverse_ = false;
231     SliderMode mode_ = SliderMode::OUTSET;
232     RefPtr<RotationController> rotationController_;
233     Axis axis_ = Axis::HORIZONTAL;
234     Dimension thickness_;
235 };
236 
237 } // namespace OHOS::Ace
238 
239 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SLIDER_SLIDER_COMPONENT_H
240