1/* 2 * Copyright (c) 2025 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 */ 15import { BaseInterface } from './BaseInterface'; 16import { CommonConstants } from '../common/CommonConstants'; 17import { SizeMode } from './SizeMode'; 18 19/** 20 * 自定义背景条属性 21 * 22 */ 23export class IndicatorBarAttribute { 24 // background模式背景条 25 public static readonly BACKGROUNDBAR: IndicatorBarAttribute = 26 new IndicatorBarAttribute(backgroundBar, SizeMode.Padding, 20, 10, 0, 1, VerticalAlign.Center); 27 // thinstrip模式背景条 28 public static readonly THINSTRIP: IndicatorBarAttribute = 29 new IndicatorBarAttribute(thinStrip, SizeMode.Normal, 0, CommonConstants.THINSTRIP_INDICATOR_HEIGHT, 0, 1, 30 VerticalAlign.Bottom); 31 // 自定义背景条组件 32 private innerIndicatorBar: (index: BaseInterface) => void; 33 // 尺寸模式 34 private innerSizeMode: SizeMode; 35 // 1. 尺寸模式为正常模式,表示背景条宽度,值为0时与页签宽度保持一致 36 // 2. 尺寸模式为内边距模式,表示背景条与页签项之间的左右边距 37 private innerWidth: number; 38 // 1. 尺寸模式为正常模式,表示背景条高度,值为0时与页签高度保持一致 39 // 2. 尺寸模式为内边距模式,表示背景条与页签项之间的上下边距 40 private innerHeight: number 41 // 背景条最大偏移(<0: 无上限, >=0: innerMaxIndicatorBarLeft) 42 private innerMaxIndicatorBarLeft: number; 43 // 背景条宽度扩展比例 44 private innerIndicatorExpand: number; 45 // 背景条垂直布局 46 private innerBarAlign: VerticalAlign; 47 48 constructor(indicatorBar: (index: BaseInterface) => void, sizeMode: SizeMode = SizeMode.Normal, 49 indicatorWidth: number = 0, indicatorHeight: number = 0, maxIndicatorBarLeft: number = -1, 50 indicatorExpand: number = 1, barAlign: VerticalAlign = VerticalAlign.Center) { 51 this.innerIndicatorBar = indicatorBar; 52 this.innerSizeMode = sizeMode; 53 this.innerWidth = indicatorWidth; 54 this.innerHeight = indicatorHeight; 55 this.innerBarAlign = barAlign; 56 this.innerIndicatorExpand = indicatorExpand; 57 this.innerMaxIndicatorBarLeft = maxIndicatorBarLeft; 58 } 59 60 get indicatorBar(): (index: BaseInterface) => void { 61 return this.innerIndicatorBar; 62 } 63 64 set maxIndicatorBarLeft(left: number) { 65 this.innerMaxIndicatorBarLeft = left; 66 } 67 68 get maxIndicatorBarLeft(): number { 69 return this.innerMaxIndicatorBarLeft; 70 } 71 72 get barAlign(): VerticalAlign { 73 return this.innerBarAlign; 74 } 75 76 get indicatorExpand(): number { 77 return this.innerIndicatorExpand; 78 } 79 80 get sizeMode(): SizeMode { 81 return this.innerSizeMode; 82 } 83 84 get indicatorWidth(): number { 85 return this.innerWidth; 86 } 87 88 get indicatorHeight(): number { 89 return this.innerHeight; 90 } 91} 92 93@Builder 94function backgroundBar($$: BaseInterface) { 95 Column() 96 .height(CommonConstants.FULL_PERCENT) 97 .width(CommonConstants.FULL_PERCENT) 98 .backgroundColor(CommonConstants.BACKGROUND_INDICATOR_COLOR) 99 .borderRadius(CommonConstants.BACKGROUND_INDICATOR_BORDER_RADIUS) 100} 101 102@Builder 103function thinStrip($$: BaseInterface) { 104 Column() 105 .height(CommonConstants.FULL_PERCENT) 106 .width(CommonConstants.FORTY_PERCENT) 107 .backgroundColor(CommonConstants.THINSTRIP_INDICATOR_COLOR) 108 .borderRadius(CommonConstants.THINSTRIP_INDICATOR_BORDER_RADIUS) 109}