1a3e0fd82Sopenharmony_ci/* 2a3e0fd82Sopenharmony_ci * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 3a3e0fd82Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4a3e0fd82Sopenharmony_ci * you may not use this file except in compliance with the License. 5a3e0fd82Sopenharmony_ci * You may obtain a copy of the License at 6a3e0fd82Sopenharmony_ci * 7a3e0fd82Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8a3e0fd82Sopenharmony_ci * 9a3e0fd82Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10a3e0fd82Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11a3e0fd82Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12a3e0fd82Sopenharmony_ci * See the License for the specific language governing permissions and 13a3e0fd82Sopenharmony_ci * limitations under the License. 14a3e0fd82Sopenharmony_ci */ 15a3e0fd82Sopenharmony_ci 16a3e0fd82Sopenharmony_ci/** 17a3e0fd82Sopenharmony_ci * @addtogroup UI_Components 18a3e0fd82Sopenharmony_ci * @{ 19a3e0fd82Sopenharmony_ci * 20a3e0fd82Sopenharmony_ci * @brief Defines UI components such as buttons, texts, images, lists, and progress bars. 21a3e0fd82Sopenharmony_ci * 22a3e0fd82Sopenharmony_ci * @since 1.0 23a3e0fd82Sopenharmony_ci * @version 1.0 24a3e0fd82Sopenharmony_ci */ 25a3e0fd82Sopenharmony_ci 26a3e0fd82Sopenharmony_ci/** 27a3e0fd82Sopenharmony_ci * @file ui_abstract_scroll.h 28a3e0fd82Sopenharmony_ci * 29a3e0fd82Sopenharmony_ci * @brief Declares the base class used to define the attributes of a scroll. The <b>UIList</b>, <b>UIScrollView</b>, and 30a3e0fd82Sopenharmony_ci * <b>UISwipeView</b> inherit from this class. 31a3e0fd82Sopenharmony_ci * 32a3e0fd82Sopenharmony_ci * @since 1.0 33a3e0fd82Sopenharmony_ci * @version 1.0 34a3e0fd82Sopenharmony_ci */ 35a3e0fd82Sopenharmony_ci 36a3e0fd82Sopenharmony_ci#ifndef GRAPHIC_LITE_UI_ABSTRACT_SCROLL_H 37a3e0fd82Sopenharmony_ci#define GRAPHIC_LITE_UI_ABSTRACT_SCROLL_H 38a3e0fd82Sopenharmony_ci 39a3e0fd82Sopenharmony_ci#include "animator/animator.h" 40a3e0fd82Sopenharmony_ci#include "animator/easing_equation.h" 41a3e0fd82Sopenharmony_ci#include "components/ui_view_group.h" 42a3e0fd82Sopenharmony_ci 43a3e0fd82Sopenharmony_cinamespace OHOS { 44a3e0fd82Sopenharmony_ciclass BarEaseInOutAnimator; 45a3e0fd82Sopenharmony_ciclass UIAbstractScrollBar; 46a3e0fd82Sopenharmony_ci/** 47a3e0fd82Sopenharmony_ci * @brief Defines the attributes of a scroll, including the scroll direction, blank size of a scroll view, velocity and 48a3e0fd82Sopenharmony_ci * effects of a scroll animation. 49a3e0fd82Sopenharmony_ci * 50a3e0fd82Sopenharmony_ci * @since 1.0 51a3e0fd82Sopenharmony_ci * @version 1.0 52a3e0fd82Sopenharmony_ci */ 53a3e0fd82Sopenharmony_ciclass UIAbstractScroll : public UIViewGroup { 54a3e0fd82Sopenharmony_cipublic: 55a3e0fd82Sopenharmony_ci /** 56a3e0fd82Sopenharmony_ci * @brief A constructor used to create a <b>UIAbstractScroll</b> instance. 57a3e0fd82Sopenharmony_ci * 58a3e0fd82Sopenharmony_ci * @since 1.0 59a3e0fd82Sopenharmony_ci * @version 1.0 60a3e0fd82Sopenharmony_ci */ 61a3e0fd82Sopenharmony_ci UIAbstractScroll(); 62a3e0fd82Sopenharmony_ci 63a3e0fd82Sopenharmony_ci /** 64a3e0fd82Sopenharmony_ci * @brief A destructor used to delete the <b>UIAbstractScroll</b> instance. 65a3e0fd82Sopenharmony_ci * 66a3e0fd82Sopenharmony_ci * @since 1.0 67a3e0fd82Sopenharmony_ci * @version 1.0 68a3e0fd82Sopenharmony_ci */ 69a3e0fd82Sopenharmony_ci virtual ~UIAbstractScroll(); 70a3e0fd82Sopenharmony_ci 71a3e0fd82Sopenharmony_ci /** 72a3e0fd82Sopenharmony_ci * @brief Obtains the view type. 73a3e0fd82Sopenharmony_ci * @return Returns the view type, as defined in {@link UIViewType}. 74a3e0fd82Sopenharmony_ci * @since 1.0 75a3e0fd82Sopenharmony_ci * @version 1.0 76a3e0fd82Sopenharmony_ci */ 77a3e0fd82Sopenharmony_ci UIViewType GetViewType() const override 78a3e0fd82Sopenharmony_ci { 79a3e0fd82Sopenharmony_ci return UI_ABSTRACT_SCROLL; 80a3e0fd82Sopenharmony_ci } 81a3e0fd82Sopenharmony_ci 82a3e0fd82Sopenharmony_ci /** 83a3e0fd82Sopenharmony_ci * @brief Sets the blank size for this scroll view. 84a3e0fd82Sopenharmony_ci * 85a3e0fd82Sopenharmony_ci * 86a3e0fd82Sopenharmony_ci * @param value Indicates the blank size to set. The default value is <b>0</b>. Taking a vertical scroll as an 87a3e0fd82Sopenharmony_ci * example, the value <b>0</b> indicates that the head node can only scroll downwards the top of the 88a3e0fd82Sopenharmony_ci * view and the tail node scroll upwards the bottom; the value <b>10</b> indicates that the head node 89a3e0fd82Sopenharmony_ci * can continue scrolling down by 10 pixels after it reaches the top of the view. 90a3e0fd82Sopenharmony_ci * @since 1.0 91a3e0fd82Sopenharmony_ci * @version 1.0 92a3e0fd82Sopenharmony_ci */ 93a3e0fd82Sopenharmony_ci void SetScrollBlankSize(uint16_t size) 94a3e0fd82Sopenharmony_ci { 95a3e0fd82Sopenharmony_ci scrollBlankSize_ = size; 96a3e0fd82Sopenharmony_ci } 97a3e0fd82Sopenharmony_ci 98a3e0fd82Sopenharmony_ci /** 99a3e0fd82Sopenharmony_ci * @brief Get the blank size for this scroll view. 100a3e0fd82Sopenharmony_ci * 101a3e0fd82Sopenharmony_ci * @return Returns the blank size for this scroll view 102a3e0fd82Sopenharmony_ci */ 103a3e0fd82Sopenharmony_ci uint16_t GetScrollBlankSize() const 104a3e0fd82Sopenharmony_ci { 105a3e0fd82Sopenharmony_ci return scrollBlankSize_; 106a3e0fd82Sopenharmony_ci } 107a3e0fd82Sopenharmony_ci 108a3e0fd82Sopenharmony_ci /** 109a3e0fd82Sopenharmony_ci * @brief Sets the maximum scroll distance after a finger lifts the screen. 110a3e0fd82Sopenharmony_ci * 111a3e0fd82Sopenharmony_ci * @param distance Indicates the maximum scroll distance to set. The default value is <b>0</b>, indicating that the 112a3e0fd82Sopenharmony_ci * scroll distance is not limited. 113a3e0fd82Sopenharmony_ci * @since 1.0 114a3e0fd82Sopenharmony_ci * @version 1.0 115a3e0fd82Sopenharmony_ci */ 116a3e0fd82Sopenharmony_ci void SetMaxScrollDistance(uint16_t distance) 117a3e0fd82Sopenharmony_ci { 118a3e0fd82Sopenharmony_ci maxScrollDistance_ = distance; 119a3e0fd82Sopenharmony_ci } 120a3e0fd82Sopenharmony_ci 121a3e0fd82Sopenharmony_ci /** 122a3e0fd82Sopenharmony_ci * @brief Sets the rebound size, which is the distance a knob moves after being released when it reaches the end of 123a3e0fd82Sopenharmony_ci * a scrollbar. 124a3e0fd82Sopenharmony_ci * 125a3e0fd82Sopenharmony_ci * @param size Indicates the rebound size to set. 126a3e0fd82Sopenharmony_ci * @since 1.0 127a3e0fd82Sopenharmony_ci * @version 1.0 128a3e0fd82Sopenharmony_ci */ 129a3e0fd82Sopenharmony_ci void SetReboundSize(uint16_t size) 130a3e0fd82Sopenharmony_ci { 131a3e0fd82Sopenharmony_ci reboundSize_ = size; 132a3e0fd82Sopenharmony_ci } 133a3e0fd82Sopenharmony_ci 134a3e0fd82Sopenharmony_ci /** 135a3e0fd82Sopenharmony_ci * @brief Get the rebound size, which is the distance a knob moves after being released when it reaches the end of 136a3e0fd82Sopenharmony_ci * a scrollbar. 137a3e0fd82Sopenharmony_ci * 138a3e0fd82Sopenharmony_ci * @return Returns the rebound size. 139a3e0fd82Sopenharmony_ci */ 140a3e0fd82Sopenharmony_ci uint16_t GetReboundSize() const 141a3e0fd82Sopenharmony_ci { 142a3e0fd82Sopenharmony_ci return reboundSize_; 143a3e0fd82Sopenharmony_ci } 144a3e0fd82Sopenharmony_ci 145a3e0fd82Sopenharmony_ci /** 146a3e0fd82Sopenharmony_ci * @brief Obtains the maximum scroll distance after a finger lifts the screen. 147a3e0fd82Sopenharmony_ci * 148a3e0fd82Sopenharmony_ci * @return Returns the maximum scroll distance. The default value is <b>0</b>, indicating that the scroll distance 149a3e0fd82Sopenharmony_ci * is not limited. 150a3e0fd82Sopenharmony_ci * @since 1.0 151a3e0fd82Sopenharmony_ci * @version 1.0 152a3e0fd82Sopenharmony_ci */ 153a3e0fd82Sopenharmony_ci uint16_t GetMaxScrollDistance() const 154a3e0fd82Sopenharmony_ci { 155a3e0fd82Sopenharmony_ci return maxScrollDistance_; 156a3e0fd82Sopenharmony_ci } 157a3e0fd82Sopenharmony_ci 158a3e0fd82Sopenharmony_ci /** 159a3e0fd82Sopenharmony_ci * @brief Sets the easing function that specifies a scroll animation after a finger lifts the screen. 160a3e0fd82Sopenharmony_ci * 161a3e0fd82Sopenharmony_ci * @param func Indicates the easing function to set. The default function is {@link EasingEquation::CubicEaseOut}. 162a3e0fd82Sopenharmony_ci * For details, see {@link EasingEquation}. 163a3e0fd82Sopenharmony_ci * @since 1.0 164a3e0fd82Sopenharmony_ci * @version 1.0 165a3e0fd82Sopenharmony_ci */ 166a3e0fd82Sopenharmony_ci void SetDragFunc(EasingFunc func) 167a3e0fd82Sopenharmony_ci { 168a3e0fd82Sopenharmony_ci easingFunc_ = func; 169a3e0fd82Sopenharmony_ci } 170a3e0fd82Sopenharmony_ci 171a3e0fd82Sopenharmony_ci /** 172a3e0fd82Sopenharmony_ci * @brief Get the easing function that specifies a scroll animation after a finger lifts the screen. 173a3e0fd82Sopenharmony_ci * 174a3e0fd82Sopenharmony_ci * @param func Returns the easing function to set. The default function is {@link EasingEquation::CubicEaseOut}. 175a3e0fd82Sopenharmony_ci * For details, see {@link EasingEquation}. 176a3e0fd82Sopenharmony_ci */ 177a3e0fd82Sopenharmony_ci EasingFunc GetDragFunc() const 178a3e0fd82Sopenharmony_ci { 179a3e0fd82Sopenharmony_ci return easingFunc_; 180a3e0fd82Sopenharmony_ci } 181a3e0fd82Sopenharmony_ci 182a3e0fd82Sopenharmony_ci /** 183a3e0fd82Sopenharmony_ci * @brief Sets whether to continue scrolling after a finger lifts the screen. 184a3e0fd82Sopenharmony_ci * 185a3e0fd82Sopenharmony_ci * @param throwDrag Specifies whether to continue scrolling after a finger lifts the screen. <b>true</b> indicates 186a3e0fd82Sopenharmony_ci * the scroll continues, and <b>false</b> indicates the scroll stops immediately after a finger 187a3e0fd82Sopenharmony_ci * lifts. 188a3e0fd82Sopenharmony_ci * @since 1.0 189a3e0fd82Sopenharmony_ci * @version 1.0 190a3e0fd82Sopenharmony_ci */ 191a3e0fd82Sopenharmony_ci void SetThrowDrag(bool throwDrag) 192a3e0fd82Sopenharmony_ci { 193a3e0fd82Sopenharmony_ci throwDrag_ = throwDrag; 194a3e0fd82Sopenharmony_ci } 195a3e0fd82Sopenharmony_ci 196a3e0fd82Sopenharmony_ci /** 197a3e0fd82Sopenharmony_ci * @brief Moves the position of all child views. 198a3e0fd82Sopenharmony_ci * 199a3e0fd82Sopenharmony_ci * @param offsetX Indicates the offset distance by which a child view is moved on the x-axis. 200a3e0fd82Sopenharmony_ci * @param offsetY Indicates the offset distance by which a child view is moved on the y-axis. 201a3e0fd82Sopenharmony_ci * @since 1.0 202a3e0fd82Sopenharmony_ci * @version 1.0 203a3e0fd82Sopenharmony_ci */ 204a3e0fd82Sopenharmony_ci void MoveChildByOffset(int16_t offsetX, int16_t offsetY) override; 205a3e0fd82Sopenharmony_ci 206a3e0fd82Sopenharmony_ci /** 207a3e0fd82Sopenharmony_ci * @brief Sets the drag acceleration. 208a3e0fd82Sopenharmony_ci * 209a3e0fd82Sopenharmony_ci * @param value Indicates the drag acceleration to set. The default value is <b>10</b>. A larger drag acceleration 210a3e0fd82Sopenharmony_ci * indicates a higher inertial scroll velocity. 211a3e0fd82Sopenharmony_ci * @since 1.0 212a3e0fd82Sopenharmony_ci * @version 1.0 213a3e0fd82Sopenharmony_ci */ 214a3e0fd82Sopenharmony_ci void SetDragACCLevel(uint16_t value) 215a3e0fd82Sopenharmony_ci { 216a3e0fd82Sopenharmony_ci if (value != 0) { 217a3e0fd82Sopenharmony_ci dragAccCoefficient_ = value; 218a3e0fd82Sopenharmony_ci } 219a3e0fd82Sopenharmony_ci } 220a3e0fd82Sopenharmony_ci 221a3e0fd82Sopenharmony_ci /** 222a3e0fd82Sopenharmony_ci * @brief Obtains the drag acceleration. 223a3e0fd82Sopenharmony_ci * 224a3e0fd82Sopenharmony_ci * @return Returns the drag acceleration. 225a3e0fd82Sopenharmony_ci * @since 1.0 226a3e0fd82Sopenharmony_ci * @version 1.0 227a3e0fd82Sopenharmony_ci */ 228a3e0fd82Sopenharmony_ci uint8_t GetDragACCLevel() const 229a3e0fd82Sopenharmony_ci { 230a3e0fd82Sopenharmony_ci return dragAccCoefficient_; 231a3e0fd82Sopenharmony_ci } 232a3e0fd82Sopenharmony_ci 233a3e0fd82Sopenharmony_ci /** 234a3e0fd82Sopenharmony_ci * @brief Sets the compensation distance after a finger lifts the screen. 235a3e0fd82Sopenharmony_ci * 236a3e0fd82Sopenharmony_ci * @param value Indicates the compensation distance to set. The default value is <b>0</b>. 237a3e0fd82Sopenharmony_ci * @since 1.0 238a3e0fd82Sopenharmony_ci * @version 1.0 239a3e0fd82Sopenharmony_ci */ 240a3e0fd82Sopenharmony_ci void SetSwipeACCLevel(uint16_t value) 241a3e0fd82Sopenharmony_ci { 242a3e0fd82Sopenharmony_ci swipeAccCoefficient_ = value; 243a3e0fd82Sopenharmony_ci } 244a3e0fd82Sopenharmony_ci 245a3e0fd82Sopenharmony_ci /** 246a3e0fd82Sopenharmony_ci * @brief Obtains the compensation distance after a finger lifts the screen. 247a3e0fd82Sopenharmony_ci * 248a3e0fd82Sopenharmony_ci * @return Returns the compensation distance. 249a3e0fd82Sopenharmony_ci * @since 1.0 250a3e0fd82Sopenharmony_ci * @version 1.0 251a3e0fd82Sopenharmony_ci */ 252a3e0fd82Sopenharmony_ci uint8_t GetSwipeACCLevel() const 253a3e0fd82Sopenharmony_ci { 254a3e0fd82Sopenharmony_ci return swipeAccCoefficient_; 255a3e0fd82Sopenharmony_ci } 256a3e0fd82Sopenharmony_ci 257a3e0fd82Sopenharmony_ci#if ENABLE_ROTATE_INPUT 258a3e0fd82Sopenharmony_ci /** 259a3e0fd82Sopenharmony_ci * @brief Sets coefficient for rotation dragthrow animation. The view will roll farther with larger coeffcient. 260a3e0fd82Sopenharmony_ci * 261a3e0fd82Sopenharmony_ci * @param value Indicates the coefficient to set. The default value is <b>0</b>. 262a3e0fd82Sopenharmony_ci * @since 1.0 263a3e0fd82Sopenharmony_ci * @version 1.0 264a3e0fd82Sopenharmony_ci */ 265a3e0fd82Sopenharmony_ci void SetRotateACCLevel(uint8_t value) 266a3e0fd82Sopenharmony_ci { 267a3e0fd82Sopenharmony_ci rotateAccCoefficient_ = value; 268a3e0fd82Sopenharmony_ci } 269a3e0fd82Sopenharmony_ci 270a3e0fd82Sopenharmony_ci /** 271a3e0fd82Sopenharmony_ci * @brief Obtains the coefficient for rotation drag throw animation. 272a3e0fd82Sopenharmony_ci * 273a3e0fd82Sopenharmony_ci * @return Returns the coefficient for rotation drag throw animation. 274a3e0fd82Sopenharmony_ci * @since 1.0 275a3e0fd82Sopenharmony_ci * @version 1.0 276a3e0fd82Sopenharmony_ci */ 277a3e0fd82Sopenharmony_ci uint8_t GetRotateACCLevel() const 278a3e0fd82Sopenharmony_ci { 279a3e0fd82Sopenharmony_ci return rotateAccCoefficient_; 280a3e0fd82Sopenharmony_ci } 281a3e0fd82Sopenharmony_ci 282a3e0fd82Sopenharmony_ci /** 283a3e0fd82Sopenharmony_ci * @brief Obtains the rotation factor. 284a3e0fd82Sopenharmony_ci * 285a3e0fd82Sopenharmony_ci * @return Returns the rotation factor. 286a3e0fd82Sopenharmony_ci * @since 5.0 287a3e0fd82Sopenharmony_ci * @version 3.0 288a3e0fd82Sopenharmony_ci */ 289a3e0fd82Sopenharmony_ci float GetRotateFactor() const 290a3e0fd82Sopenharmony_ci { 291a3e0fd82Sopenharmony_ci return rotateFactor_; 292a3e0fd82Sopenharmony_ci } 293a3e0fd82Sopenharmony_ci 294a3e0fd82Sopenharmony_ci /** 295a3e0fd82Sopenharmony_ci * @brief Sets the rotation factor. 296a3e0fd82Sopenharmony_ci * 297a3e0fd82Sopenharmony_ci * @param factor Indicates the rotation factor to set. 298a3e0fd82Sopenharmony_ci * @since 5.0 299a3e0fd82Sopenharmony_ci * @version 3.0 300a3e0fd82Sopenharmony_ci */ 301a3e0fd82Sopenharmony_ci void SetRotateFactor(float factor) 302a3e0fd82Sopenharmony_ci { 303a3e0fd82Sopenharmony_ci if (MATH_ABS(factor) > MAX_ROTATE_FACTOR) { 304a3e0fd82Sopenharmony_ci rotateFactor_ = (factor > 0) ? MAX_ROTATE_FACTOR : -MAX_ROTATE_FACTOR; 305a3e0fd82Sopenharmony_ci return; 306a3e0fd82Sopenharmony_ci } 307a3e0fd82Sopenharmony_ci rotateFactor_ = factor; 308a3e0fd82Sopenharmony_ci } 309a3e0fd82Sopenharmony_ci 310a3e0fd82Sopenharmony_ci /** 311a3e0fd82Sopenharmony_ci * @brief Sets threshold for rotation drag throw animation. The view will roll easier with larger threshold. 312a3e0fd82Sopenharmony_ci * 313a3e0fd82Sopenharmony_ci * @param threshold Indicates the rotation factor to set. 314a3e0fd82Sopenharmony_ci * 315a3e0fd82Sopenharmony_ci * @since 6 316a3e0fd82Sopenharmony_ci */ 317a3e0fd82Sopenharmony_ci void SetRotateThrowThreshold(uint8_t threshold) 318a3e0fd82Sopenharmony_ci { 319a3e0fd82Sopenharmony_ci if (threshold == 0) { 320a3e0fd82Sopenharmony_ci return; 321a3e0fd82Sopenharmony_ci } 322a3e0fd82Sopenharmony_ci rotateThrowthreshold_ = threshold; 323a3e0fd82Sopenharmony_ci } 324a3e0fd82Sopenharmony_ci 325a3e0fd82Sopenharmony_ci /** 326a3e0fd82Sopenharmony_ci * @brief Get threshold for rotation drag throw animation. The view will roll easier with larger threshold. 327a3e0fd82Sopenharmony_ci * 328a3e0fd82Sopenharmony_ci * @param Returns the threshold for rotation drag throw animation. The view will roll easier with larger threshold. 329a3e0fd82Sopenharmony_ci * 330a3e0fd82Sopenharmony_ci */ 331a3e0fd82Sopenharmony_ci uint8_t GetRotateThrowThreshold() const 332a3e0fd82Sopenharmony_ci { 333a3e0fd82Sopenharmony_ci return rotateThrowthreshold_; 334a3e0fd82Sopenharmony_ci } 335a3e0fd82Sopenharmony_ci 336a3e0fd82Sopenharmony_ci bool OnRotateStartEvent(const RotateEvent& event) override; 337a3e0fd82Sopenharmony_ci 338a3e0fd82Sopenharmony_ci bool OnRotateEvent(const RotateEvent& event) override; 339a3e0fd82Sopenharmony_ci 340a3e0fd82Sopenharmony_ci bool OnRotateEndEvent(const RotateEvent& event) override; 341a3e0fd82Sopenharmony_ci#endif 342a3e0fd82Sopenharmony_ci 343a3e0fd82Sopenharmony_ci void SetXScrollBarVisible(bool visible); 344a3e0fd82Sopenharmony_ci 345a3e0fd82Sopenharmony_ci void SetYScrollBarVisible(bool visible); 346a3e0fd82Sopenharmony_ci 347a3e0fd82Sopenharmony_ci void SetScrollBarSide(uint8_t side) 348a3e0fd82Sopenharmony_ci { 349a3e0fd82Sopenharmony_ci scrollBarSide_ = side; 350a3e0fd82Sopenharmony_ci } 351a3e0fd82Sopenharmony_ci 352a3e0fd82Sopenharmony_ci /** 353a3e0fd82Sopenharmony_ci * @brief Get ScrollBarSide. 354a3e0fd82Sopenharmony_ci * 355a3e0fd82Sopenharmony_ci * @param Returns the scrollBarSide_. 356a3e0fd82Sopenharmony_ci * 357a3e0fd82Sopenharmony_ci */ 358a3e0fd82Sopenharmony_ci uint8_t GetScrollBarSide() 359a3e0fd82Sopenharmony_ci { 360a3e0fd82Sopenharmony_ci return scrollBarSide_; 361a3e0fd82Sopenharmony_ci } 362a3e0fd82Sopenharmony_ci 363a3e0fd82Sopenharmony_ci void SetScrollBarCenter(const Point& center) 364a3e0fd82Sopenharmony_ci { 365a3e0fd82Sopenharmony_ci scrollBarCenter_ = center; 366a3e0fd82Sopenharmony_ci scrollBarCenterSetFlag_ = true; 367a3e0fd82Sopenharmony_ci } 368a3e0fd82Sopenharmony_ci 369a3e0fd82Sopenharmony_ci /** 370a3e0fd82Sopenharmony_ci * @brief Get scrollBarCenter. 371a3e0fd82Sopenharmony_ci * 372a3e0fd82Sopenharmony_ci * @param Returns the scrollBarCenter_. 373a3e0fd82Sopenharmony_ci * 374a3e0fd82Sopenharmony_ci */ 375a3e0fd82Sopenharmony_ci Point GetScrollBarCenter() 376a3e0fd82Sopenharmony_ci { 377a3e0fd82Sopenharmony_ci return scrollBarCenter_; 378a3e0fd82Sopenharmony_ci } 379a3e0fd82Sopenharmony_ci 380a3e0fd82Sopenharmony_ci /** 381a3e0fd82Sopenharmony_ci * @brief Sets the list direction. 382a3e0fd82Sopenharmony_ci * 383a3e0fd82Sopenharmony_ci * @param direction Indicates the list direction, either {@link HORIZONTAL} or {@link VERTICAL}. 384a3e0fd82Sopenharmony_ci * @since 1.0 385a3e0fd82Sopenharmony_ci * @version 1.0 386a3e0fd82Sopenharmony_ci */ 387a3e0fd82Sopenharmony_ci void SetDirection(uint8_t direction) 388a3e0fd82Sopenharmony_ci { 389a3e0fd82Sopenharmony_ci direction_ = direction; 390a3e0fd82Sopenharmony_ci } 391a3e0fd82Sopenharmony_ci 392a3e0fd82Sopenharmony_ci /** 393a3e0fd82Sopenharmony_ci * @brief Obtains the list direction. 394a3e0fd82Sopenharmony_ci * @return Returns the list direction, either {@link HORIZONTAL} or {@link VERTICAL}. 395a3e0fd82Sopenharmony_ci * @since 1.0 396a3e0fd82Sopenharmony_ci * @version 1.0 397a3e0fd82Sopenharmony_ci */ 398a3e0fd82Sopenharmony_ci uint8_t GetDirection() const 399a3e0fd82Sopenharmony_ci { 400a3e0fd82Sopenharmony_ci return direction_; 401a3e0fd82Sopenharmony_ci } 402a3e0fd82Sopenharmony_ci 403a3e0fd82Sopenharmony_ci void OnPostDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) override; 404a3e0fd82Sopenharmony_ci 405a3e0fd82Sopenharmony_ci static constexpr uint8_t HORIZONTAL = 0; 406a3e0fd82Sopenharmony_ci static constexpr uint8_t VERTICAL = 1; 407a3e0fd82Sopenharmony_ci 408a3e0fd82Sopenharmony_ciprotected: 409a3e0fd82Sopenharmony_ci static constexpr uint8_t HORIZONTAL_AND_VERTICAL = 2; 410a3e0fd82Sopenharmony_ci static constexpr uint8_t HORIZONTAL_NOR_VERTICAL = 3; 411a3e0fd82Sopenharmony_ci /* calculate drag throw distance, last drag distance in one tick * DRAG_DISTANCE_COEFFICIENT */ 412a3e0fd82Sopenharmony_ci static constexpr uint8_t DRAG_DISTANCE_COEFFICIENT = 5; 413a3e0fd82Sopenharmony_ci /* calculate drag throw times, drag distance / DRAG_TIMES_COEFFICIENT */ 414a3e0fd82Sopenharmony_ci static constexpr uint8_t DRAG_TIMES_COEFFICIENT = 18; 415a3e0fd82Sopenharmony_ci /* the minimum duration of the swipe animator */ 416a3e0fd82Sopenharmony_ci static constexpr uint8_t MIN_DRAG_TIMES = 5; 417a3e0fd82Sopenharmony_ci /* acceleration calculation coefficient */ 418a3e0fd82Sopenharmony_ci static constexpr uint8_t DRAG_ACC_FACTOR = 10; 419a3e0fd82Sopenharmony_ci /* the maximum number of historical drag data */ 420a3e0fd82Sopenharmony_ci static constexpr uint8_t MAX_DELTA_SIZE = 3; 421a3e0fd82Sopenharmony_ci 422a3e0fd82Sopenharmony_ci static constexpr uint16_t SCROLL_BAR_WIDTH = 4; 423a3e0fd82Sopenharmony_ci static constexpr uint8_t MAX_ROTATE_FACTOR = 128; 424a3e0fd82Sopenharmony_ci 425a3e0fd82Sopenharmony_ci class ListAnimatorCallback : public AnimatorCallback { 426a3e0fd82Sopenharmony_ci public: 427a3e0fd82Sopenharmony_ci ListAnimatorCallback() 428a3e0fd82Sopenharmony_ci : curtTime_(0), 429a3e0fd82Sopenharmony_ci dragTimes_(0), 430a3e0fd82Sopenharmony_ci startValueX_(0), 431a3e0fd82Sopenharmony_ci endValueX_(0), 432a3e0fd82Sopenharmony_ci previousValueX_(0), 433a3e0fd82Sopenharmony_ci startValueY_(0), 434a3e0fd82Sopenharmony_ci endValueY_(0), 435a3e0fd82Sopenharmony_ci previousValueY_(0) 436a3e0fd82Sopenharmony_ci { 437a3e0fd82Sopenharmony_ci } 438a3e0fd82Sopenharmony_ci 439a3e0fd82Sopenharmony_ci virtual ~ListAnimatorCallback() {} 440a3e0fd82Sopenharmony_ci 441a3e0fd82Sopenharmony_ci void SetDragTimes(uint16_t times) 442a3e0fd82Sopenharmony_ci { 443a3e0fd82Sopenharmony_ci dragTimes_ = times; 444a3e0fd82Sopenharmony_ci } 445a3e0fd82Sopenharmony_ci 446a3e0fd82Sopenharmony_ci void SetDragStartValue(int16_t startValueX, int16_t startValueY) 447a3e0fd82Sopenharmony_ci { 448a3e0fd82Sopenharmony_ci startValueX_ = startValueX; 449a3e0fd82Sopenharmony_ci previousValueX_ = startValueX; 450a3e0fd82Sopenharmony_ci startValueY_ = startValueY; 451a3e0fd82Sopenharmony_ci previousValueY_ = startValueY; 452a3e0fd82Sopenharmony_ci } 453a3e0fd82Sopenharmony_ci 454a3e0fd82Sopenharmony_ci void SetDragEndValue(int16_t endValueX, int16_t endValueY) 455a3e0fd82Sopenharmony_ci { 456a3e0fd82Sopenharmony_ci endValueX_ = endValueX; 457a3e0fd82Sopenharmony_ci endValueY_ = endValueY; 458a3e0fd82Sopenharmony_ci } 459a3e0fd82Sopenharmony_ci 460a3e0fd82Sopenharmony_ci void ResetCallback() 461a3e0fd82Sopenharmony_ci { 462a3e0fd82Sopenharmony_ci curtTime_ = 0; 463a3e0fd82Sopenharmony_ci dragTimes_ = 0; 464a3e0fd82Sopenharmony_ci startValueX_ = 0; 465a3e0fd82Sopenharmony_ci endValueX_ = 0; 466a3e0fd82Sopenharmony_ci startValueY_ = 0; 467a3e0fd82Sopenharmony_ci endValueY_ = 0; 468a3e0fd82Sopenharmony_ci } 469a3e0fd82Sopenharmony_ci 470a3e0fd82Sopenharmony_ci void Callback(UIView* view) override; 471a3e0fd82Sopenharmony_ci 472a3e0fd82Sopenharmony_ci uint16_t curtTime_; 473a3e0fd82Sopenharmony_ci uint16_t dragTimes_; 474a3e0fd82Sopenharmony_ci int16_t startValueX_; 475a3e0fd82Sopenharmony_ci int16_t endValueX_; 476a3e0fd82Sopenharmony_ci int16_t previousValueX_; 477a3e0fd82Sopenharmony_ci int16_t startValueY_; 478a3e0fd82Sopenharmony_ci int16_t endValueY_; 479a3e0fd82Sopenharmony_ci int16_t previousValueY_; 480a3e0fd82Sopenharmony_ci }; 481a3e0fd82Sopenharmony_ci 482a3e0fd82Sopenharmony_ci bool DragThrowAnimator(Point currentPos, Point lastPos, uint8_t dragDirection, bool dragBack = true); 483a3e0fd82Sopenharmony_ci 484a3e0fd82Sopenharmony_ci virtual void StopAnimator(); 485a3e0fd82Sopenharmony_ci 486a3e0fd82Sopenharmony_ci virtual bool DragXInner(int16_t distance) = 0; 487a3e0fd82Sopenharmony_ci 488a3e0fd82Sopenharmony_ci virtual bool DragYInner(int16_t distance) = 0; 489a3e0fd82Sopenharmony_ci 490a3e0fd82Sopenharmony_ci void RefreshDelta(int16_t distance) 491a3e0fd82Sopenharmony_ci { 492a3e0fd82Sopenharmony_ci lastDelta_[deltaIndex_ % MAX_DELTA_SIZE] = distance; 493a3e0fd82Sopenharmony_ci deltaIndex_++; 494a3e0fd82Sopenharmony_ci } 495a3e0fd82Sopenharmony_ci 496a3e0fd82Sopenharmony_ci void InitDelta(); 497a3e0fd82Sopenharmony_ci 498a3e0fd82Sopenharmony_ci void RefreshRotate(int16_t distance) 499a3e0fd82Sopenharmony_ci { 500a3e0fd82Sopenharmony_ci lastRotate_[rotateIndex_ % MAX_DELTA_SIZE] = distance; 501a3e0fd82Sopenharmony_ci rotateIndex_++; 502a3e0fd82Sopenharmony_ci } 503a3e0fd82Sopenharmony_ci 504a3e0fd82Sopenharmony_ci void InitRotate(); 505a3e0fd82Sopenharmony_ci 506a3e0fd82Sopenharmony_ci virtual void CalculateDragDistance(Point currentPos, 507a3e0fd82Sopenharmony_ci Point lastPos, 508a3e0fd82Sopenharmony_ci uint8_t dragDirection, 509a3e0fd82Sopenharmony_ci int16_t& dragDistanceX, 510a3e0fd82Sopenharmony_ci int16_t& dragDistanceY); 511a3e0fd82Sopenharmony_ci 512a3e0fd82Sopenharmony_ci void StartAnimator(int16_t dragDistanceX, int16_t dragDistanceY); 513a3e0fd82Sopenharmony_ci 514a3e0fd82Sopenharmony_ci virtual void CalculateReboundDistance(int16_t& dragDistanceX, int16_t& dragDistanceY) {} 515a3e0fd82Sopenharmony_ci 516a3e0fd82Sopenharmony_ci int16_t GetMaxDelta() const; 517a3e0fd82Sopenharmony_ci 518a3e0fd82Sopenharmony_ci int16_t GetMaxRotate() const; 519a3e0fd82Sopenharmony_ci 520a3e0fd82Sopenharmony_ci void RefreshAnimator(); 521a3e0fd82Sopenharmony_ci 522a3e0fd82Sopenharmony_ci virtual void FixDistance(int16_t& distanceX, int16_t& distanceY) {} 523a3e0fd82Sopenharmony_ci 524a3e0fd82Sopenharmony_ci uint16_t scrollBlankSize_ = 0; 525a3e0fd82Sopenharmony_ci uint16_t reboundSize_ = 0; 526a3e0fd82Sopenharmony_ci uint16_t maxScrollDistance_ = 0; 527a3e0fd82Sopenharmony_ci int16_t lastDelta_[MAX_DELTA_SIZE] = {0}; 528a3e0fd82Sopenharmony_ci int16_t lastRotate_[MAX_DELTA_SIZE] = {0}; 529a3e0fd82Sopenharmony_ci uint8_t dragAccCoefficient_ = DRAG_ACC_FACTOR; 530a3e0fd82Sopenharmony_ci uint8_t swipeAccCoefficient_ = 0; 531a3e0fd82Sopenharmony_ci uint8_t direction_ : 2; 532a3e0fd82Sopenharmony_ci uint8_t deltaIndex_ : 2; 533a3e0fd82Sopenharmony_ci uint8_t rotateIndex_ : 2; 534a3e0fd82Sopenharmony_ci uint8_t reserve_ : 2; 535a3e0fd82Sopenharmony_ci bool throwDrag_ = false; 536a3e0fd82Sopenharmony_ci EasingFunc easingFunc_; 537a3e0fd82Sopenharmony_ci ListAnimatorCallback animatorCallback_; 538a3e0fd82Sopenharmony_ci Animator scrollAnimator_; 539a3e0fd82Sopenharmony_ci#if ENABLE_ROTATE_INPUT 540a3e0fd82Sopenharmony_ci uint8_t rotateAccCoefficient_ = 0; 541a3e0fd82Sopenharmony_ci float rotateFactor_; 542a3e0fd82Sopenharmony_ci uint8_t rotateThrowthreshold_; 543a3e0fd82Sopenharmony_ci bool isRotating_; 544a3e0fd82Sopenharmony_ci#endif 545a3e0fd82Sopenharmony_ci bool yScrollBarVisible_ = false; 546a3e0fd82Sopenharmony_ci UIAbstractScrollBar* yScrollBar_ = nullptr; 547a3e0fd82Sopenharmony_ci bool xScrollBarVisible_ = false; 548a3e0fd82Sopenharmony_ci UIAbstractScrollBar* xScrollBar_ = nullptr; 549a3e0fd82Sopenharmony_ci uint8_t scrollBarSide_; 550a3e0fd82Sopenharmony_ci Point scrollBarCenter_; 551a3e0fd82Sopenharmony_ci bool scrollBarCenterSetFlag_; 552a3e0fd82Sopenharmony_ci bool dragBack_ = true; 553a3e0fd82Sopenharmony_ci#if DEFAULT_ANIMATION 554a3e0fd82Sopenharmony_ci friend class BarEaseInOutAnimator; 555a3e0fd82Sopenharmony_ci BarEaseInOutAnimator* barEaseInOutAnimator_ = nullptr; 556a3e0fd82Sopenharmony_ci#endif 557a3e0fd82Sopenharmony_ci}; 558a3e0fd82Sopenharmony_ci} // namespace OHOS 559a3e0fd82Sopenharmony_ci#endif // GRAPHIC_LITE_UI_ABSTRACT_SCROLL_H 560