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
fix(qt): clip library horizontal card strip so it does not widen hero or page
LNPANDY14cb905d4c9a
diff --git a/frontend-qt/nspb_qt/ui.py b/frontend-qt/nspb_qt/ui.pyindex ef81f095..7bb2142a 100644--- a/frontend-qt/nspb_qt/ui.py+++ b/frontend-qt/nspb_qt/ui.py@@ -45,6 +45,7 @@ from .widgets import (DropOverlayWidget,GameCardWidget,HeroBannerWidget,+ HorizontalStripViewport,LauncherSegmented,LauncherSwitch,StatusDot,@@ -513,12 +514,11 @@ class MainWindow(QMainWindow):ccol.addLayout(chead)self._coll_offset = 0- self.coll_strip = QWidget()- self.coll_strip.setFixedHeight(176)- self.coll_strip_layout = QHBoxLayout(self.coll_strip)- self.coll_strip_layout.setContentsMargins(0, 4, 0, 4)- self.coll_strip_layout.setSpacing(18)- ccol.addWidget(self.coll_strip)+ self._ensure_selected_card_visible = False+ self.coll_viewport = HorizontalStripViewport(height=176)+ self.coll_strip = self.coll_viewport.strip+ self.coll_strip_layout = self.coll_viewport.strip_layout+ ccol.addWidget(self.coll_viewport)pcol.addWidget(coll_wrap)self.lib_stack.addWidget(pop)@@ -607,6 +607,7 @@ class MainWindow(QMainWindow):w_old.setParent(None)w_old.deleteLater()+ selected_card: GameCardWidget | None = Noneif not filtered:no_lbl = QLabel(self.m.t('library.noResults'))no_lbl.setObjectName('muted')@@ -615,21 +616,29 @@ class MainWindow(QMainWindow):for g in filtered:dot_c = style.GREEN if g.has_any_build else style.NEUTRAL_DOTart = self.m.artwork.image_path(g.title_id, self.m.engine_path)+ is_sel = sel is not None and g.title_id == sel.title_idcard = GameCardWidget(title_id=g.title_id,title=g.name,image_path=art,- selected=(sel is not None and g.title_id == sel.title_id),+ selected=is_sel,dot_color=dot_c,is_switch2=g.is_switch2(self.m.engine_path),switch2_label=self.m.t('switch2.badge'),)+ if is_sel:+ selected_card = cardcard.clicked.connect(self._on_card_selected)card.doubleClicked.connect(self._on_card_double_clicked)self.coll_strip_layout.addWidget(card)self.coll_strip_layout.addStretch(1)+ self.coll_viewport.sync_strip(+ ensure_visible=selected_card if self._ensure_selected_card_visible else None+ )+ self._ensure_selected_card_visible = Falsedef _on_card_selected(self, title_id: str) -> None:+ self._ensure_selected_card_visible = Trueself.m.library.select(title_id)self._refresh_library()@@ -728,7 +737,13 @@ class MainWindow(QMainWindow):filtered = self._filtered_games()if not filtered:return- self._coll_offset = max(0, min(max(0, len(filtered) - 1), self._coll_offset + direction))+ sel = self.m.library.selected+ cur_idx = next(+ (i for i, g in enumerate(filtered) if sel is not None and g.title_id == sel.title_id),+ self._coll_offset,+ )+ self._coll_offset = max(0, min(max(0, len(filtered) - 1), cur_idx + direction))+ self._ensure_selected_card_visible = Trueself.m.library.select(filtered[self._coll_offset].title_id)self._refresh_library()diff --git a/frontend-qt/nspb_qt/widgets.py b/frontend-qt/nspb_qt/widgets.pyindex 6b21fef5..f138b31b 100644--- a/frontend-qt/nspb_qt/widgets.py+++ b/frontend-qt/nspb_qt/widgets.py@@ -14,6 +14,7 @@ from PySide6.QtGui import (QPainterPath,QPen,QPixmap,+ QWheelEvent,)from PySide6.QtWidgets import (QFrame,@@ -608,6 +609,86 @@ class GameCardWidget(QWidget):p.drawRoundedRect(QRectF(4.0, self.TOTAL_H - 5.0, 28.0, 3.0), 1.5, 1.5)+class HorizontalStripViewport(QWidget):+ """Clipping viewport that hosts a horizontally scrollable card strip without expanding parent width."""++ def __init__(self, height: int = 176, parent: QWidget | None = None) -> None:+ super().__init__(parent)+ self._fixed_h = height+ self._scroll_x = 0+ self.setFixedHeight(height)+ self.setMinimumWidth(0)+ self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)++ self.strip = QWidget(self)+ self.strip.setFixedHeight(height)+ self.strip_layout = QHBoxLayout(self.strip)+ self.strip_layout.setContentsMargins(0, 4, 0, 4)+ self.strip_layout.setSpacing(18)++ def minimumSizeHint(self) -> QSize:+ return QSize(0, self._fixed_h)++ def sizeHint(self) -> QSize:+ return QSize(200, self._fixed_h)++ def _layout_strip(self) -> tuple[int, int]:+ for i in range(self.strip_layout.count()):+ w = self.strip_layout.itemAt(i).widget()+ if w is not None and not w.isVisibleTo(self.strip):+ w.show()+ self.strip_layout.invalidate()+ self.strip_layout.activate()+ content_w = self.strip_layout.sizeHint().width()+ vw = max(1, self.width())+ self.strip.resize(max(vw, content_w), self._fixed_h)+ self.strip_layout.activate()+ return content_w, vw++ def max_scroll(self) -> int:+ content_w, vw = self._layout_strip()+ return max(0, content_w - vw)++ def set_scroll_x(self, x: int) -> None:+ content_w, vw = self._layout_strip()+ self._scroll_x = max(0, min(max(0, content_w - vw), x))+ self.strip.move(-self._scroll_x, 0)++ def scroll_by(self, dx: int) -> None:+ self.set_scroll_x(self._scroll_x + dx)++ def sync_strip(self, ensure_visible: QWidget | None = None) -> None:+ content_w, vw = self._layout_strip()+ target_x = self._scroll_x+ if ensure_visible is not None and self.width() > 0:+ left = ensure_visible.x()+ right = left + ensure_visible.width()+ if left < target_x:+ target_x = left+ elif right > target_x + vw:+ target_x = right - vw+ self._scroll_x = max(0, min(max(0, content_w - vw), target_x))+ self.strip.move(-self._scroll_x, 0)++ def resizeEvent(self, event) -> None:+ super().resizeEvent(event)+ self.set_scroll_x(self._scroll_x)++ def wheelEvent(self, event: QWheelEvent) -> None:+ px = event.pixelDelta()+ ang = event.angleDelta()+ if not px.isNull() and (px.x() != 0 or px.y() != 0):+ dx = -px.x() if abs(px.x()) >= abs(px.y()) else -px.y()+ else:+ raw = ang.x() if abs(ang.x()) >= abs(ang.y()) else ang.y()+ dx = -int(raw * 0.8)+ if dx != 0 and self.max_scroll() > 0:+ self.scroll_by(dx)+ event.accept()+ return+ super().wheelEvent(event)++class DropOverlayWidget(QWidget):"""Full-window drag-and-drop overlay matching GameFilesDropOverlay in SwiftUI."""diff --git a/frontend-qt/tests/test_app_update.py b/frontend-qt/tests/test_app_update.pyindex 891f7383..0e64447d 100644--- a/frontend-qt/tests/test_app_update.py+++ b/frontend-qt/tests/test_app_update.py@@ -163,6 +163,54 @@ class AppUpdateTests(unittest.TestCase):self.assertEqual(env['NX_NEW_EXE'], 'NX2Apple.exe')self.assertEqual(env['NX_TARGET'], str(old_exe.resolve().parent))+ def test_library_horizontal_strip_does_not_widen_hero_or_page_and_scrolls_cards(self) -> None:+ os.environ.setdefault('QT_QPA_PLATFORM', 'offscreen')+ try:+ from PySide6.QtCore import QEvent+ from PySide6.QtWidgets import QApplication+ except ImportError:+ self.skipTest('PySide6 is not installed')++ from nspb_qt.library import LibraryGame+ from nspb_qt.model import Model+ from nspb_qt.ui import MainWindow++ app = QApplication.instance() or QApplication([])+ m = Model()+ w = MainWindow(m)++ def cleanup() -> None:+ w.close()+ w.deleteLater()+ m.deleteLater()+ app.sendPostedEvents(None, QEvent.DeferredDelete)+ app.processEvents()++ self.addCleanup(cleanup)+ m.library.games = [+ LibraryGame(title_id=f'01000000000100{i:02X}', name=f'Game {i}')+ for i in range(11)+ ]+ m.library.selected_id = m.library.games[0].title_id+ w.resize(1080, 720)+ w.show()+ w._switch_page('library')+ w._refresh_library()+ for _ in range(3):+ app.processEvents()++ self.assertLessEqual(w.library_page.minimumSizeHint().width(), 1080)+ self.assertLessEqual(w.hero.width(), 1080)+ self.assertGreater(w.coll_viewport.max_scroll(), 1000)+ self.assertEqual(w.coll_strip.x(), 0)++ for _ in range(10):+ w._scroll_collection(1)+ app.processEvents()+ self.assertEqual(m.library.selected_id, m.library.games[10].title_id)+ self.assertLess(w.coll_strip.x(), -1000)+ self.assertLessEqual(w.hero.width(), 1080)+if __name__ == '__main__':unittest.main()