1 /* 2 * Copyright (c) 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_NG_PATTERNS_BUTTON_TOGGLE_BUTTON_PATTERN_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_BUTTON_TOGGLE_BUTTON_PATTERN_H 18 19 #include <optional> 20 21 #include "core/components/common/layout/constants.h" 22 #include "core/components/common/properties/color.h" 23 #include "core/components_ng/event/event_hub.h" 24 #include "core/components_ng/pattern/button/button_pattern.h" 25 #include "core/components_ng/pattern/button/toggle_button_event_hub.h" 26 #include "core/components_ng/pattern/button/toggle_button_paint_property.h" 27 28 namespace OHOS::Ace::NG { 29 class ToggleButtonPattern : public ButtonPattern { 30 DECLARE_ACE_TYPE(ToggleButtonPattern, ButtonPattern); 31 32 public: 33 ToggleButtonPattern() = default; 34 35 ~ToggleButtonPattern() override = default; 36 IsAtomicNode()37 bool IsAtomicNode() const override 38 { 39 return false; 40 } 41 CreateEventHub()42 RefPtr<EventHub> CreateEventHub() override 43 { 44 return MakeRefPtr<ToggleButtonEventHub>(); 45 } 46 CreatePaintProperty()47 RefPtr<PaintProperty> CreatePaintProperty() override 48 { 49 return MakeRefPtr<ToggleButtonPaintProperty>(); 50 } 51 52 void OnClick(); 53 54 private: 55 void OnAttachToFrameNode() override; 56 void InitParameters(); 57 void OnModifyDone() override; 58 void HandleEnabled(); 59 void InitClickEvent(); 60 void InitButtonAndText(); 61 void InitOnKeyEvent(); 62 bool OnKeyEvent(const KeyEvent& event); 63 64 RefPtr<ClickEvent> clickListener_; 65 std::optional<bool> isOn_; 66 Color checkedColor_; 67 Color unCheckedColor_; 68 float disabledAlpha_ { 1.0f }; 69 Dimension textMargin_; 70 Dimension buttonMargin_; 71 Dimension buttonHeight_; 72 Dimension buttonRadius_; 73 Dimension textFontSize_; 74 Color textColor_; 75 76 ACE_DISALLOW_COPY_AND_MOVE(ToggleButtonPattern); 77 }; 78 } // namespace OHOS::Ace::NG 79 80 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_BUTTON_TOGGLE_BUTTON_PATTERN_H 81