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