• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_ACE_ENGINE_FRAMEWORKS_CORE_COMPONENTS_COMMON_PROPERTIES_DIALOG_PROPERTIES_H
17 #define FOUNDATION_ACE_ACE_ENGINE_FRAMEWORKS_CORE_COMPONENTS_COMMON_PROPERTIES_DIALOG_PROPERTIES_H
18 
19 #include "base/geometry/dimension_offset.h"
20 #include "core/event/ace_event_handler.h"
21 #include "core/gestures/gesture_info.h"
22 
23 namespace OHOS::Ace {
24 
25 enum class DialogType {
26     COMMON = 0,
27     ALERT_DIALOG,
28     ACTION_SHEET,
29 };
30 
31 // Alignment of dialog in vertical.
32 enum class DialogAlignment {
33     TOP = 0,
34     CENTER,
35     BOTTOM,
36     DEFAULT,
37     TOP_START,
38     TOP_END,
39     CENTER_START,
40     CENTER_END,
41     BOTTOM_START,
42     BOTTOM_END,
43 };
44 
45 // Information of ActionSheet
46 struct ActionSheetInfo {
47     std::string title;       // title of ActionSheet, necessary.
48     std::string icon;        // icon of ActionSheet, not necessary.
49     EventMarker callbackId;  // called when ActionSheet is clicked.
50     RefPtr<Gesture> gesture; // called when ActionSheet is clicked.
51 
52     // Whether sheetInfo is valid, valid if title if not empty.
IsValidActionSheetInfo53     bool IsValid() const
54     {
55         return !title.empty();
56     }
57 };
58 
59 // Information of Button.
60 struct ButtonInfo {
61     std::string text;      // text of button.
62     std::string textColor; // style of text in button.
63     bool isBgColorSetted = false;
64     Color bgColor;   // background color of button.
65 
66     // Whether button info is valid, valid if text is not empty.
IsValidButtonInfo67     bool IsValid() const
68     {
69         return !text.empty();
70     }
71 };
72 
73 struct DialogProperties {
74     DialogType type = DialogType::COMMON; // type of dialog, current support common dialog and alert dialog.
75     std::string title;                    // title of dialog.
76     std::string content;                  // message of dialog.
77     bool autoCancel = true;               // pop dialog when click mask if autoCancel is true.
78     bool customStyle = false;             // whether use custom style.
79     bool isMenu = false;
80     std::vector<ButtonInfo> buttons;
81     std::unordered_map<std::string, EventMarker> callbacks; // <callback type(success, cancel, complete), eventId>
82     DialogAlignment alignment = DialogAlignment::DEFAULT;   // Alignment of dialog.
83     DimensionOffset offset;                                 // Offset which base on alignment of Dialog.
84     int32_t gridCount = 0;
85 
86     // These ids is used for AlertDialog of declarative.
87     EventMarker primaryId;   // first button's callback.
88     EventMarker secondaryId; // second button's callback.
89 
90     // These attributes is used for CustomDialog.
91     RefPtr<Component> customComponent;         // Used for CustomDialog in declarative.
92     std::function<void(bool)> onStatusChanged; // Called when dialog appear or disappear.
93 
94     // These attributes is used for ActionSheet.
95     std::vector<ActionSheetInfo> sheetsInfo;
96 };
97 
98 } // namespace OHOS::Ace
99 
100 #endif // FOUNDATION_ACE_ACE_ENGINE_FRAMEWORKS_CORE_COMPONENTS_COMMON_PROPERTIES_DIALOG_PROPERTIES_H
101