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_DECLARATION_NAVIGATION_NAVIGATION_DECLARATION_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_NAVIGATION_NAVIGATION_DECLARATION_H
18
19 #include <string>
20
21 #include "base/geometry/dimension.h"
22 #include "core/components/common/properties/color.h"
23 #include "core/components/declaration/common/declaration.h"
24 #include "core/components/navigation_bar/navigation_bar_theme.h"
25 #include "core/pipeline_ng/pipeline_context.h"
26
27 namespace OHOS::Ace::NG {
28
NavigationGetTheme()29 inline RefPtr<NavigationBarTheme> NavigationGetTheme()
30 {
31 // get theme
32 auto pipeline = PipelineContext::GetCurrentContext();
33 auto theme = pipeline->GetTheme<NavigationBarTheme>();
34 return theme;
35 }
36
37 // TODO:move some items to theme
38 // title bar back button
39 const std::string BACK_BUTTON = "Back";
40 constexpr InternalResource::ResourceId BACK_ICON = InternalResource::ResourceId::IC_BACK;
41 constexpr InternalResource::ResourceId MORE_ICON = InternalResource::ResourceId::IC_MORE;
42 // title bar and tool bar, bar item
43 constexpr float BAR_ITEM_WIDTH = 40.0f;
44 constexpr float BAR_ITEM_HEIGHT = 60.0f;
45 constexpr float BAR_TEXT_FONT_SIZE = 18.0f;
46 // title bar title and subtitle
47 constexpr float TITLE_WIDTH = 100.0f;
48 // single page maximum width
49 constexpr float SINGLE_PAGE_MAXIMUM_WIDTH = 720.0f;
50
51 // title
52 constexpr Dimension TITLE_HEIGHT = 56.0_vp;
53 constexpr Dimension MAX_TITLE_FONT_SIZE = 30.0_vp;
54 constexpr Dimension MIN_TITLE_FONT_SIZE = 20.0_vp;
55 // subtitle
56 constexpr Dimension SUBTITLE_FONT_SIZE = 14.0_vp; // ohos_id_text_size_sub_title3
57 constexpr Color SUBTITLE_COLOR = Color(0x99000000); // ohos_id_alpha_content_secondary
58 constexpr Dimension SUBTITLE_HEIGHT = 26.0_vp;
59 // back button
60 constexpr Dimension BACK_BUTTON_SIZE = 48.0_vp;
61 constexpr Dimension BACK_BUTTON_ICON_SIZE = 24.0_vp;
62 // title bar
63 constexpr Dimension TITLEBAR_HEIGHT_MINI = 56.0_vp;
64 constexpr Dimension TITLEBAR_HEIGHT_WITH_SUBTITLE = 137.0_vp;
65 constexpr Dimension TITLEBAR_HEIGHT_WITHOUT_SUBTITLE = 112.0_vp;
66 // toolbar item
67 constexpr Dimension TEXT_FONT_SIZE = 10.0_vp;
68 constexpr Color TEXT_COLOR = Color(0xE6000000);
69 constexpr Color ICON_COLOR = Color(0xE6000000);
70 // toolbar
71 constexpr Dimension ICON_PADDING = 10.0_vp;
72 constexpr Dimension TEXT_TOP_PADDING = 2.0_vp;
73
74 // divider
75 constexpr Dimension DIVIDER_WIDTH = 1.0_vp;
76 constexpr Color DIVIDER_COLOR = Color(0x08000000);
77
78 // navigation content
79 constexpr Dimension SINGLE_LINE_TITLEBAR_HEIGHT = 56.0_vp;
80 constexpr Dimension DOUBLE_LINE_TITLEBAR_HEIGHT = 82.0_vp;
81 constexpr Color CONTENT_COLOR = Color(0x00000000);
82
83 // navBar
84 constexpr Dimension FULL_SINGLE_LINE_TITLEBAR_HEIGHT = 112.0_vp;
85 constexpr Dimension FULL_DOUBLE_LINE_TITLEBAR_HEIGHT = 138.0_vp;
86 constexpr Dimension HORIZONTAL_MARGIN = 16.0_vp; // ohos_id_elements_margin_horizontal_l
87 constexpr Dimension HORIZONTAL_MARGIN_M = 8.0_vp; // ohos_id_elements_margin_horizontal_m
88 constexpr Dimension MENU_ITEM_PADDING = 24.0_vp;
89 constexpr Dimension BUTTON_PADDING = 12.0_vp;
90 constexpr Dimension BUTTON_RADIUS = 5.0_vp;
91
92 // more button
93 constexpr Dimension MORE_BUTTON_CORNER_RADIUS = 8.0_vp;
94 constexpr Dimension MENU_AND_BUTTON_SPACE = 8.0_vp;
95
96 struct BarItem {
97 std::optional<std::string> text;
98 std::optional<std::string> icon;
99 std::function<void()> action;
ToStringBarItem100 std::string ToString() const
101 {
102 std::string result;
103 result.append("text: ");
104 result.append(text.value_or("na"));
105 result.append(", icon: ");
106 result.append(icon.value_or("na"));
107 return result;
108 }
109 };
110
111 enum class TitleBarChildType {
112 TITLE = 0,
113 SUBTITLE,
114 MENU,
115 };
116
117 enum class NavigationTitleMode {
118 FREE = 0,
119 FULL,
120 MINI,
121 };
122
123 enum class NavigationMode {
124 STACK = 0,
125 SPLIT,
126 AUTO,
127 };
128
129 enum class NavBarPosition {
130 START = 0,
131 END,
132 };
133
134 enum class ChildNodeOperation {
135 ADD,
136 // remove case only used for back button
137 REMOVE,
138 REPLACE,
139 NONE
140 };
141
142 enum class TitleHeight {
143 MAIN_ONLY,
144 MAIN_WITH_SUB
145 };
146
147 enum class TitleBarParentType {
148 NAVBAR,
149 NAV_DESTINATION
150 };
151 } // namespace OHOS::Ace::NG
152 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_NAVIGATION_NAVIGATION_DECLARATION_H