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_PICKER_RENDER_PICKER_OPTION_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PICKER_RENDER_PICKER_OPTION_H 18 19 #include "core/components/box/box_component.h" 20 #include "core/components/box/render_box.h" 21 #include "core/components/text/render_text.h" 22 #include "core/components/text/text_component.h" 23 #include "core/gestures/press_recognizer.h" 24 #include "core/pipeline/base/render_node.h" 25 26 namespace OHOS::Ace { 27 28 class RenderPickerOption : public RenderNode { 29 DECLARE_ACE_TYPE(RenderPickerOption, RenderNode); 30 31 public: 32 RenderPickerOption(); 33 ~RenderPickerOption() override = default; 34 35 void Update(const RefPtr<Component>& component) override; 36 void PerformLayout() override; 37 void OnPaintFinish() override; 38 39 bool GetSelected() const; 40 41 void UpdateValue(uint32_t newIndex, const std::string& newText); 42 void UpdateFocus(bool focus); 43 void UpdatePhoneFocus(bool focus); 44 void UpdateTextFocus(bool focus); 45 void UpdateScrollDelta(double delta); 46 void UpdateRenders(); 47 void HandleMouseHoverEvent(MouseState mouseState) override; 48 GetFocusAnimationColor()49 const Color& GetFocusAnimationColor() const 50 { 51 return focusColor_; 52 } 53 GetFocusBackColor()54 Color GetFocusBackColor() const 55 { 56 if (!focusDecoration_) { 57 return Color::WHITE; 58 } 59 return focusDecoration_->GetBackgroundColor(); 60 } 61 GetNormalBackColor()62 Color GetNormalBackColor() const 63 { 64 if (!selectedDecoration_) { 65 return Color::TRANSPARENT; 66 } 67 return selectedDecoration_->GetBackgroundColor(); 68 } 69 GetRenderBox()70 RefPtr<RenderBox> GetRenderBox() const 71 { 72 return renderBox_; 73 } 74 75 protected: 76 void OnTouchTestHit(const Offset&, const TouchRestrict&, TouchTestResult& result) override; 77 void OnMouseHoverEnterTest() override; 78 void OnMouseHoverExitTest() override; 79 void StartHoverAnimation(bool isEnter); 80 void StartPressAnimation(bool isDown); 81 bool ResetHoverAnimation(bool isEnter); 82 bool ResetPressAnimation(bool isDown); 83 void ResetMouseController(); 84 void UpdateBackgroundDecoration(const Color& color); 85 86 private: 87 double LayoutBox(); 88 void GetRenders(const RefPtr<RenderNode>& render); 89 void GetRenders(); 90 void ClearRenders(); 91 void RefreshFocus(); 92 93 Size optionSize_; 94 bool optionDefaultHeight_ = false; 95 DimensionUnit optionSizeUnit_ = DimensionUnit::PX; 96 Size realSize_; 97 double deltaSize_ = 0.0; 98 double optionPadding_ = 0.0; 99 double realPadding_ = 0.0; 100 101 TextStyle selectedStyle_; 102 TextStyle focusStyle_; 103 Color focusColor_; 104 Radius rrectRadius_; 105 106 RefPtr<Decoration> selectedDecoration_; 107 RefPtr<Decoration> focusDecoration_; 108 RefPtr<Decoration> pressDecoration_; 109 RefPtr<Decoration> hoverDecoration_; 110 RefPtr<TextComponent> textComponent_; 111 RefPtr<RenderText> renderText_; 112 RefPtr<BoxComponent> boxComponent_; 113 RefPtr<RenderBox> renderBox_; 114 RefPtr<Animator> mouseAnimationController_; 115 RefPtr<PressRecognizer> pressDetect_; 116 117 uint32_t index_ = 0; 118 std::string text_; 119 bool selected_ = false; 120 bool autoLayout_ = false; 121 bool hasAnimate_ = false; 122 bool alignTop_ = false; 123 bool alignBottom_ = false; 124 bool hasTextFocus_ = false; 125 }; 126 127 } // namespace OHOS::Ace 128 129 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PICKER_RENDER_PICKER_OPTION_H 130