1 /* 2 * Copyright (c) 2022-2023 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_NG_PATTERNS_SLIDER_SLIDER_MODEL_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SLIDER_SLIDER_MODEL_H 18 19 #include <functional> 20 #include <memory> 21 #include <mutex> 22 #include <optional> 23 24 #include "base/geometry/axis.h" 25 #include "base/memory/ace_type.h" 26 #include "base/utils/macros.h" 27 #include "core/components/common/properties/clip_path.h" 28 #include "core/components/common/properties/color.h" 29 #include "core/components_ng/property/gradient_property.h" 30 31 namespace OHOS::Ace { 32 class ACE_FORCE_EXPORT SliderModel { 33 public: 34 enum class SliderMode { 35 OUTSET, // block on track, track is thin 36 INSET, // block inside track, track is rough 37 NONE, // no block 38 CAPSULE, // capsule slider. 39 }; 40 41 enum class BlockStyleType { 42 DEFAULT, 43 IMAGE, 44 SHAPE, 45 }; 46 47 enum class SliderInteraction { 48 SLIDE_AND_CLICK, 49 SLIDE_ONLY, 50 SLIDE_AND_CLICK_UP, 51 }; 52 53 class SliderValidRange final : public AceType { 54 public: 55 SliderValidRange() = default; SliderValidRange(float from,float to)56 SliderValidRange(float from, float to) : fromValue(from), toValue(to) {} 57 ~SliderValidRange() = default; GetFromValue()58 float GetFromValue() const 59 { 60 return fromValue; 61 } GetToValue()62 float GetToValue() const 63 { 64 return toValue; 65 } HasValidValues()66 bool HasValidValues() const 67 { 68 return std::isfinite(fromValue) && std::isfinite(toValue); 69 } 70 71 private: 72 float fromValue = std::numeric_limits<float>::quiet_NaN(); 73 float toValue = std::numeric_limits<float>::quiet_NaN(); 74 }; 75 76 static SliderModel* GetInstance(); 77 virtual ~SliderModel() = default; 78 79 virtual void Create(float value, float step, float min, float max) = 0; 80 virtual void SetSliderMode(const SliderMode& value) = 0; 81 virtual void SetDirection(Axis value) = 0; 82 virtual void SetReverse(bool value) = 0; 83 virtual void SetBlockColor(const Color& value) = 0; 84 virtual void SetTrackBackgroundColor(const Color& value) = 0; 85 virtual void SetTrackBackgroundColor(const NG::Gradient& value, bool isResourceColor = false) = 0; 86 virtual void SetSelectColor(const Color& value) = 0; 87 virtual void SetMinLabel(float value) = 0; 88 virtual void SetMaxLabel(float value) = 0; SetMinResponsiveDistance(float value)89 virtual void SetMinResponsiveDistance(float value) {}; 90 virtual void SetShowSteps(bool value) = 0; 91 virtual void SetShowTips(bool value, const std::optional<std::string>& content) = 0; 92 virtual void SetThickness(const Dimension& value) = 0; 93 virtual void SetBlockBorderColor(const Color& value) = 0; 94 virtual void SetBlockBorderWidth(const Dimension& value) = 0; 95 virtual void SetStepColor(const Color& value) = 0; 96 virtual void SetTrackBorderRadius(const Dimension& value) = 0; 97 virtual void SetSelectedBorderRadius(const Dimension& value) = 0; 98 virtual void SetBlockSize(const Dimension& width, const Dimension& height) = 0; 99 virtual void SetBlockType(BlockStyleType value) = 0; 100 virtual void SetBlockImage( 101 const std::string& value, const std::string& bundleName, const std::string& moduleName) = 0; 102 virtual void SetBlockShape(const RefPtr<BasicShape>& value) = 0; 103 virtual void SetStepSize(const Dimension& value) = 0; SetSliderInteractionMode(SliderInteraction mode)104 virtual void SetSliderInteractionMode(SliderInteraction mode) {}; 105 virtual void SetOnChange(std::function<void(float, int32_t)>&& eventOnChange) = 0; 106 virtual void SetOnChangeEvent(std::function<void(float)>&& onChangeEvent) = 0; SetValidSlideRange(float fromValue,float toValue)107 virtual void SetValidSlideRange(float fromValue, float toValue) {}; 108 109 virtual void ResetBlockBorderColor() = 0; 110 virtual void ResetBlockBorderWidth() = 0; 111 virtual void ResetStepColor() = 0; 112 virtual void ResetTrackBorderRadius() = 0; 113 virtual void ResetSelectedBorderRadius() = 0; 114 virtual void ResetBlockSize() = 0; 115 virtual void ResetBlockType() = 0; 116 virtual void ResetBlockImage() = 0; 117 virtual void ResetBlockShape() = 0; 118 virtual void ResetStepSize() = 0; 119 virtual void ResetSliderInteractionMode() = 0; 120 virtual void ResetMinResponsiveDistance() = 0; 121 virtual void ResetValidSlideRange() = 0; 122 123 private: 124 static std::unique_ptr<SliderModel> instance_; 125 static std::mutex mutex_; 126 }; 127 128 } // namespace OHOS::Ace 129 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SLIDER_SLIDER_MODEL_H 130