提交 f02ac81e 编写于 作者: W wang-xupeng2 提交者: 王旭鹏
上级 497ac09c
...@@ -12,25 +12,60 @@ ...@@ -12,25 +12,60 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import componentUtils from '@ohos.componentUtils';
@Entry @Entry
@Component @Component
struct getcomponent { struct getcomponent {
@State message: string = 'Hello World' @State message: string = 'Hello World'
getcomponentRect(key){
let modePosition = componentUtils.getRectangleById(key)
let widthSize = modePosition.size.width
let heightSize = modePosition.size.height
let localOffsetX = modePosition.localOffset.x
let localOffsetY = modePosition.localOffset.y
let windowOffsetX = modePosition.windowOffset.x
let windowOffsetY = modePosition.windowOffset.y
let screenOffsetX = modePosition.screenOffset.x
let screenOffsetY = modePosition.screenOffset.y
let Matrix4Result1 = modePosition.transform
return {
"sizeWidth": widthSize,
"sizeHeight": heightSize,
"localOffsetX": localOffsetX,
"localOffsetY": localOffsetY,
"windowOffsetX": windowOffsetX,
"windowOffsetY": windowOffsetY,
"screenOffsetX": screenOffsetX,
"screenOffsetY": screenOffsetY,
"Matrix4Result1": Matrix4Result1
}
}
build() { build() {
Column() { Column() {
Button() { Button('next page')
Text('next page') .size({ width: 90, height: 90 })
.fontSize(20)
.fontWeight(FontWeight.Bold) .fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule) .id('ArkUX_Get_component_0010')
.key('ArkUX_Get_component_0010')
.margin({ .margin({
top: 20 top: 20
}) })
.backgroundColor('#0D9FFB') .backgroundColor('#0D9FFB')
.width('50%')
.height('50%') Button("返回值").margin(30)
}.width(200).height(200) .onClick(()=>{
let Rectangle = this.getcomponentRect("ArkUX_Get_component_0010")
this.message = "sizeWidth: " + Rectangle.sizeWidth + "\n sizeHeight: " + Rectangle.sizeHeight
+ "\n localOffsetX: " + Rectangle.localOffsetX + "\n localOffsetY: " + Rectangle.localOffsetY
+ "\n windowOffsetX: " + Rectangle.windowOffsetX + "\n windowOffsetY: " + Rectangle.windowOffsetY
+ "\n screenOffsetX: " + Rectangle.screenOffsetX + "\n screenOffsetY: " + Rectangle.screenOffsetY
+ "\n Matrix4Result: " + Rectangle.Matrix4Result1.toString()
})
Text(this.message).fontSize(25).padding(15).fontWeight(FontWeight.Bold).margin(10)
}.width("100%").height("100%")
} }
} }
\ No newline at end of file
...@@ -58,14 +58,26 @@ export default function ActsgetcomponentTest() { ...@@ -58,14 +58,26 @@ export default function ActsgetcomponentTest() {
console.info('ArkUX_Get_component_0010 START'); console.info('ArkUX_Get_component_0010 START');
setTimeout(()=>{ setTimeout(()=>{
try{ try{
let strJson = Utils.getComponentRect('ArkUX_Get_component_0010'); let strJson = getInspectorByKey('ArkUX_Get_component_0010');
expect(parseInt(strJson.width)).assertEqual(vp2px(100)); let obj = JSON.parse(strJson);
expect(parseInt(strJson.height)).assertEqual(vp2px(100)); console.info('ArkUX_Get_component_0010 width: '+ JSON.stringify(obj.width));
expect(parseInt(strJson.localOffsetY)).assertEqual(30); console.info('ArkUX_Get_component_0010 height: '+ JSON.stringify(obj.height));
expect(parseInt(strJson.windowOffsetX)).assertEqual(234); console.info('ArkUX_Get_component_0010 localOffsetX: '+ JSON.stringify(obj.localOffsetX));
expect(parseInt(strJson.windowOffsetY)).assertEqual(102); console.info('ArkUX_Get_component_0010 localOffsetY: '+ JSON.stringify(obj.localOffsetY));
expect(parseInt(strJson.screenOffsetX)).assertEqual(234); console.info('ArkUX_Get_component_0010 windowOffsetX: '+ JSON.stringify(obj.windowOffsetX));
expect(parseInt(strJson.screenOffsetY)).assertEqual(234); console.info('ArkUX_Get_component_0010 windowOffsetY: '+ JSON.stringify(obj.windowOffsetY));
console.info('ArkUX_Get_component_0010 screenOffsetX: '+ JSON.stringify(obj.screenOffsetX));
console.info('ArkUX_Get_component_0010 screenOffsetY: '+ JSON.stringify(obj.screenOffsetY));
console.info('ArkUX_Get_component_0010 transform: '+ JSON.stringify(obj.transform));
expect(parseInt(obj.width)).assertEqual(vp2px(90));
expect(parseInt(obj.height)).assertEqual(vp2px(90));
expect(parseInt(obj.localOffsetX)).assertEqual(293);
expect(parseInt(obj.localOffsetY)).assertEqual(30);
expect(parseInt(obj.windowOffsetX)).assertEqual(293);
expect(parseInt(obj.windowOffsetY)).assertEqual(102);
expect(parseInt(obj.screenOffsetX)).assertEqual(293);
expect(parseInt(obj.screenOffsetY)).assertEqual(102);
expect(obj.transform).assertEqual('[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]');
console.info('ArkUX_Get_component_0010 END '); console.info('ArkUX_Get_component_0010 END ');
} catch(err) { } catch(err) {
expect().assertFail() expect().assertFail()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册