Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.
Swift apple-siliconcustom-formathomebrewiosipaipadipadosiphonemetalnative-portnintendo-switchnxnativeromfsswitch-games
iOS shell: settings as the Controllers overlay, state dots on the covers
v0lumehi929b914e10db
diff --git a/frontend-ios/Sources/ShellUI/CoverFlowView.swift b/frontend-ios/Sources/ShellUI/CoverFlowView.swiftindex 7aff8359..c5ee02cc 100644--- a/frontend-ios/Sources/ShellUI/CoverFlowView.swift+++ b/frontend-ios/Sources/ShellUI/CoverFlowView.swift@@ -185,7 +185,7 @@ struct CoverFlowView: View, Equatable {withAnimation(reduceMotion ? nil : .smooth(duration: 0.3)) { centredID = detail.id }select(detail.id)} label: {- CoverView(game: detail.game, radius: cover * 0.03)+ CoverView(game: detail.game, radius: cover * 0.03, showsState: true).frame(width: cover, height: cover * 9 / 16).shadow(color: .black.opacity(0.5), radius: cover * 0.05, y: cover * 0.03)}@@ -220,10 +220,12 @@ struct CoverFlowView: View, Equatable {.lineLimit(2).truncationMode(.tail).multilineTextAlignment(.center).shadow(color: .black.opacity(0.35), radius: 10).accessibilityAddTraits(.isHeader).accessibilityIdentifier("hero.title")+ // A ready game needs no words: its green dot says it. A game that cannot start gets one small line, its+ // way out in the state's colour. The space is reserved either way.if game.state == .playable {- StatusLabel(state: game.state, prominent: true).frame(minHeight: 34)+ Color.clear.frame(height: 34).accessibilityHidden(true)} else {- StateChip(game: game) { primary(selected) }+ StateAction(game: game) { primary(selected) }}}.id(game.id).transition(.opacity)@@ -244,6 +246,29 @@ struct CoverFlowView: View, Equatable {}}+/// The way out for a game that cannot start, as one small tappable line in the state's colour: "How to fix ›".+/// VoiceOver reads the state with it.+struct StateAction: View {+ let game: GameTile+ let action: () -> Void+ var body: some View {+ Button(action: action) {+ HStack(spacing: 5) {+ Text(game.state.actionTitle).shellType(ShellType.button)+ Image(systemName: "chevron.right").font(.system(size: 11, weight: .bold))+ }+ .foregroundStyle(game.state.color)+ .lineLimit(1)+ .padding(.horizontal, 12).frame(minHeight: 34)+ .contentShape(Rectangle())+ }+ .buttonStyle(.plain)+ .accessibilityLabel(game.state.title + ", " + game.state.actionTitle)+ .accessibilityIdentifier("state.chip")+ .shellTarget("lib.chip", radius: 17, action: action)+ }+}+/// What is wrong and what to do, as one small tappable line: "Game files damaged · How to fix".struct StateChip: View {let game: GameTilediff --git a/frontend-ios/Sources/ShellUI/LibraryView.swift b/frontend-ios/Sources/ShellUI/LibraryView.swiftindex 380ffbc0..ee46343f 100644--- a/frontend-ios/Sources/ShellUI/LibraryView.swift+++ b/frontend-ios/Sources/ShellUI/LibraryView.swift@@ -16,16 +16,13 @@ enum ShellLayout: Equatable {return regular && !accessibilityText ? .grid : .column}- /// The settings panel's width: the whole width where it covers the library, else a panel that leaves the- /// library in view beside it.- func paneWidth(_ width: CGFloat) -> CGFloat {- switch self {- case .column, .coverFlow(regular: false): width- case .grid, .coverFlow(regular: true): min(500, max(380, width * 0.5))- }- }- /// Whether the settings float as a panel over a dimmed library, rather than replacing it.- var settingsFloat: Bool { self == .grid || self == .coverFlow(regular: true) }+ /// The width of the overlay Settings and Controllers share: a panel from the trailing edge over the dimmed library.+ static let overlayWidth: CGFloat = 520+ /// Settings drop in as that overlay wherever the library stays in view beside it (at least 120 points of it), and+ /// take the whole screen where it would not: a phone held upright, a folded foldable, a narrow window.+ func settingsFloat(_ width: CGFloat) -> Bool { self != .column && width >= Self.overlayWidth + 120 }+ /// The settings' width: the overlay, or the whole width.+ func paneWidth(_ width: CGFloat) -> CGFloat { settingsFloat(width) ? min(width, Self.overlayWidth) : width }var isCoverFlow: Bool { if case .coverFlow = self { true } else { false } }}@@ -82,7 +79,7 @@ public struct LibraryView: View {let pane = layout.paneWidth(width)// Settings only when asked for. A panel floats over the dimmed library where there is room, otherwise the// settings take the whole screen and the library steps out of the way.- let floating = layout.settingsFloat+ let floating = layout.settingsFloat(width)let paneCovers = settingsOpen && !floatinglet panelOverLibrary = settingsOpen && floatingZStack(alignment: .topLeading) {@@ -100,30 +97,24 @@ public struct LibraryView: View {.accessibilityHidden(settingsOpen || helpGameID != nil).transformPreference(FocusTargets.self) { if settingsOpen { $0.removeAll() } }if panelOverLibrary {- Color.black.opacity(0.5).ignoresSafeArea()+ // The same dimming and dismissal as the Controllers overlay.+ Color.black.opacity(0.55).ignoresSafeArea().onTapGesture { closeSettings() }.accessibilityHidden(true).transition(.opacity)}// One settings view in one place for every layout, so its state, scroll position and focus survive// a fold, a rotation or a Stage Manager resize.- settingsPane(selected, floating: floating, width: pane - (floating ? 24 : 0),- insets: floating ? EdgeInsets() : insets)- .frame(width: pane - (floating ? 24 : 0))+ settingsPane(selected, floating: floating, width: pane,+ insets: floating ? EdgeInsets(top: insets.top, leading: 0, bottom: insets.bottom, trailing: insets.trailing)+ : insets)+ .frame(width: pane).frame(maxHeight: .infinity)- .background {- if floating {- RoundedRectangle(cornerRadius: 26).fill(Color(red: 0.075, green: 0.075, blue: 0.082))- .overlay(RoundedRectangle(cornerRadius: 26).strokeBorder(.white.opacity(0.10)))- } else {- ShellPalette.background.ignoresSafeArea()- }+ // Presented like Controllers: the page colour edge to edge, a hairline toward the library.+ .background { ShellPalette.background.ignoresSafeArea() }+ .overlay(alignment: .leading) {+ if floating { Rectangle().fill(ShellPalette.hairline).frame(width: 1).ignoresSafeArea() }}- // Rounded as a panel. Full screen the clip reaches far past the edges, so the banner and the- // scrolling settings run under the status bar and the home indicator.- .clipShape(RoundedRectangle(cornerRadius: floating ? 26 : 0).inset(by: floating ? 0 : -400))- .shadow(color: .black.opacity(floating ? 0.5 : 0), radius: 40, x: -8)- .padding(floating ? 12 : 0).offset(x: settingsOpen ? 0 : pane + 40).opacity(settingsOpen ? 1 : 0).frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .trailing)@@ -225,7 +216,7 @@ public struct LibraryView: View {ScrollView {VStack(alignment: .leading, spacing: 0) {PaneBanner(game: selected.game, width: width + insets.leading + insets.trailing,- leading: insets.leading, topInset: insets.top).id("set.top")+ leading: insets.leading, trailing: insets.trailing, topInset: insets.top).id("set.top")GameDetailView(detail: selected, actions: actions, showsPrimaryAction: true, showsHeader: false).padding(.horizontal, 24).padding(.top, 18).padding(.bottom, 32 + insets.bottom)// A phone on its side: a readable column, not rows stretched across the whole width.@@ -236,7 +227,7 @@ public struct LibraryView: View {}.scrollPosition($settingsPosition).scrollIndicators(.hidden)- .ignoresSafeArea(edges: floating ? [] : .all)+ .ignoresSafeArea(edges: .all).onChange(of: focus.id) { _, id inguard let id, id.hasPrefix("set.") else { return }withAnimation(reduceMotion ? nil : .easeOut(duration: 0.18)) {@@ -252,7 +243,7 @@ public struct LibraryView: View {.accessibilityLabel(ShellStrings.text("Library")).accessibilityIdentifier("library.back").shellTarget("set.back", radius: 22, action: closeSettings)- .padding(.leading, 16).padding(.top, floating ? 14 : 6)+ .padding(.leading, 16).padding(.top, 6)}}@@ -347,8 +338,9 @@ private struct PaneBanner: View {let game: GameTile/// The full width, edge to edge under the side safe areas.let width: CGFloat- /// The leading safe area: the words keep it, the banner does not.+ /// The side safe areas: the words keep them, the banner does not.var leading: CGFloat = 0+ var trailing: CGFloat = 0/// The status bar's height where the banner runs under it.var topInset: CGFloat = 0var body: some View {@@ -368,40 +360,47 @@ private struct PaneBanner: View {words(title: game.title)}}- .padding(.leading, leading + 24).padding(.trailing, 24)+ .padding(.leading, leading + 24).padding(.trailing, trailing + 24).padding(.top, bannerHeight - (hasBanner ? 22 : 0)).frame(maxWidth: .infinity, alignment: .leading)- .background {- Group {- if hasBanner {- // The banner fills the whole header edge to edge, cropped as needed, darker under the words.- ArtView(game: game, lettering: false)- .frame(width: width)- .overlay {- LinearGradient(stops: [.init(color: .clear, location: 0.35), .init(color: .black.opacity(0.45), location: 0.7),- .init(color: .black.opacity(0.6), location: 1)], startPoint: .top, endPoint: .bottom)- }- } else {- ArtView(game: game, backdrop: true)- .frame(width: width)- .scaleEffect(1.4)- .blur(radius: 40, opaque: true)- .saturation(1.2)- .overlay(Color.black.opacity(0.38))+ .background(alignment: .top) {+ // The art runs on past the header and fades into the page over a long distance, so there is no line where+ // the header ends and the settings begin.+ GeometryReader { geometry in+ let tall = geometry.size.height + 160+ Group {+ if hasBanner {+ // The banner fills the header edge to edge, cropped as needed, darker under the words.+ ArtView(game: game, lettering: false)+ .overlay {+ LinearGradient(stops: [.init(color: .clear, location: 0.3), .init(color: .black.opacity(0.4), location: 0.6),+ .init(color: .black.opacity(0.55), location: 1)], startPoint: .top, endPoint: .bottom)+ }+ } else {+ ArtView(game: game, backdrop: true)+ .scaleEffect(1.4)+ .blur(radius: 40, opaque: true)+ .saturation(1.2)+ .overlay(Color.black.opacity(0.38))+ }}- }- .overlay(alignment: .top) {- // Darker under the status bar, so the time and battery stay legible on any art.- if topInset > 0 {- LinearGradient(colors: [.black.opacity(0.5), .clear], startPoint: .top, endPoint: .bottom)- .frame(height: topInset + 50)+ .frame(width: width, height: tall)+ .clipped()+ .overlay(alignment: .top) {+ // Darker under the status bar, so the time and battery stay legible on any art.+ if topInset > 0 {+ LinearGradient(colors: [.black.opacity(0.5), .clear], startPoint: .top, endPoint: .bottom)+ .frame(height: topInset + 50)+ }+ }+ .mask {+ LinearGradient(stops: [.init(color: .black, location: 0),+ .init(color: .black, location: 0.45),+ .init(color: .black.opacity(0.55), location: 0.68),+ .init(color: .black.opacity(0.18), location: 0.85),+ .init(color: .clear, location: 1)], startPoint: .top, endPoint: .bottom)}}- .mask {- LinearGradient(stops: [.init(color: .black, location: 0), .init(color: .black, location: 0.7),- .init(color: .clear, location: 1)], startPoint: .top, endPoint: .bottom)- }- .clipped().accessibilityHidden(true)}}diff --git a/frontend-ios/Sources/ShellUI/PortraitLibrary.swift b/frontend-ios/Sources/ShellUI/PortraitLibrary.swiftindex bc6dafea..45bfae8c 100644--- a/frontend-ios/Sources/ShellUI/PortraitLibrary.swift+++ b/frontend-ios/Sources/ShellUI/PortraitLibrary.swift@@ -122,12 +122,17 @@ struct PortraitLibrary: View, Equatable {let chosen = detail.id == selected.idreturn Button { rowSelecting = !chosen; select(detail.id) } label: {VStack(alignment: .leading, spacing: 0) {- CoverView(game: detail.game)+ CoverView(game: detail.game, showsState: true).shellTarget("lib.tile.\(detail.id)") { primary(detail) }Text(detail.game.title).shellType(ShellType.cardTitle).lineLimit(typeSize.isAccessibilitySize ? 3 : 1).foregroundStyle(.white.opacity(chosen ? 1 : 0.86)).frame(maxWidth: .infinity, alignment: .leading).padding(.top, 10)- StatusLabel(state: detail.game.state).padding(.top, 4)+ // The dot on the card carries the state. Words only where the game needs something, the line kept for+ // every card so the row stays even.+ Text(detail.game.state == .playable ? " " : detail.game.state.title)+ .shellType(ShellType.status).foregroundStyle(detail.game.state.color).lineLimit(1)+ .padding(.top, 4)+ .accessibilityHidden(detail.game.state == .playable)// The Mac's selection mark: a cream bar under the chosen game.Capsule().fill(ShellPalette.cream).frame(height: 3).padding(.top, 10).opacity(chosen ? 1 : 0)}.contentShape(Rectangle())diff --git a/frontend-ios/Sources/ShellUI/ShellStyle.swift b/frontend-ios/Sources/ShellUI/ShellStyle.swiftindex 65867ffe..ab1276f0 100644--- a/frontend-ios/Sources/ShellUI/ShellStyle.swift+++ b/frontend-ios/Sources/ShellUI/ShellStyle.swift@@ -288,15 +288,39 @@ struct PlaceholderArt: View {}}-/// A 16:9 card with the hairline every picture gets, so dark art keeps its edge on the dark page.+/// A 16:9 card with the hairline every picture gets, so dark art keeps its edge on the dark page. In the library it+/// carries the game's state as a small dot in its top-left corner.struct CoverView: View {let game: GameTilevar radius: CGFloat = 10+ var showsState = falsevar body: some View {ArtView(game: game).aspectRatio(16 / 9, contentMode: .fit).clipShape(RoundedRectangle(cornerRadius: radius)).overlay(RoundedRectangle(cornerRadius: radius).strokeBorder(.white.opacity(0.10)))+ .overlay(alignment: .topLeading) {+ if showsState {+ GeometryReader { geometry in+ let size = max(8, min(14, geometry.size.width * 0.034))+ StateDot(state: game.state, size: size).padding(size * 0.9)+ }+ }+ }+ .accessibilityHidden(true)+ }+}++/// The game's state as a dot: green ready, amber when it needs data or an update, grey when it is damaged. A dark+/// ring behind it keeps it readable on light art.+struct StateDot: View {+ let state: GameState+ var size: CGFloat = 10+ var body: some View {+ Circle().fill(state.color).frame(width: size, height: size)+ .padding(size * 0.32)+ .background(Circle().fill(.black.opacity(0.55)))+ .overlay(Circle().strokeBorder(.white.opacity(0.18), lineWidth: 0.5)).accessibilityHidden(true)}}diff --git a/frontend-ios/Tests/ShellUITests/LayoutTests.swift b/frontend-ios/Tests/ShellUITests/LayoutTests.swiftindex 5a657d81..b7b4a9ba 100644--- a/frontend-ios/Tests/ShellUITests/LayoutTests.swift+++ b/frontend-ios/Tests/ShellUITests/LayoutTests.swift@@ -33,15 +33,17 @@ final class LayoutTests: XCTestCase {func testAccessibilityTextUsesOneColumn() {XCTAssertEqual(layout(834, 1194, large: true), .column)}- func testPaneWidths() {+ /// Settings drop in as the Controllers-style overlay where the library stays in view, else take the whole screen.+ func testSettingsOverlay() {+ XCTAssertFalse(ShellLayout.column.settingsFloat(402), "a phone held upright")+ XCTAssertTrue(ShellLayout.coverFlow(regular: false).settingsFloat(750), "a phone on its side")+ XCTAssertFalse(ShellLayout.coverFlow(regular: false).settingsFloat(525), "the folded foldable on its side")+ XCTAssertTrue(ShellLayout.grid.settingsFloat(834), "an iPad held upright")+ XCTAssertFalse(ShellLayout.grid.settingsFloat(626), "the unfolded foldable held upright: too narrow for both")+ XCTAssertTrue(ShellLayout.coverFlow(regular: true).settingsFloat(1194))+ XCTAssertEqual(ShellLayout.coverFlow(regular: true).paneWidth(1194), 520)XCTAssertEqual(ShellLayout.column.paneWidth(402), 402)- XCTAssertEqual(ShellLayout.grid.paneWidth(626), 380)- XCTAssertEqual(ShellLayout.grid.paneWidth(834), 417)- XCTAssertEqual(ShellLayout.coverFlow(regular: true).paneWidth(1194), 500)- XCTAssertTrue(ShellLayout.grid.settingsFloat)- XCTAssertFalse(ShellLayout.column.settingsFloat)}-/// Cover Flow moves one card per gesture: a flick to the neighbour of where the touch began, a slow drag to the/// nearest card.func testCardSnap() {