• 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.setSymbolId(node, '');
150      }
151      else {
152        getUINativeModule().symbolGlyph.setSymbolId(node, this.value);
153      }
154    }
155  }
156
157  class ArkSymbolGlyphComponent extends ArkComponent implements SymbolGlyphAttribute {
158    constructor(nativePtr: KNode, classType?: ModifierType) {
159      super(nativePtr, classType);
160    }
161    initialize(value: Object[]): SymbolGlyphAttribute {
162      if (value[0] !== undefined) {
163        modifierWithKey(this._modifiersWithKeys, SymbolContentModifier.identity, SymbolContentModifier, value[0]);
164      }
165      return this;
166    }
167    fontColor(value: object): SymbolGlyphAttribute {
168      modifierWithKey(this._modifiersWithKeys, SymbolFontColorModifier.identity, SymbolFontColorModifier, value);
169      return this;
170    }
171    fontSize(value: number | string | Resource): SymbolGlyphAttribute {
172      modifierWithKey(this._modifiersWithKeys, SymbolFontSizeModifier.identity, SymbolFontSizeModifier, value);
173      return this;
174    }
175    fontWeight(value: number | FontWeight | string): SymbolGlyphAttribute {
176      let fontWeightStr: string = '400';
177      if (isNumber(value)) {
178        fontWeightStr = value.toString();
179      } else if (isString(value)) {
180        fontWeightStr = String(value);
181      }
182      modifierWithKey(this._modifiersWithKeys, SymbolFontWeightModifier.identity, SymbolFontWeightModifier, fontWeightStr);
183      return this;
184    }
185    renderingStrategy(value: SymbolRenderingStrategy): SymbolGlyphAttribute {
186      modifierWithKey(this._modifiersWithKeys, RenderingStrategyModifier.identity, RenderingStrategyModifier, value);
187      return this;
188    }
189    effectStrategy(value: SymbolEffectStrategy): SymbolGlyphAttribute {
190      modifierWithKey(this._modifiersWithKeys, EffectStrategyModifier.identity, EffectStrategyModifier, value);
191      return this;
192    }
193    symbolEffect(effect: SymbolEffect, action?: boolean | number): SymbolGlyphAttribute {
194      let symbolEffect = new ArkSymbolEffect();
195      symbolEffect.symbolEffect = effect;
196      symbolEffect.action = action;
197      modifierWithKey(this._modifiersWithKeys, SymbolEffectModifier.identity, SymbolEffectModifier, symbolEffect);
198      return this;
199    }
200  }
201
202  // @ts-ignore
203  globalThis.SymbolGlyph.attributeModifier = function (modifier: ArkComponent): void {
204    attributeModifierFunc.call(this, modifier, (nativePtr: KNode) => {
205      return new ArkSymbolGlyphComponent(nativePtr);
206    }, (nativePtr: KNode, classType: ModifierType, modifierJS: ModifierJS) => {
207      return new modifierJS.SymbolGlyphModifier(undefined, nativePtr, classType);
208    });
209  };