Skip to content

Commit

Permalink
Update example code
Browse files Browse the repository at this point in the history
  • Loading branch information
richerfu committed Feb 12, 2025
1 parent 3438fa6 commit e58663b
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 16 deletions.
19 changes: 13 additions & 6 deletions OpenHarmony/entry/oh-package-lock.json5

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion OpenHarmony/entry/oh-package.json5
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"license": "",
"dependencies": {
"libentry.so": "file:./src/main/cpp/types/libentry",
"@ohos-rs/ability": "^0.0.1"
"libwgpu_in_app.so": "file:./src/main/cpp/types/libwgpu_in_app",
"@ohos-rs/ability": "^0.0.2"
},
"devDependencies": {},
"dynamicDependencies": {}
Expand Down
25 changes: 25 additions & 0 deletions OpenHarmony/entry/src/main/cpp/types/libwgpu_in_app/Index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* auto-generated by OHOS-RS */
/* eslint-disable */
import { NodeContent } from "@kit.ArkUI"

export interface ApplicationLifecycle {
environmentCallback: EnvironmentCallback
windowStageEventCallback: WindowStageEventCallback
}

export interface EnvironmentCallback {
onConfigurationUpdated: () => void
onMemoryLevel: () => void
}

export interface WindowStageEventCallback {
onWindowStageCreate: () => void
onWindowStageDestroy: () => void
onAbilityCreate: () => void
onAbilityDestroy: () => void
onAbilitySaveState: () => void
}

export declare function init(slot: NodeContent): ApplicationLifecycle;

export declare function changeRender(index: number): void
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "libwgpu_in_app.so",
"types": "./Index.d.ts",
"version": "1.0.0",
"description": "Please describe the basic information."
}
7 changes: 7 additions & 0 deletions OpenHarmony/entry/src/main/ets/entryability/EntryAbility.ets
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import { RustAbility } from '@ohos-rs/ability'
import Want from '@ohos.app.ability.Want'
import { AbilityConstant } from '@kit.AbilityKit';
import window from '@ohos.window';

export default class EntryAbility extends RustAbility {
public moduleName: string = "wgpu_in_app"
public defaultPage: boolean = false;

async onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): Promise<void> {
super.onCreate(want, launchParam);
}

async onWindowStageCreate(windowStage: window.WindowStage): Promise<void> {
super.onWindowStageCreate(windowStage);
await windowStage.loadContent('pages/Index');
}
}
27 changes: 18 additions & 9 deletions OpenHarmony/entry/src/main/ets/pages/Index.ets
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
import { hilog } from '@kit.PerformanceAnalysisKit';
import testNapi from 'libentry.so';
import { DefaultXComponent } from "@ohos-rs/ability"
import { ItemRestriction, SegmentButton, SegmentButtonOptions, SegmentButtonTextItem } from '@kit.ArkUI';
import { changeRender } from "libwgpu_in_app.so"

@Entry
@Component
struct Index {
@State message: string = 'Hello World';
@State tabOptions: SegmentButtonOptions = SegmentButtonOptions.capsule({
buttons: [{ text: 'boids' },
{ text: 'MSAA line' },
{ text: 'cube' },
{ text: "water" },
{ text: "shadow" }] as ItemRestriction<SegmentButtonTextItem>,
backgroundBlurStyle: BlurStyle.BACKGROUND_THICK,
})
@State @Watch("handleChange") tabSelectedIndexes: number[] = [0]

handleChange() {
changeRender(this.tabSelectedIndexes[0])
}

build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
.onClick(() => {
hilog.info(0x0000, 'testTag', 'Test NAPI 2 + 3 = %{public}d', testNapi.add(2, 3));
})
SegmentButton({ options: this.tabOptions, selectedIndexes: $tabSelectedIndexes })
DefaultXComponent()
}
.width('100%')
}
Expand Down

0 comments on commit e58663b

Please sign in to comment.