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/// <reference path='./import.ts' /> 17class ArkGaugeComponent extends ArkComponent implements GaugeAttribute { 18 constructor(nativePtr: KNode) { 19 super(nativePtr); 20 } 21 value(value: number): this { 22 modifierWithKey(this._modifiersWithKeys, GaugeVauleModifier.identity, GaugeVauleModifier, value); 23 return this; 24 } 25 startAngle(angle: number): this { 26 modifierWithKey(this._modifiersWithKeys, GaugeStartAngleModifier.identity, GaugeStartAngleModifier, angle); 27 return this; 28 } 29 endAngle(angle: number): this { 30 modifierWithKey(this._modifiersWithKeys, GaugeEndAngleModifier.identity, GaugeEndAngleModifier, angle); 31 return this; 32 } 33 colors(colors: ResourceColor | LinearGradient | Array<[ResourceColor | LinearGradient, number]>): this { 34 modifierWithKey(this._modifiersWithKeys, GaugeColorsModifier.identity, GaugeColorsModifier, colors); 35 return this; 36 } 37 strokeWidth(length: any): this { 38 modifierWithKey(this._modifiersWithKeys, GaugeStrokeWidthModifier.identity, GaugeStrokeWidthModifier, length); 39 return this; 40 } 41 description(value: CustomBuilder): this { 42 throw new Error('Method not implemented.'); 43 } 44 trackShadow(value: GaugeShadowOptions): this { 45 modifierWithKey(this._modifiersWithKeys, GaugeTrackShadowModifier.identity, GaugeTrackShadowModifier, value); 46 return this; 47 } 48 indicator(value: GaugeIndicatorOptions): this { 49 modifierWithKey(this._modifiersWithKeys, GaugeIndicatorModifier.identity, GaugeIndicatorModifier, value); 50 return this; 51 } 52} 53 54class GaugeIndicatorModifier extends ModifierWithKey<GaugeIndicatorOptions> { 55 static identity: Symbol = Symbol('gaugeIndicator'); 56 applyPeer(node: KNode, reset: boolean): void { 57 if (reset) { 58 getUINativeModule().gauge.resetGaugeIndicator(node, this.value); 59 } else { 60 getUINativeModule().gauge.setGaugeIndicator(node, this.value.icon, this.value.space); 61 } 62 } 63 64 checkObjectDiff(): boolean { 65 return !isBaseOrResourceEqual(this.stageValue.icon, this.value.icon) || 66 !isBaseOrResourceEqual(this.stageValue.space, this.value.space); 67 } 68} 69 70class GaugeColorsModifier extends ModifierWithKey<ResourceColor | LinearGradient | Array<[ResourceColor | LinearGradient, number]>> { 71 static identity = Symbol('gaugeColors'); 72 applyPeer(node: KNode, reset: boolean): void { 73 if (reset) { 74 getUINativeModule().gauge.resetGaugeColors(node); 75 } else { 76 getUINativeModule().gauge.setGaugeColors(node, this.value!); 77 } 78 } 79 checkObjectDiff(): boolean { 80 return true; 81 } 82} 83 84class GaugeVauleModifier extends ModifierWithKey<number> { 85 static identity: Symbol = Symbol('gaugeVaule'); 86 applyPeer(node: KNode, reset: boolean): void { 87 if (reset) { 88 getUINativeModule().gauge.resetGaugeVaule(node); 89 } else { 90 getUINativeModule().gauge.setGaugeVaule(node, this.value); 91 } 92 } 93 94 checkObjectDiff(): boolean { 95 return !isBaseOrResourceEqual(this.stageValue, this.value); 96 } 97} 98 99class GaugeStartAngleModifier extends ModifierWithKey<number> { 100 static identity: Symbol = Symbol('gaugeStartAngle'); 101 applyPeer(node: KNode, reset: boolean): void { 102 if (reset) { 103 getUINativeModule().gauge.resetGaugeStartAngle(node); 104 } else { 105 getUINativeModule().gauge.setGaugeStartAngle(node, this.value); 106 } 107 } 108 109 checkObjectDiff(): boolean { 110 return !isBaseOrResourceEqual(this.stageValue, this.value); 111 } 112} 113 114class GaugeEndAngleModifier extends ModifierWithKey<number> { 115 static identity: Symbol = Symbol('gaugeEndAngle'); 116 applyPeer(node: KNode, reset: boolean): void { 117 if (reset) { 118 getUINativeModule().gauge.resetGaugeEndAngle(node); 119 } else { 120 getUINativeModule().gauge.setGaugeEndAngle(node, this.value); 121 } 122 } 123 124 checkObjectDiff(): boolean { 125 return !isBaseOrResourceEqual(this.stageValue, this.value); 126 } 127} 128 129class GaugeStrokeWidthModifier extends ModifierWithKey<Length> { 130 static identity: Symbol = Symbol('gaugeStrokeWidth'); 131 applyPeer(node: KNode, reset: boolean): void { 132 if (reset) { 133 getUINativeModule().gauge.resetGaugeStrokeWidth(node); 134 } else { 135 getUINativeModule().gauge.setGaugeStrokeWidth(node, this.value); 136 } 137 } 138 139 checkObjectDiff(): boolean { 140 return !isBaseOrResourceEqual(this.stageValue, this.value); 141 } 142} 143 144class GaugeTrackShadowModifier extends ModifierWithKey<GaugeShadowOptions> { 145 static identity: Symbol = Symbol('gaugeTrackShadow'); 146 applyPeer(node: KNode, reset: boolean): void { 147 if (reset) { 148 getUINativeModule().gauge.resetGaugeTrackShadow(node); 149 } else { 150 getUINativeModule().gauge.setGaugeTrackShadow(node, this.value, this.value.radius, this.value.offsetX, this.value.offsetY); 151 } 152 } 153 154 checkObjectDiff(): boolean { 155 return !isBaseOrResourceEqual(this.stageValue, this.value); 156 } 157} 158 159// @ts-ignore 160globalThis.Gauge.attributeModifier = function (modifier) { 161 const elmtId = ViewStackProcessor.GetElmtIdToAccountFor(); 162 let nativeNode = getUINativeModule().getFrameNodeById(elmtId); 163 let component = this.createOrGetNode(elmtId, () => { 164 return new ArkGaugeComponent(nativeNode); 165 }); 166 applyUIAttributes(modifier, nativeNode, component); 167 component.applyModifierPatch(); 168}; 169