Skip to content

Commit

Permalink
Demonstrate how to display UI components on top of a SurfaceView.
Browse files Browse the repository at this point in the history
  • Loading branch information
jinleili committed Nov 6, 2024
1 parent 3289571 commit f3c7acb
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 22 deletions.
66 changes: 46 additions & 20 deletions Android/app/src/main/java/name/jinleili/wgpu/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,52 @@ fun SurfaceCard() {
) {
Text(text = "wgpu in Android App", fontSize = 20.sp, fontWeight = FontWeight.Bold)
}
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center,
modifier = Modifier
.height(54.dp)
.padding(horizontal = 0.dp, vertical = 9.dp)
.fillMaxWidth()
) {
// Row(
// verticalAlignment = Alignment.CenterVertically,
// horizontalArrangement = Arrangement.Center,
// modifier = Modifier
// .height(54.dp)
// .padding(horizontal = 0.dp, vertical = 9.dp)
// .fillMaxWidth()
// ) {

// ToggleButton(
// currentSelection = selected,
// toggleStates = toggleValues,
// onToggleChange = { title ->
// selected = title
// toggleValues.forEachIndexed { idx, v ->
// if (v == title) {
// surfaceView?.changeExample(idx)
// }
// }
// },
// )
//
// }
// Spacer(modifier = Modifier.height(8.dp))
// AndroidView(
// factory = { ctx ->
// val sv = WGPUSurfaceView(context = ctx)
// surfaceView = sv
// sv
// },
// modifier = Modifier
// .fillMaxWidth()
// .height(screenWidth),
// )
// }
Box(modifier = Modifier.fillMaxSize()) {
AndroidView(
factory = { ctx ->
val sv = WGPUSurfaceView(context = ctx)
surfaceView = sv
sv
},
modifier = Modifier
.fillMaxWidth()
.height(screenWidth),
)
ToggleButton(
currentSelection = selected,
toggleStates = toggleValues,
Expand All @@ -73,18 +111,6 @@ fun SurfaceCard() {
}
},
)

}
Spacer(modifier = Modifier.height(8.dp))
AndroidView(
factory = { ctx ->
val sv = WGPUSurfaceView(context = ctx)
surfaceView = sv
sv
},
modifier = Modifier
.fillMaxWidth()
.height(screenWidth),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ class WGPUSurfaceView : SurfaceView, SurfaceHolder.Callback2 {
holder.addCallback(this)
// The only way to set SurfaceView background color to transparent:
// https://groups.google.com/g/android-developers/c/jYjvm7ItpXQ?pli=1
this.setZOrderOnTop(true)
// this.setZOrderOnTop(true)

// 让系统 ui 能覆盖在 SurfaceView 之上
this.setZOrderMediaOverlay(true)
holder.setFormat(PixelFormat.TRANSPARENT)
}

Expand Down
2 changes: 1 addition & 1 deletion cargo-so/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ authors = ["jinleili"]
description = "Helps cargo build Android .so lib files"
repository = "https://github.com/jinleili/wgpu-in-app"
readme = "./README.MD"
keywords = ["android", "so", "ndk", "jni", "cargo", "wgpu"]
keywords = ["android", "so", "ndk", "jni", "cargo"]
license = "MIT OR Apache-2.0"
edition = "2021"
version = "0.3.0"
Expand Down

0 comments on commit f3c7acb

Please sign in to comment.