• 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@Entry
16@Component
17struct lineMetrics2 {
18  @State startIndexA: number = 0
19  @State endIndexA: number = 0
20  @State ascentA: number = 0
21  @State descentA: number = 0
22  @State heightA: number = 0
23  @State widthA: number = 0
24  @State leftA: number = 0
25  @State baselineA: number = 0
26  @State lineNumberA: number = 0
27  @State topHeightA: number = 0
28  @State flags: number = 0
29  @State text: string = '点击'
30  controller: TextController = new TextController()
31  @State textStr: string = 'qwertyu'
32
33  build(){
34    Column() {
35      Text(this.textStr, { controller: this.controller })
36      Text(this.startIndexA + '').id('LineMetrics_1')
37      Text(this.endIndexA + '').id('LineMetrics_2')
38      Text(this.topHeightA + '').id('LineMetrics_3')
39      Text(this.ascentA + '').id('LineMetrics_5')
40      Text(this.descentA + '').id('LineMetrics_6')
41      Button('getLineMetrics(1)')
42      .id('LineMetrics_4')
43      .onClick(() => {
44        let layoutManager: LayoutManager = this.controller.getLayoutManager()
45        let lineMetrics = layoutManager.getLineMetrics(0)
46        lineMetrics.startIndex = 1
47        this.startIndexA = Math.round(lineMetrics.startIndex)
48        lineMetrics.endIndex = 7
49        this.endIndexA = Math.round(lineMetrics.endIndex)
50        lineMetrics.topHeight = 10
51        this.topHeightA = Math.round(lineMetrics.topHeight)
52        lineMetrics.ascent = 5
53        this.ascentA = Math.round(lineMetrics.ascent)
54        lineMetrics.descent = 6
55        this.descentA = Math.round(lineMetrics.descent)
56        console.log('aaa_1',JSON.stringify(lineMetrics))
57      })
58    }
59    .width('100%')
60    .height('100%')
61  }
62}