forked from MeloNX/MeloNX
Fix of stretch aspect ratio
This commit is contained in:
parent
a8994d8b50
commit
eb010fa380
@ -17,11 +17,10 @@ struct MetalViewContainer: View {
|
||||
GeometryReader { geo in
|
||||
ZStack {
|
||||
if shouldStretchToFillScreen {
|
||||
stretchedView
|
||||
Color.black
|
||||
stretchedView(containerSize: geo.size)
|
||||
} else if oldView {
|
||||
Color.black.edgesIgnoringSafeArea(.all)
|
||||
|
||||
|
||||
Color.black
|
||||
oldStyleView(containerSize: geo.size)
|
||||
} else {
|
||||
modernView(containerSize: geo.size)
|
||||
@ -30,15 +29,16 @@ struct MetalViewContainer: View {
|
||||
.animation(.easeInOut(duration: 0.3), value: ryujinx.aspectRatio)
|
||||
.animation(.easeInOut(duration: 0.3), value: oldView)
|
||||
}
|
||||
.ignoresSafeArea()
|
||||
}
|
||||
|
||||
// MARK: - View Components
|
||||
|
||||
private var stretchedView: some View {
|
||||
MetalView()
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
.aspectRatio(contentMode: .fill)
|
||||
.edgesIgnoringSafeArea(.all)
|
||||
private func stretchedView(containerSize: CGSize) -> some View {
|
||||
let size = targetSize(for: containerSize, ignoreSafeArea: true)
|
||||
|
||||
return MetalView()
|
||||
.frame(width: size.width, height: size.height)
|
||||
}
|
||||
|
||||
private func oldStyleView(containerSize: CGSize) -> some View {
|
||||
@ -114,7 +114,7 @@ struct MetalViewContainer: View {
|
||||
return isPortrait ? baseScale : baseScale * 0.92
|
||||
}
|
||||
|
||||
private func targetSize(for containerSize: CGSize) -> CGSize {
|
||||
private func targetSize(for containerSize: CGSize, ignoreSafeArea: Bool = false) -> CGSize {
|
||||
let targetAspect: CGFloat = {
|
||||
switch ryujinx.aspectRatio {
|
||||
case .fixed4x3: return 4.0 / 3.0
|
||||
@ -122,20 +122,16 @@ struct MetalViewContainer: View {
|
||||
case .fixed16x10: return 16.0 / 10.0
|
||||
case .fixed21x9: return 21.0 / 9.0
|
||||
case .fixed32x9: return 32.0 / 10.0
|
||||
case .stretched: return containerSize.width / containerSize.height
|
||||
case .stretched: return 16.0 / 9.0
|
||||
}
|
||||
}()
|
||||
|
||||
let safeArea = UIApplication.shared.windows.first?.safeAreaInsets ?? .zero
|
||||
let safeArea: UIEdgeInsets = ignoreSafeArea ? .zero : UIApplication.shared.windows.first?.safeAreaInsets ?? .zero
|
||||
let adjustedContainer = CGSize(
|
||||
width: containerSize.width - safeArea.left - safeArea.right,
|
||||
height: containerSize.height - safeArea.top - safeArea.bottom
|
||||
)
|
||||
|
||||
if ryujinx.aspectRatio == .stretched {
|
||||
return adjustedContainer
|
||||
}
|
||||
|
||||
let containerAspect = adjustedContainer.width / adjustedContainer.height
|
||||
|
||||
if containerAspect > targetAspect {
|
||||
|
Loading…
x
Reference in New Issue
Block a user