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_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 if (theme_) { 166 InitStyle(theme_); 167 } 168 } 169 SetShowTips(bool showTips)170 void SetShowTips(bool showTips) 171 { 172 showTips_ = showTips; 173 } 174 NeedShowTips()175 bool NeedShowTips() const 176 { 177 return showTips_; 178 } 179 SetShowSteps(bool showSteps)180 void SetShowSteps(bool showSteps) 181 { 182 showSteps_ = showSteps; 183 } 184 NeedShowSteps()185 bool NeedShowSteps() const 186 { 187 return showSteps_; 188 } 189 SetDirection(Axis axis)190 void SetDirection(Axis axis) 191 { 192 axis_ = axis; 193 track_->SetDirection(axis_); 194 } 195 GetDirection()196 Axis GetDirection() const 197 { 198 return axis_; 199 } 200 IsReverse()201 bool IsReverse() const 202 { 203 return isReverse_; 204 } 205 SetReverse(bool isReverse)206 void SetReverse(bool isReverse) 207 { 208 isReverse_ = isReverse; 209 track_->SetReverse(isReverse_); 210 } 211 GetThickness()212 const Dimension& GetThickness() const 213 { 214 return thickness_; 215 } 216 SetThickness(const Dimension & thickness)217 void SetThickness(const Dimension& thickness) 218 { 219 thickness_ = thickness; 220 } 221 GetMouseAnimationType()222 HoverAnimationType GetMouseAnimationType() const 223 { 224 return animationType_; 225 } SetMouseAnimationType(HoverAnimationType animationType)226 void SetMouseAnimationType(HoverAnimationType animationType) 227 { 228 animationType_ = animationType; 229 } 230 231 ACE_DEFINE_COMPONENT_EVENT(OnChange, void(double, int)); 232 233 private: 234 ProgressData data_; 235 RefPtr<BlockComponent> block_; 236 RefPtr<TrackComponent> track_; 237 EventMarker onMoveEndEventId_; 238 EventMarker onMovingEventId_; 239 bool isDisable_ = false; 240 bool showTips_ = false; 241 bool showSteps_ = false; 242 bool isReverse_ = false; 243 SliderMode mode_ = SliderMode::OUTSET; 244 RefPtr<RotationController> rotationController_; 245 Axis axis_ = Axis::HORIZONTAL; 246 Dimension thickness_; 247 RefPtr<SliderTheme> theme_; 248 HoverAnimationType animationType_ = HoverAnimationType::NONE; 249 }; 250 251 } // namespace OHOS::Ace 252 253 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SLIDER_SLIDER_COMPONENT_H 254