1 /* 2 * Copyright (c) 2021-2022 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_V2_INDEXER_INDEXER_ITEM_COMPONENT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_INDEXER_INDEXER_ITEM_COMPONENT_H 18 19 #include "base/utils/string_utils.h" 20 #include "core/components/box/box_component.h" 21 #include "core/components/image/image_component.h" 22 #include "core/components/text/text_component.h" 23 #include "core/components_v2/indexer/indexer_event_info.h" 24 25 namespace OHOS::Ace::V2 { 26 class IndexerItemComponent : public SoleChildComponent { 27 DECLARE_ACE_TYPE(IndexerItemComponent, SoleChildComponent); 28 29 public: IndexerItemComponent()30 IndexerItemComponent() 31 { 32 strSection_ = StringUtils::Str8ToStr16(""); 33 strLabel_ = StringUtils::Str8ToStr16(""); 34 BuildItem(); 35 } 36 37 IndexerItemComponent(const std::u16string& strSection, const std::u16string& strLabel, const Dimension& itemSize, 38 bool rotate = false) 39 : strSection_(strSection), strLabel_(strLabel), itemSize_(itemSize), rotate_(rotate) 40 { 41 BuildItem(); 42 } 43 44 ~IndexerItemComponent() override = default; 45 RefPtr<RenderNode> CreateRenderNode() override; 46 47 void BuildItem(); 48 GetSectionStr()49 const std::u16string& GetSectionStr() const 50 { 51 return strSection_; 52 } 53 GetLabelStr()54 const std::u16string& GetLabelStr() const 55 { 56 return strLabel_; 57 } 58 GetSectionIndex()59 int32_t GetSectionIndex() const 60 { 61 return sectionIndex_; 62 } 63 SetSectionIndex(int32_t index)64 void SetSectionIndex(int32_t index) 65 { 66 sectionIndex_ = index; 67 } 68 SetPosition(int32_t position)69 void SetPosition(int32_t position) 70 { 71 position_ = position; 72 } 73 GetPosition()74 int32_t GetPosition() const 75 { 76 return position_; 77 } 78 79 void SetTextStyle(bool active); 80 GetTextComponent()81 const RefPtr<TextComponent>& GetTextComponent() const 82 { 83 return text_; 84 } 85 GetItemSize()86 const Dimension& GetItemSize() const 87 { 88 return itemSize_; 89 } 90 SetItemSize(const Dimension & size)91 void SetItemSize(const Dimension& size) 92 { 93 itemSize_ = size; 94 } 95 GetNormalTextStyle()96 const TextStyle& GetNormalTextStyle() const 97 { 98 return normalStyle_; 99 } 100 SetNormalTextStyle(const TextStyle & textStyle)101 void SetNormalTextStyle(const TextStyle& textStyle) 102 { 103 normalStyle_ = textStyle; 104 } 105 GetActiveTextStyle()106 const TextStyle& GetActiveTextStyle() const 107 { 108 return activeStyle_; 109 } 110 SetActiveTextStyle(const TextStyle & textStyle)111 void SetActiveTextStyle(const TextStyle& textStyle) 112 { 113 activeStyle_ = textStyle; 114 } 115 GetRotateFlag()116 bool GetRotateFlag() const 117 { 118 return rotate_; 119 } 120 121 void MarkItemPrimary(bool isPrimary = true) 122 { 123 isPrimary_ = isPrimary; 124 } 125 IsItemPrimary()126 bool IsItemPrimary() const 127 { 128 return isPrimary_; 129 } 130 GetItemType()131 int32_t GetItemType() const 132 { 133 return itemType_; 134 } 135 SetItemType(int32_t type)136 void SetItemType(int32_t type) 137 { 138 itemType_ = type; 139 } 140 SetSelectedBackgroundColor(const Color & bgColor)141 void SetSelectedBackgroundColor(const Color& bgColor) 142 { 143 selectedBgColor_ = bgColor; 144 } 145 GetSelectedBackgroundColor()146 const Color& GetSelectedBackgroundColor() 147 { 148 return selectedBgColor_; 149 } 150 151 void UpdateSize(); 152 153 private: 154 std::u16string strSection_; 155 std::u16string strLabel_; // string show in the section head 156 Dimension itemSize_; // item size 157 bool rotate_ = false; 158 int32_t sectionIndex_ = 0; 159 int32_t position_ = 0; 160 int32_t itemType_ = 0; 161 RefPtr<TextComponent> text_; 162 RefPtr<ImageComponent> image_; 163 RefPtr<BoxComponent> box_; 164 TextStyle normalStyle_; 165 TextStyle activeStyle_; 166 Color selectedBgColor_; 167 bool isPrimary_ = false; 168 }; 169 } // namespace OHOS::Ace::V2 170 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_INDEXER_INDEXER_ITEM_COMPONENT_H