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_TOGGLE_TOGGLE_COMPONENT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TOGGLE_TOGGLE_COMPONENT_H 18 19 #include "base/geometry/dimension.h" 20 #include "core/pipeline/base/sole_child_component.h" 21 #include "core/components_v2/common/common_def.h" 22 23 namespace OHOS::Ace { 24 25 class ACE_EXPORT ToggleComponent : public SoleChildComponent { 26 DECLARE_ACE_TYPE(ToggleComponent, SoleChildComponent); 27 28 public: 29 ToggleComponent() = default; 30 ~ToggleComponent() override = default; 31 32 RefPtr<RenderNode> CreateRenderNode() override; 33 RefPtr<Element> CreateElement() override; 34 GetCheckedState()35 bool GetCheckedState() const 36 { 37 return isChecked_; 38 } 39 40 ACE_DEFINE_COMPONENT_EVENT(OnChange, void(bool)); 41 GetWidth()42 const Dimension& GetWidth() const 43 { 44 return width_; 45 } 46 GetHeight()47 const Dimension& GetHeight() const 48 { 49 return height_; 50 } 51 GetBackgroundColor()52 const Color& GetBackgroundColor() const 53 { 54 return backgroundColor_; 55 } 56 GetPressedBlendColor()57 const Color& GetPressedBlendColor() const 58 { 59 return pressedBlendColor_; 60 } 61 GetCheckedColor()62 const Color& GetCheckedColor() const 63 { 64 return checkedColor_; 65 } 66 GetClickEvent()67 const EventMarker& GetClickEvent() const 68 { 69 return clickEvent_; 70 } 71 GetChangeEvent()72 const EventMarker& GetChangeEvent() const 73 { 74 return changeEvent_; 75 } 76 GetFontDefinedState()77 bool GetFontDefinedState() const 78 { 79 return fontSizeDefined_; 80 } 81 SetCheckedState(bool state)82 void SetCheckedState(bool state) 83 { 84 isChecked_ = state; 85 } 86 SetWidth(const Dimension & width)87 void SetWidth(const Dimension& width) 88 { 89 width_ = width; 90 } 91 SetHeight(const Dimension & height)92 void SetHeight(const Dimension& height) 93 { 94 height_ = height; 95 } 96 SetBackgroundColor(const Color & color)97 void SetBackgroundColor(const Color& color) 98 { 99 backgroundColor_ = color; 100 } 101 SetCheckedColor(const Color & color)102 void SetCheckedColor(const Color& color) 103 { 104 checkedColor_ = color; 105 } 106 SetPressedBlendColor(const Color & color)107 void SetPressedBlendColor(const Color& color) 108 { 109 pressedBlendColor_ = color; 110 } 111 SetClickEvent(const EventMarker & event)112 void SetClickEvent(const EventMarker& event) 113 { 114 clickEvent_ = event; 115 } 116 SetChangeEvent(const EventMarker & event)117 void SetChangeEvent(const EventMarker& event) 118 { 119 changeEvent_ = event; 120 } 121 SetFontDefinedState(bool state)122 void SetFontDefinedState(bool state) 123 { 124 fontSizeDefined_ = state; 125 } 126 SetDisabled(bool disabled)127 void SetDisabled(bool disabled) 128 { 129 isDisabled_ = disabled; 130 } 131 IsDisabled()132 bool IsDisabled() const 133 { 134 return isDisabled_; 135 } 136 137 private: 138 bool isChecked_ = false; 139 bool fontSizeDefined_ = false; 140 bool isDisabled_ = false; 141 Color backgroundColor_; 142 Color checkedColor_; 143 Color pressedBlendColor_; 144 EventMarker clickEvent_; 145 EventMarker changeEvent_; 146 Dimension width_; 147 Dimension height_; 148 }; 149 150 } // namespace OHOS::Ace 151 152 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TOGGLE_TOGGLE_COMPONENT_H 153