1 /* 2 * Copyright (c) 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_MENU_MENU_PREVIEW_PATTERN_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_MENU_MENU_PREVIEW_PATTERN_H 18 19 #include "base/memory/ace_type.h" 20 #include "base/memory/referenced.h" 21 #include "base/utils/string_utils.h" 22 #include "base/utils/utils.h" 23 #include "core/components/common/properties/color.h" 24 #include "core/components_ng/pattern/linear_layout/linear_layout_pattern.h" 25 #include "core/components_ng/pattern/menu/preview/menu_preview_layout_algorithm.h" 26 #include "core/components_ng/pattern/pattern.h" 27 #include "core/components_v2/inspector/inspector_constants.h" 28 #include "core/pipeline_ng/ui_task_scheduler.h" 29 30 namespace OHOS::Ace::NG { 31 class MenuPreviewPattern : public LinearLayoutPattern { 32 DECLARE_ACE_TYPE(MenuPreviewPattern, Pattern); 33 34 public: MenuPreviewPattern()35 MenuPreviewPattern() : LinearLayoutPattern(true) {} 36 ~MenuPreviewPattern() override = default; 37 CreateLayoutAlgorithm()38 RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override 39 { 40 return MakeRefPtr<MenuPreviewLayoutAlgorithm>(); 41 } 42 SetFirstShow()43 void SetFirstShow() 44 { 45 isFirstShow_ = true; 46 } 47 SetHasPreviewTransitionEffect(bool hasPreviewTransitionEffect)48 void SetHasPreviewTransitionEffect(bool hasPreviewTransitionEffect) 49 { 50 hasPreviewTransitionEffect_ = hasPreviewTransitionEffect; 51 } 52 SetIsShowHoverImage(bool isShow)53 void SetIsShowHoverImage(bool isShow) 54 { 55 isShowHoverImage_ = isShow; 56 } 57 GetIsShowHoverImage()58 bool GetIsShowHoverImage() const 59 { 60 return isShowHoverImage_; 61 } 62 SetHoverImageAfterScaleWidth(float width)63 void SetHoverImageAfterScaleWidth(float width) 64 { 65 hoverImageAfterScaleWidth_ = width; 66 } 67 GetHoverImageAfterScaleWidth()68 float GetHoverImageAfterScaleWidth() const 69 { 70 return hoverImageAfterScaleWidth_; 71 } 72 SetHoverImageAfterScaleHeight(float height)73 void SetHoverImageAfterScaleHeight(float height) 74 { 75 hoverImageAfterScaleHeight_ = height; 76 } 77 GetHoverImageAfterScaleHeight()78 float GetHoverImageAfterScaleHeight() const 79 { 80 return hoverImageAfterScaleHeight_; 81 } 82 SetClipStartWidth(float width)83 void SetClipStartWidth(float width) 84 { 85 clipStartWidth_ = width; 86 } 87 GetClipStartWidth()88 float GetClipStartWidth() const 89 { 90 return clipStartWidth_; 91 } 92 SetClipStartHeight(float height)93 void SetClipStartHeight(float height) 94 { 95 clipStartHeight_ = height; 96 } 97 GetClipStartHeight()98 float GetClipStartHeight() const 99 { 100 return clipStartHeight_; 101 } 102 SetClipStartValue(float value)103 void SetClipStartValue(float value) 104 { 105 clipStartVal_ = value; 106 } 107 GetClipStartValue()108 float GetClipStartValue() const 109 { 110 return clipStartVal_; 111 } 112 SetClipEndValue(float value)113 void SetClipEndValue(float value) 114 { 115 clipEndVal_ = value; 116 } 117 GetClipEndValue()118 float GetClipEndValue() const 119 { 120 return clipEndVal_; 121 } 122 SetHoverImageAfterScaleOffset(const OffsetF & offset)123 void SetHoverImageAfterScaleOffset(const OffsetF& offset) 124 { 125 hoverImageAfterScaleOffset_ = offset; 126 } 127 GetHoverImageAfterScaleOffset()128 OffsetF GetHoverImageAfterScaleOffset() const 129 { 130 return hoverImageAfterScaleOffset_; 131 } 132 SetCustomPreviewWidth(float width)133 void SetCustomPreviewWidth(float width) 134 { 135 customPreviewWidth_ = width; 136 } 137 GetCustomPreviewWidth()138 float GetCustomPreviewWidth() const 139 { 140 return customPreviewWidth_; 141 } 142 SetCustomPreviewHeight(float height)143 void SetCustomPreviewHeight(float height) 144 { 145 customPreviewHeight_ = height; 146 } 147 GetCustomPreviewHeight()148 float GetCustomPreviewHeight() const 149 { 150 return customPreviewHeight_; 151 } 152 SetStackAfterScaleActualWidth(float width)153 void SetStackAfterScaleActualWidth(float width) 154 { 155 stackAfterScaleActualWidth_ = width; 156 } 157 GetStackAfterScaleActualWidth()158 float GetStackAfterScaleActualWidth() const 159 { 160 return stackAfterScaleActualWidth_; 161 } 162 SetStackAfterScaleActualHeight(float height)163 void SetStackAfterScaleActualHeight(float height) 164 { 165 stackAfterScaleActualHeight_ = height; 166 } 167 GetStackAfterScaleActualHeight()168 float GetStackAfterScaleActualHeight() const 169 { 170 return stackAfterScaleActualHeight_; 171 } 172 SetIsWidthDistLarger(bool widthDistLarger)173 void SetIsWidthDistLarger(bool widthDistLarger) 174 { 175 isWidthDistLarge_ = widthDistLarger; 176 } 177 GetIsWidthDistLarger()178 bool GetIsWidthDistLarger() const 179 { 180 return isWidthDistLarge_; 181 } 182 SetHoverImageScaleFrom(float scaleFrom)183 void SetHoverImageScaleFrom(float scaleFrom) 184 { 185 hoverImageScaleFrom_ = scaleFrom; 186 } 187 GetHoverImageScaleFrom()188 float GetHoverImageScaleFrom() const 189 { 190 return hoverImageScaleFrom_; 191 } 192 SetHoverImageScaleTo(float scaleTo)193 void SetHoverImageScaleTo(float scaleTo) 194 { 195 hoverImageScaleTo_ = scaleTo; 196 } 197 GetHoverImageScaleTo()198 float GetHoverImageScaleTo() const 199 { 200 return hoverImageScaleTo_; 201 } 202 SetCustomPreviewScaleTo(float scaleTo)203 void SetCustomPreviewScaleTo(float scaleTo) 204 { 205 customPreviewScaleTo_ = scaleTo; 206 } 207 GetCustomPreviewScaleTo()208 float GetCustomPreviewScaleTo() const 209 { 210 return customPreviewScaleTo_; 211 } 212 SetIsHoverImageScaleNearEqual(bool isEqual)213 void SetIsHoverImageScaleNearEqual(bool isEqual) 214 { 215 isHoverImageScaleNearEqual_ = isEqual; 216 } 217 IsHoverImageScaleNearEqual()218 bool IsHoverImageScaleNearEqual() const 219 { 220 return isHoverImageScaleNearEqual_; 221 } 222 SetIsHoverImageAnimationPlaying(bool isPlay)223 void SetIsHoverImageAnimationPlaying(bool isPlay) 224 { 225 isHoverImageAnimationPlaying_ = isPlay; 226 } 227 IsHoverImageAnimationPlaying()228 bool IsHoverImageAnimationPlaying() const 229 { 230 return isHoverImageAnimationPlaying_; 231 } 232 233 RefPtr<FrameNode> GetMenuWrapper() const; 234 SetIsHoverImageScalePlaying(bool isPlay)235 void SetIsHoverImageScalePlaying(bool isPlay) 236 { 237 isHoverImageScalePlaying_ = isPlay; 238 } 239 IsHoverImageScalePlaying()240 bool IsHoverImageScalePlaying() 241 { 242 return isHoverImageScalePlaying_; 243 } 244 245 private: 246 void OnModifyDone() override; 247 bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override; 248 void InitPanEvent(const RefPtr<GestureEventHub>& gestureHub); 249 void HandleDragEnd(float offsetX, float offsetY, float velocity); 250 bool isFirstShow_ = false; 251 bool hasPreviewTransitionEffect_ = false; 252 253 bool isShowHoverImage_ = false; 254 bool isHoverImageScaleNearEqual_ = false; 255 bool isHoverImageAnimationPlaying_ = false; 256 bool isWidthDistLarge_ = false; 257 bool isHoverImageScalePlaying_ = false; 258 OffsetF hoverImageAfterScaleOffset_; 259 float hoverImageAfterScaleWidth_ = 0.0f; 260 float hoverImageAfterScaleHeight_ = 0.0f; 261 float clipStartWidth_ = 0.0f; 262 float clipStartHeight_ = 0.0f; 263 float clipStartVal_ = 0.0f; 264 float clipEndVal_ = 0.0f; 265 float customPreviewWidth_ = 0.0f; 266 float customPreviewHeight_ = 0.0f; 267 float stackAfterScaleActualWidth_ = 0.0f; 268 float stackAfterScaleActualHeight_ = 0.0f; 269 float hoverImageScaleFrom_ = 1.0f; 270 float hoverImageScaleTo_ = 1.0f; 271 float customPreviewScaleTo_ = 1.0f; 272 ACE_DISALLOW_COPY_AND_MOVE(MenuPreviewPattern); 273 }; 274 } // namespace OHOS::Ace::NG 275 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_MENU_MENU_PREVIEW_PATTERN_H 276