1/* 2 * Copyright (c) 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// 字体透明度 17const TEXT_OPACITY: number = 0.8; 18 19@Component 20export struct IconItem { 21 @Link renderGroupFlag: boolean; 22 image: string | Resource = ''; 23 text: string | Resource = ''; 24 25 build() { 26 Flex({ direction: FlexDirection.Column, justifyContent: FlexAlign.Center, alignContent: FlexAlign.Center }) { 27 Image(this.image) 28 .height($r('app.integer.RenderGroup_item_image_height')) 29 .width($r('app.integer.RenderGroup_item_image_width')) 30 .objectFit(ImageFit.Contain) 31 .margin({ 32 left: $r('app.integer.RenderGroup_item_image_margin') 33 }) 34 35 Text(this.text) 36 .fontSize($r('app.integer.RenderGroup_item_text_font')) 37 .fontColor($r('app.color.RenderGroup_item_text_fontColor')) 38 .margin({ 39 top: $r('app.integer.RenderGroup_item_text_margin_top') 40 }) 41 .width($r('app.integer.RenderGroup_item_text_width')) 42 .opacity(TEXT_OPACITY) 43 .textAlign(TextAlign.Center) 44 } 45 .backgroundColor($r('app.color.RenderGroup_item_backgroundColor')) 46 .width($r('app.integer.RenderGroup_item_width')) 47 .height($r('app.integer.RenderGroup_item_height')) 48 .borderRadius($r('app.integer.RenderGroup_item_borderRadius')) 49 // 在IconItem内调用renderGroup,true为开启,false为关闭 50 .renderGroup(this.renderGroupFlag) 51 } 52}