mirror of
https://git.ryujinx.app/kenji-nx/ryujinx.git
synced 2025-12-17 16:37:04 +00:00
Merge branch 'libryujinx_bionic_tablet-foldables' into 'libryujinx_bionic'
Fixed Gamescreen for Tablets and Foldables See merge request kenji-nx/ryujinx!16
This commit is contained in:
commit
7c84187e46
1 changed files with 68 additions and 7 deletions
|
|
@ -48,6 +48,15 @@ import org.kenjinx.android.viewmodels.VSyncMode
|
||||||
import org.kenjinx.android.widgets.SimpleAlertDialog
|
import org.kenjinx.android.widgets.SimpleAlertDialog
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
import android.net.Uri
|
||||||
|
import android.widget.Toast
|
||||||
|
import androidx.compose.foundation.layout.aspectRatio
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.fillMaxHeight
|
||||||
|
import androidx.compose.foundation.layout.BoxWithConstraints
|
||||||
|
import androidx.compose.ui.platform.LocalConfiguration
|
||||||
|
import org.kenjinx.android.viewmodels.QuickSettings.VirtualControllerPreset
|
||||||
|
|
||||||
|
|
||||||
class GameViews {
|
class GameViews {
|
||||||
companion object {
|
companion object {
|
||||||
|
|
@ -55,7 +64,7 @@ class GameViews {
|
||||||
fun Main() {
|
fun Main() {
|
||||||
Surface(
|
Surface(
|
||||||
modifier = Modifier.fillMaxSize(),
|
modifier = Modifier.fillMaxSize(),
|
||||||
color = MaterialTheme.colorScheme.background
|
color = Color.Black
|
||||||
) {
|
) {
|
||||||
GameView(mainViewModel = MainActivity.mainViewModel!!)
|
GameView(mainViewModel = MainActivity.mainViewModel!!)
|
||||||
}
|
}
|
||||||
|
|
@ -63,16 +72,68 @@ class GameViews {
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun GameView(mainViewModel: MainViewModel) {
|
fun GameView(mainViewModel: MainViewModel) {
|
||||||
Box(modifier = Modifier.fillMaxSize()) {
|
val cfg = LocalConfiguration.current
|
||||||
AndroidView(
|
val isLandscape = cfg.screenWidthDp >= cfg.screenHeightDp
|
||||||
|
val isLarge = (cfg.smallestScreenWidthDp >= 600) || (cfg.screenWidthDp >= 900)
|
||||||
|
|
||||||
|
// Setting from preferences (read at game start)
|
||||||
|
val stretch = QuickSettings(mainViewModel.activity).stretchToFullscreen
|
||||||
|
|
||||||
|
// Default aspect ratio (Switch 16:9). If you later want to read dynamically from the renderer,
|
||||||
|
// you can update gameAspect here at runtime.
|
||||||
|
val gameAspect = 16f / 9f
|
||||||
|
|
||||||
|
if (stretch) {
|
||||||
|
// Stretch to full screen (no letterbox), anchored to the top
|
||||||
|
Box(
|
||||||
modifier = Modifier.fillMaxSize(),
|
modifier = Modifier.fillMaxSize(),
|
||||||
factory = { context ->
|
contentAlignment = Alignment.TopCenter
|
||||||
GameHost(context, mainViewModel)
|
) {
|
||||||
|
AndroidView(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.align(Alignment.TopCenter),
|
||||||
|
factory = { context -> GameHost(context, mainViewModel) }
|
||||||
|
)
|
||||||
|
GameOverlay(mainViewModel)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// Keep letterbox but pin to the top. Phones: smart-fit,
|
||||||
|
// Tablets/Foldables in landscape: enforce fitWidth (as desired).
|
||||||
|
BoxWithConstraints(modifier = Modifier.fillMaxSize()) {
|
||||||
|
val containerAspect = maxWidth.value / maxHeight.value
|
||||||
|
|
||||||
|
val useFitWidth =
|
||||||
|
if (isLandscape && isLarge) true
|
||||||
|
else containerAspect < gameAspect
|
||||||
|
|
||||||
|
val fitModifier =
|
||||||
|
if (useFitWidth) {
|
||||||
|
Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.aspectRatio(gameAspect)
|
||||||
|
.align(Alignment.TopCenter)
|
||||||
|
} else {
|
||||||
|
Modifier
|
||||||
|
.fillMaxHeight()
|
||||||
|
.aspectRatio(gameAspect)
|
||||||
|
.align(Alignment.TopCenter)
|
||||||
|
}
|
||||||
|
|
||||||
|
Box(
|
||||||
|
modifier = Modifier.fillMaxSize(),
|
||||||
|
contentAlignment = Alignment.TopCenter
|
||||||
|
) {
|
||||||
|
AndroidView(
|
||||||
|
modifier = fitModifier,
|
||||||
|
factory = { context -> GameHost(context, mainViewModel) }
|
||||||
)
|
)
|
||||||
GameOverlay(mainViewModel)
|
GameOverlay(mainViewModel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue