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_INDEXER_RENDER_INDEXER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_INDEXER_RENDER_INDEXER_H 18 19 #include "base/geometry/size.h" 20 #include "core/components/box/render_box_base.h" 21 #include "core/components/common/rotation/rotation_node.h" 22 #include "core/components/focus_animation/render_focus_animation.h" 23 #include "core/components/indexer/indexer_component.h" 24 #include "core/components/indexer/render_indexer_item.h" 25 #include "core/gestures/drag_recognizer.h" 26 #include "core/gestures/raw_recognizer.h" 27 #include "core/pipeline/base/render_node.h" 28 29 namespace OHOS::Ace { 30 31 constexpr int32_t TABLE_ANGLE = 0; 32 constexpr int32_t TABLE_POSITION_X = 1; 33 constexpr int32_t TABLE_POSITION_Y = 2; 34 constexpr int32_t TABLE_INDEX_COUNT = 3; 35 constexpr int32_t INDEXER_BUBBLE_ANIMATION_DURATION = 3000; 36 constexpr double ROTATION_THRESHOLD = 90.0; 37 constexpr double HALF = 0.5; 38 constexpr double DOUBLE = 2.0; 39 40 class RenderIndexer : public RenderNode, public RotationNode { 41 DECLARE_ACE_TYPE(RenderIndexer, RenderNode); 42 43 public: 44 RenderIndexer(); 45 ~RenderIndexer() override = default; 46 47 static RefPtr<RenderNode> Create(); 48 49 void Update(const RefPtr<Component>& component) override; 50 void PerformLayout() override; 51 void OnTouchTestHit( 52 const Offset& coordinateOffset, const TouchRestrict& touchRestrict, TouchTestResult& result) override; 53 bool TouchTest(const Point& globalPoint, const Point& parentLocalPoint, const TouchRestrict& touchRestrict, 54 TouchTestResult& result) override; OnRotation(const RotationEvent & event)55 bool OnRotation(const RotationEvent& event) override 56 { 57 return true; 58 } 59 virtual void HandleTouchDown(const TouchEventInfo& info); 60 virtual void HandleTouchUp(const TouchEventInfo& info); 61 virtual void HandleTouchMove(const TouchEventInfo& info); 62 virtual int32_t GetTouchedItemIndex(const Offset& touchPosition); HandleListMoveItems(int32_t curHeadIndex)63 virtual void HandleListMoveItems(int32_t curHeadIndex) {} UpdateCurrentSectionItem(int32_t curSection)64 virtual void UpdateCurrentSectionItem(int32_t curSection) {} BeginFocusAnimation(int32_t originIndex,int32_t targetIndex)65 virtual void BeginFocusAnimation(int32_t originIndex, int32_t targetIndex) {} 66 virtual bool IsValidBubbleBox(); 67 NeedProcess(const RefPtr<RenderNode> & item)68 virtual bool NeedProcess(const RefPtr<RenderNode>& item) const 69 { 70 return true; 71 } NeedRotation()72 virtual bool NeedRotation() const 73 { 74 return false; 75 } 76 GetCircleMode()77 bool GetCircleMode() const 78 { 79 return circleMode_; 80 } 81 GetFocusIndex()82 int32_t GetFocusIndex() const 83 { 84 return focusedIndex_; 85 } 86 SetFocusIndex(int32_t index)87 void SetFocusIndex(int32_t index) 88 { 89 focusedIndex_ = index; 90 } 91 ClearFocusAnimation()92 void ClearFocusAnimation() 93 { 94 auto context = context_.Upgrade(); 95 if (!context) { 96 LOGE("Pipeline context upgrade fail!"); 97 return; 98 } 99 if (!context->GetRenderFocusAnimation()) { 100 LOGE("focusAnimation is null!"); 101 return; 102 } 103 context->CancelFocusAnimation(); 104 } 105 106 RefPtr<RenderIndexerItem> GetSpecificItem(int32_t index); 107 108 void HandleFocusAnimation(const Size& size, const Offset& offset); 109 void MoveSectionWithIndexer(int32_t curSection); 110 111 protected: 112 void HandleDragStart(); 113 void HandleDragEnd(); 114 void HandleTouched(const Offset& touchPosition); 115 void MoveList(int32_t index); 116 void UpdateSection(int32_t index); 117 void MoveSection(int32_t index); 118 119 virtual void InitIndexTable(); 120 void InitFocusedItem(); 121 void UpdateItems(); 122 void UpdateBubbleText(); 123 void BuildBubbleAnimation(); 124 void BeginBubbleAnimation(); 125 int32_t GetItemIndex(int32_t index); // get first list item index in specified section 126 127 int32_t curHitItem_ = -1; // current touched item when touch move. 128 int32_t focusedItem_ = -1; // the item which set high light 129 int32_t nonItemCount_ = 0; 130 int32_t itemCount_ = INDEXER_ITEM_MAX_COUNT; 131 int32_t lastHeadIndex_ = 0; 132 int32_t focusedIndex_ = -1; // focused index 133 134 bool clicked_ = false; 135 bool isInitFocus_ = true; 136 bool circleMode_ = false; 137 bool bubbleEnabled_ = true; 138 139 double itemInfo_[INDEXER_ITEM_MAX_COUNT + 1][TABLE_INDEX_COUNT] = {}; 140 double itemSize_ = INDEXER_CIRCLE_ITEM_SIZE; 141 double itemSizeRender_ = INDEXER_CIRCLE_ITEM_SIZE; 142 double paddingX_ = INDEXER_DEFAULT_PADDING_X; 143 double paddingY_ = INDEXER_DEFAULT_PADDING_Y; 144 145 RefPtr<RawRecognizer> touchRecognizer_; 146 RefPtr<DragRecognizer> dragRecognizer_; 147 RefPtr<ScrollPositionController> controller_; 148 RefPtr<TextComponent> bubbleText_; 149 RefPtr<RenderBox> bubbleBox_; // reference of the bubble box render node 150 RefPtr<RenderDisplay> bubbleDisplay_; // reference of the bubble box render node 151 RefPtr<Animator> bubbleController_; // control bubble appear and disappear 152 Offset touchPostion_; 153 std::list<RefPtr<RenderNode>> items_; 154 }; 155 156 } // namespace OHOS::Ace 157 158 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_INDEXER_RENDER_INDEXER_H 159