• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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/properties/color.h"
22 #include "core/components_ng/event/event_hub.h"
23 #include "core/components_ng/pattern/button/button_pattern.h"
24 #include "core/components_ng/pattern/button/toggle_button_accessibility_property.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 
CreateAccessibilityProperty()52     RefPtr<AccessibilityProperty> CreateAccessibilityProperty() override
53     {
54         return MakeRefPtr<ToggleButtonAccessibilityProperty>();
55     }
56     std::string ProvideRestoreInfo() override;
57     void OnRestoreInfo(const std::string& restoreInfo) override;
58     void OnClick();
59 
60 private:
61     void OnAttachToFrameNode() override;
62     void InitParameters();
63     void OnModifyDone() override;
64     void HandleEnabled();
65     void InitClickEvent();
66     void InitButtonAndText();
67     void InitOnKeyEvent();
68     bool OnKeyEvent(const KeyEvent& event);
69 
70     RefPtr<ClickEvent> clickListener_;
71     std::optional<bool> isOn_;
72     Color checkedColor_;
73     Color unCheckedColor_;
74     float disabledAlpha_ { 1.0f };
75     Dimension textMargin_;
76     Dimension buttonMargin_;
77     Dimension buttonHeight_;
78     Dimension buttonRadius_;
79     Dimension textFontSize_;
80     Color textColor_;
81 
82     ACE_DISALLOW_COPY_AND_MOVE(ToggleButtonPattern);
83 };
84 } // namespace OHOS::Ace::NG
85 
86 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_BUTTON_TOGGLE_BUTTON_PATTERN_H
87