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_BADGE_RENDER_BADGE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BADGE_RENDER_BADGE_H 18 19 #include "base/utils/system_properties.h" 20 #include "core/components/badge/badge_component.h" 21 #include "core/components/common/properties/color.h" 22 #include "core/components/text/render_text.h" 23 #include "core/components/text/text_component.h" 24 #include "core/gestures/click_recognizer.h" 25 #include "core/pipeline/base/render_node.h" 26 27 namespace OHOS::Ace { 28 29 class RenderBadge : public RenderNode { 30 DECLARE_ACE_TYPE(RenderBadge, RenderNode); 31 32 public: 33 RenderBadge(); 34 ~RenderBadge() override; 35 36 static RefPtr<RenderNode> Create(); 37 38 void Update(const RefPtr<Component>& component) override; 39 void PerformLayout() override; 40 virtual Size CalculateTextSize(const std::string& text, const TextStyle& textStyle, 41 RefPtr<RenderText>& renderText) = 0; 42 GetBadgeComponent()43 const RefPtr<BadgeComponent>& GetBadgeComponent() const 44 { 45 return badge_; 46 } 47 48 protected: 49 void OnTouchTestHit( 50 const Offset& coordinateOffset, const TouchRestrict& touchRestrict, TouchTestResult& result) override; 51 void HandleClickEvent(); 52 void InitialBadgeText(); 53 void UpdateBadgeText(); 54 bool ParseBadgeStatus(const std::optional<std::string>& label, int64_t messageCount, int64_t countLimit); 55 56 double width_ = 0.0; 57 double height_ = 0.0; 58 Size badgeSize_; 59 std::string textData_; 60 bool showMessage_ = true; 61 std::function<void()> onClick_; 62 RefPtr<ClickRecognizer> clickRecognizer_; 63 RefPtr<RenderText> badgeRenderText_; 64 RefPtr<TextComponent> badgeTextComponent_; 65 TextStyle textStyle_; 66 RefPtr<BadgeComponent> badge_; 67 Offset badgeChildInitialOffset_; 68 double dipScale_ = 1.0; 69 }; 70 71 } // namespace OHOS::Ace 72 73 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_BADGE_RENDER_BADGE_H 74