• 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
16import { MenuInfo } from '../bean/MenuInfo'
17
18@Component
19export struct AppMenu {
20  private menuInfos: Array<MenuInfo> = new Array<MenuInfo>();
21
22  build() {
23    Column() {
24      ForEach(this.menuInfos, (item: MenuInfo) => {
25        Column() {
26
27          MenuInfoItem({
28            menuInfo: item
29          })
30        }
31      }, (item: MenuInfo) => JSON.stringify(item))
32    }
33    .padding({ top: 4, bottom: 4, left: 4, right: 4 })
34    .borderRadius(12)
35  }
36}
37
38@Component
39struct MenuInfoItem {
40  private menuInfo: MenuInfo = new MenuInfo();
41
42  build() {
43    Row() {
44      Image(this.menuInfo.menuImgSrc)
45        .objectFit(ImageFit.Contain)
46        .height(20)
47        .width(20)
48        .margin({ left: 12 })
49      Text(this.menuInfo.menuText)
50        .fontColor("#e5000000")
51        .fontSize(14)
52        .height(20)
53        .margin({ left: 8 })
54        .textOverflow({ overflow: TextOverflow.Ellipsis })
55    }
56    .borderRadius(12)
57    .height(40)
58    .width(235)
59    .justifyContent(FlexAlign.Start)
60    .onClick(() => {
61      this.menuInfo.onMenuClick();
62      ContextMenu.close();
63    })
64  }
65}