• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024 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 SymbolFontColorModifier extends ModifierWithKey<object> {
18    constructor(value: object) {
19      super(value);
20    }
21    static identity: Symbol = Symbol('symbolGlyphFontColor');
22    applyPeer(node: KNode, reset: boolean): void {
23      if (reset) {
24        getUINativeModule().symbolGlyph.resetFontColor(node);
25      } else {
26        getUINativeModule().symbolGlyph.setFontColor(node, this.value);
27      }
28    }
29
30    checkObjectDiff(): boolean {
31      if (isResource(this.stageValue) && isResource(this.value)) {
32        let ret: boolean = !isResourceEqual(this.stageValue, this.value);
33        return ret;
34      } else {
35        return true;
36      }
37    }
38  }
39
40  class SymbolFontSizeModifier extends ModifierWithKey<number | string | Resource> {
41    constructor(value: number | string | Resource) {
42      super(value);
43    }
44    static identity: Symbol = Symbol('symbolGlyphFontSize');
45    applyPeer(node: KNode, reset: boolean): void {
46      if (reset) {
47        getUINativeModule().symbolGlyph.resetFontSize(node);
48      } else {
49        getUINativeModule().symbolGlyph.setFontSize(node, this.value);
50      }
51    }
52
53    checkObjectDiff(): boolean {
54      if (isResource(this.stageValue) && isResource(this.value)) {
55        return !isResourceEqual(this.stageValue, this.value);
56      } else {
57        return true;
58      }
59    }
60  }
61
62  class SymbolFontWeightModifier extends ModifierWithKey<number | FontWeight | string> {
63    constructor(value: number | FontWeight | string) {
64      super(value);
65    }
66    static identity: Symbol = Symbol('symbolGlyphFontWeight');
67    applyPeer(node: KNode, reset: boolean): void {
68      if (reset) {
69        getUINativeModule().symbolGlyph.resetFontWeight(node);
70      } else {
71        getUINativeModule().symbolGlyph.setFontWeight(node, this.value);
72      }
73    }
74
75    checkObjectDiff(): boolean {
76      if (isResource(this.stageValue) && isResource(this.value)) {
77        return !isResourceEqual(this.stageValue, this.value);
78      } else {
79        return true;
80      }
81    }
82  }
83
84  class RenderingStrategyModifier extends ModifierWithKey<SymbolRenderingStrategy> {
85    constructor(value: SymbolRenderingStrategy) {
86      super(value);
87    }
88    static identity: Symbol = Symbol('symbolGlyphRenderingStrategy');
89    applyPeer(node: KNode, reset: boolean): void {
90      if (reset) {
91        getUINativeModule().symbolGlyph.resetRenderingStrategy(node);
92      } else {
93        getUINativeModule().symbolGlyph.setRenderingStrategy(node, this.value);
94      }
95    }
96
97    checkObjectDiff(): boolean {
98      if (isResource(this.stageValue) && isResource(this.value)) {
99        return !isResourceEqual(this.stageValue, this.value);
100      } else {
101        return true;
102      }
103    }
104  }
105
106  class EffectStrategyModifier extends ModifierWithKey<SymbolEffectStrategy> {
107    constructor(value: SymbolEffectStrategy) {
108      super(value);
109    }
110    static identity: Symbol = Symbol('symbolGlyphEffectStrategy');
111    applyPeer(node: KNode, reset: boolean): void {
112      if (reset) {
113        getUINativeModule().symbolGlyph.resetEffectStrategy(node);
114      } else {
115        getUINativeModule().symbolGlyph.setEffectStrategy(node, this.value);
116      }
117    }
118
119    checkObjectDiff(): boolean {
120      if (isResource(this.stageValue) && isResource(this.value)) {
121        return !isResourceEqual(this.stageValue, this.value);
122      } else {
123        return true;
124      }
125    }
126  }
127
128  class SymbolEffectModifier extends ModifierWithKey<ArkSymbolEffect> {
129    constructor(value: ArkSymbolEffect) {
130      super(value);
131    }
132    static identity: Symbol = Symbol('symbolGlyphSymbolEffect');
133    applyPeer(node: KNode, reset: boolean): void {
134      if (reset) {
135        getUINativeModule().symbolGlyph.resetSymbolEffectOptions(node);
136      } else {
137        getUINativeModule().symbolGlyph.setSymbolEffectOptions(node, this.value.symbolEffect, this.value.action);
138      }
139    }
140  }
141
142  class SymbolContentModifier extends ModifierWithKey<Resource> {
143    constructor(value: Resource) {
144      super(value);
145    }
146    static identity: Symbol = Symbol('symbolContent');
147    applyPeer(node: KNode, reset: boolean): void {
148      if (reset) {
149        getUINativeModule().symbolGlyph.resetSymbolGlyphInitialize(node);
150      } else {
151        getUINativeModule().symbolGlyph.setSymbolGlyphInitialize(node, this.value);
152      }
153    }
154  }
155
156  class ArkSymbolGlyphComponent extends ArkComponent implements SymbolGlyphAttribute {
157    constructor(nativePtr: KNode, classType?: ModifierType) {
158      super(nativePtr, classType);
159    }
160    initialize(value: Object[]): this {
161      if (value[0] !== undefined) {
162        modifierWithKey(this._modifiersWithKeys, SymbolContentModifier.identity, SymbolContentModifier, value[0]);
163      } else {
164        modifierWithKey(this._modifiersWithKeys, SymbolContentModifier.identity, SymbolContentModifier, undefined);
165      }
166      return this;
167    }
168    fontColor(value: object): SymbolGlyphAttribute {
169      modifierWithKey(this._modifiersWithKeys, SymbolFontColorModifier.identity, SymbolFontColorModifier, value);
170      return this;
171    }
172    fontSize(value: number | string | Resource): SymbolGlyphAttribute {
173      modifierWithKey(this._modifiersWithKeys, SymbolFontSizeModifier.identity, SymbolFontSizeModifier, value);
174      return this;
175    }
176    fontWeight(value: number | FontWeight | string): SymbolGlyphAttribute {
177      let fontWeightStr: string = '400';
178      if (isNumber(value)) {
179        fontWeightStr = value.toString();
180      } else if (isString(value)) {
181        fontWeightStr = String(value);
182      }
183      modifierWithKey(this._modifiersWithKeys, SymbolFontWeightModifier.identity, SymbolFontWeightModifier, fontWeightStr);
184      return this;
185    }
186    renderingStrategy(value: SymbolRenderingStrategy): SymbolGlyphAttribute {
187      modifierWithKey(this._modifiersWithKeys, RenderingStrategyModifier.identity, RenderingStrategyModifier, value);
188      return this;
189    }
190    effectStrategy(value: SymbolEffectStrategy): SymbolGlyphAttribute {
191      modifierWithKey(this._modifiersWithKeys, EffectStrategyModifier.identity, EffectStrategyModifier, value);
192      return this;
193    }
194    symbolEffect(effect: SymbolEffect, action?: boolean | number): SymbolGlyphAttribute {
195      let symbolEffect = new ArkSymbolEffect();
196      symbolEffect.symbolEffect = effect;
197      symbolEffect.action = action;
198      modifierWithKey(this._modifiersWithKeys, SymbolEffectModifier.identity, SymbolEffectModifier, symbolEffect);
199      return this;
200    }
201  }
202
203  // @ts-ignore
204  globalThis.SymbolGlyph.attributeModifier = function (modifier: ArkComponent): void {
205    attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => {
206      return new ArkSymbolGlyphComponent(nativePtr);
207    }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => {
208      return new modifierJS.SymbolGlyphModifier(undefined, nativePtr, classType);
209    });
210  };