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 #include "core/components/badge/badge_component.h" 17 18 #include "core/components/badge/badge_element.h" 19 20 namespace OHOS::Ace { 21 BadgeComponent()22BadgeComponent::BadgeComponent() : SoleChildComponent() 23 { 24 if (!declaration_) { 25 declaration_ = AceType::MakeRefPtr<BadgeDeclaration>(); 26 declaration_->Init(); 27 } 28 } 29 CreateRenderNode()30RefPtr<RenderNode> BadgeComponent::CreateRenderNode() 31 { 32 return RenderBadge::Create(); 33 } 34 CreateElement()35RefPtr<Element> BadgeComponent::CreateElement() 36 { 37 return AceType::MakeRefPtr<BadgeElement>(); 38 } 39 GetBadgeColor() const40const Color& BadgeComponent::GetBadgeColor() const 41 { 42 return declaration_->GetBadgeColor(); 43 } 44 GetBadgeTextColor() const45const Color& BadgeComponent::GetBadgeTextColor() const 46 { 47 return declaration_->GetBadgeTextColor(); 48 } 49 GetBadgeFontSize() const50const Dimension& BadgeComponent::GetBadgeFontSize() const 51 { 52 return declaration_->GetBadgeFontSize(); 53 } 54 GetClickEvent() const55const EventMarker& BadgeComponent::GetClickEvent() const 56 { 57 return declaration_->GetClickEvent(); 58 } 59 GetBadgePosition() const60BadgePosition BadgeComponent::GetBadgePosition() const 61 { 62 return declaration_->GetBadgePosition(); 63 } 64 GetBadgePositionX() const65const Dimension& BadgeComponent::GetBadgePositionX() const 66 { 67 return declaration_->GetBadgePositionX(); 68 } 69 GetBadgePositionY() const70const Dimension& BadgeComponent::GetBadgePositionY() const 71 { 72 return declaration_->GetBadgePositionY(); 73 } 74 IsPositionXy() const75bool BadgeComponent::IsPositionXy() const 76 { 77 return declaration_->IsPositionXy(); 78 } 79 GetPadding() const80const Edge& BadgeComponent::GetPadding() const 81 { 82 return declaration_->GetPadding(); 83 } 84 GetBadgeCircleSize() const85const Dimension& BadgeComponent::GetBadgeCircleSize() const 86 { 87 return declaration_->GetBadgeCircleSize(); 88 } 89 GetBadgeLabel() const90const std::optional<std::string>& BadgeComponent::GetBadgeLabel() const 91 { 92 return declaration_->GetBadgeLabel(); 93 } 94 SetPadding(const Edge & padding)95void BadgeComponent::SetPadding(const Edge& padding) 96 { 97 declaration_->SetPadding(padding); 98 } 99 GetMessageCount() const100int64_t BadgeComponent::GetMessageCount() const 101 { 102 return declaration_->GetMessageCount(); 103 } 104 IsShowMessage() const105bool BadgeComponent::IsShowMessage() const 106 { 107 return declaration_->IsShowMessage(); 108 } 109 GetMaxCount() const110int64_t BadgeComponent::GetMaxCount() const 111 { 112 return declaration_->GetMaxCount(); 113 } 114 IsBadgeCircleSizeDefined() const115bool BadgeComponent::IsBadgeCircleSizeDefined() const 116 { 117 return declaration_->IsBadgeCircleSizeDefined(); 118 } 119 SetBadgeCircleSizeDefined(bool badgeCircleSizeDefined)120void BadgeComponent::SetBadgeCircleSizeDefined(bool badgeCircleSizeDefined) 121 { 122 declaration_->SetBadgeCircleSizeDefined(badgeCircleSizeDefined); 123 } 124 SetMaxCount(int64_t maxCount)125void BadgeComponent::SetMaxCount(int64_t maxCount) 126 { 127 declaration_->SetMaxCount(maxCount); 128 } 129 SetShowMessage(bool showMessage)130void BadgeComponent::SetShowMessage(bool showMessage) 131 { 132 declaration_->SetShowMessage(showMessage); 133 } 134 SetMessageCount(int64_t messageCount)135void BadgeComponent::SetMessageCount(int64_t messageCount) 136 { 137 declaration_->SetMessageCount(messageCount); 138 } 139 SetBadgePosition(BadgePosition badgePostion)140void BadgeComponent::SetBadgePosition(BadgePosition badgePostion) 141 { 142 declaration_->SetBadgePosition(badgePostion); 143 } 144 SetBadgePositionX(const Dimension & badgePostionX)145void BadgeComponent::SetBadgePositionX(const Dimension& badgePostionX) 146 { 147 declaration_->SetBadgePositionX(badgePostionX); 148 } 149 SetBadgePositionY(const Dimension & badgePostionY)150void BadgeComponent::SetBadgePositionY(const Dimension& badgePostionY) 151 { 152 declaration_->SetBadgePositionY(badgePostionY); 153 } 154 SetIsPositionXy(bool isPositionXy)155void BadgeComponent::SetIsPositionXy(bool isPositionXy) 156 { 157 declaration_->SetIsPositionXy(isPositionXy); 158 } 159 SetBadgeTextColor(const Color & badgeTextColor)160void BadgeComponent::SetBadgeTextColor(const Color& badgeTextColor) 161 { 162 declaration_->SetBadgeTextColor(badgeTextColor); 163 } 164 SetBadgeFontSize(const Dimension & badgeFontSize)165void BadgeComponent::SetBadgeFontSize(const Dimension& badgeFontSize) 166 { 167 declaration_->SetBadgeFontSize(badgeFontSize); 168 } 169 SetBadgeColor(const Color & color)170void BadgeComponent::SetBadgeColor(const Color& color) 171 { 172 declaration_->SetBadgeColor(color); 173 } 174 SetClickEvent(const EventMarker & event)175void BadgeComponent::SetClickEvent(const EventMarker& event) 176 { 177 declaration_->SetClickEvent(event); 178 } 179 SetBadgeCircleSize(const Dimension & badgeCircleSize)180void BadgeComponent::SetBadgeCircleSize(const Dimension& badgeCircleSize) 181 { 182 declaration_->SetBadgeCircleSize(badgeCircleSize); 183 } 184 SetBadgeLabel(const std::string & badgeLabel)185void BadgeComponent::SetBadgeLabel(const std::string& badgeLabel) 186 { 187 declaration_->SetBadgeLabel(badgeLabel); 188 } 189 SetDeclaration(const RefPtr<BadgeDeclaration> & declaration)190void BadgeComponent::SetDeclaration(const RefPtr<BadgeDeclaration>& declaration) 191 { 192 if (declaration) { 193 declaration_ = declaration; 194 } 195 } 196 197 } // namespace OHOS::Ace 198