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_ITEM_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_INDEXER_RENDER_INDEXER_ITEM_H 18 19 #include "base/utils/string_utils.h" 20 #include "core/animation/animator.h" 21 #include "core/animation/keyframe_animation.h" 22 #include "core/components/box/render_box.h" 23 #include "core/components/text/text_component.h" 24 #include "core/components/transform/render_transform.h" 25 26 namespace OHOS::Ace { 27 28 class RenderIndexerItem : public RenderNode { 29 DECLARE_ACE_TYPE(RenderIndexerItem, RenderNode); 30 31 public: 32 static RefPtr<RenderNode> Create(); 33 void Update(const RefPtr<Component>& component) override; 34 void PerformLayout() override; 35 void UpdateItemBackground(const Color& color); 36 void UpdateItemStyle(); 37 38 bool IsBackgroundColorEnabled(); 39 40 void MarkItemInAnimation(bool inAnimation = true) 41 { 42 isAnimating_ = inAnimation; 43 } 44 GetItemType()45 int32_t GetItemType() const 46 { 47 return itemType_; 48 } 49 IsItemPrimary()50 bool IsItemPrimary() const 51 { 52 return isPrimary_; 53 } 54 GetSectionText()55 const std::string GetSectionText() const 56 { 57 return StringUtils::Str16ToStr8(strText_); 58 } 59 GetSectionIndex()60 int32_t GetSectionIndex() const 61 { 62 return sectionIndex_; 63 } 64 SetSectionIndex(int32_t index)65 void SetSectionIndex(int32_t index) 66 { 67 sectionIndex_ = index; 68 } 69 GetKeyCount()70 uint32_t GetKeyCount() const 71 { 72 return keyCount_; 73 } 74 SetKeyCount(uint32_t keyCount)75 void SetKeyCount(uint32_t keyCount) 76 { 77 keyCount_ = keyCount; 78 } 79 GetClicked()80 bool GetClicked() const 81 { 82 return clicked_; 83 } 84 SetFocused(bool getFocus)85 void SetFocused(bool getFocus) 86 { 87 focused_ = getFocus; 88 UpdateItemStyle(); 89 } 90 SetClicked(bool clicked)91 void SetClicked(bool clicked) 92 { 93 bool preClicked = clicked_; 94 clicked_ = (clicked && keyCount_ > 0); 95 if (clicked_ != preClicked) { 96 UpdateItemStyle(); 97 } 98 } 99 SetRotate(double angle)100 void SetRotate(double angle) 101 { 102 RefPtr<RenderTransform> rotate = AceType::DynamicCast<RenderTransform>(GetChildren().front()); 103 if (rotate) { 104 rotateAngle_ = angle; 105 rotate->ResetTransform(); 106 rotate->RotateZ(angle); 107 } 108 } 109 GetNormalTextStyle()110 const TextStyle& GetNormalTextStyle() const 111 { 112 return normalStyle_; 113 } 114 GetActiveTextStyle()115 const TextStyle& GetActiveTextStyle() const 116 { 117 return activeStyle_; 118 } 119 120 protected: 121 bool MouseHoverTest(const Point& parentLocalPoint) override; 122 void OnMouseHoverEnterTest() override; 123 void OnMouseHoverExitTest() override; 124 125 private: 126 void StartHoverAnimation(RefPtr<Animator> controller, 127 RefPtr<KeyframeAnimation<Color>>& colorAnimation); 128 void ResetController(RefPtr<Animator>& controller); 129 void CreateColorAnimation(RefPtr<KeyframeAnimation<Color>>& colorAnimation, const Color& beginValue, 130 const Color& endValue); 131 132 bool clicked_ = false; 133 bool focused_ = false; 134 int32_t itemType_ = 0; 135 int32_t sectionIndex_ = 0; 136 uint32_t keyCount_ = 0; 137 RefPtr<TextComponent> textComponent_; 138 RefPtr<Animator> controllerEnter_; 139 RefPtr<Animator> controllerExit_; 140 RefPtr<KeyframeAnimation<Color>> colorAnimationEnter_; 141 RefPtr<KeyframeAnimation<Color>> colorAnimationExit_; 142 TextStyle normalStyle_; 143 TextStyle activeStyle_; 144 double currentTextSize_ = 0.0; 145 double defaultTextSize_ = 0.0; 146 bool circleMode_ = true; 147 bool rotate_ = false; 148 bool isPrimary_ = false; 149 bool isAnimating_ = false; 150 double rotateAngle_ = 0.0; 151 std::u16string strText_; 152 }; // class RenderIndexerItem 153 154 } // namespace OHOS::Ace 155 156 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_INDEXER_RENDER_INDEXER_ITEM_H 157