diff --git a/docs/CODE_MAP.md b/docs/CODE_MAP.md index 433ef8c..f553def 100644 --- a/docs/CODE_MAP.md +++ b/docs/CODE_MAP.md @@ -248,6 +248,7 @@ Content pipelines: - All visible handwriting uses `hand(size)` (`MaraHand` → Dancing Script). Colours live in `lib/ui/paper.dart`: `ink` `#36413c`, `blue` `#274956`, `muted` `#796b55`, `cream` `#f3e7cc`, `amber` `#e0b568`. - `writing()` adds paper spacing; `folio()` is the small blue label above a leaf's content. +- The home folio stays above the scroll viewport so its lettering remains fully visible during scrolling; the title, illustrations and actions scroll below it. - `InkButton` is the only button style: transparent, underlined ink text, minimum 48 px touch target, optional `primary` emphasis, wrapped in `PageSwipeBlocker`. ### Paper and leaves @@ -255,7 +256,7 @@ Content pipelines: - `Paper` draws `assets/artwork/mara-single-page-v2.png` (1024×1536). Portrait scales to fit both dimensions; landscape scales to width, so the sheet is cropped vertically. - Content area: portrait `x 11%–83%`, `y 12%–91%` of the sheet (8%–91% when narrower than 480 px); landscape `x 10%–83%`, `y 6%–94%` of the viewport. - A page turns when a horizontal drag ends with `|dx| ≥ 48` and `|dx| > 1.3·|dy|`. `PageSwipeBlocker` installs a descendant horizontal recogniser so grid/button drags never reach the page; taps and vertical drags still pass through. -- `Leaf` is the standard page body: a scrolling column in portrait, and `wideBody` in landscape when supplied. The footer stays pinned. Scroll keys are `leaf-scroll` (portrait) and `leaf-side-scroll` (landscape side column). +- `Leaf` is the standard page body: a scrolling column in portrait, and `wideBody` in landscape when supplied. The footer stays pinned. Scroll keys are `leaf-scroll` (portrait) and `leaf-side-scroll` (landscape side column). These are ordinary value keys: opening or revisiting a leaf always starts at the top, without restoring a saved scroll offset. Both panes include top padding for handwriting ascenders. - `Cover` is the tappable notebook cover on the home screen. `Sketch` draws pencil props (`match`, `envelope`). ### Puzzle board diff --git a/lib/main.dart b/lib/main.dart index 40b03e9..dba2093 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -407,87 +407,109 @@ class _NotebookState extends State with WidgetsBindingObserver { Widget home() => ColoredBox( color: cream, child: SafeArea( - child: SingleChildScrollView( - key: const ValueKey('home-scroll'), - padding: const EdgeInsets.fromLTRB(28, 26, 28, 36), - child: Center( - child: ConstrainedBox( - constraints: const BoxConstraints(maxWidth: 650), - child: column([ - folio('L U M E N / AN ISLAND STORY'), - writing('A light to come\nhome to.', size: 40), - Image.asset( - 'assets/artwork/home-harbour-v2.png', - height: 220, - fit: BoxFit.contain, - semanticLabel: 'Watercolour of the island at dusk, with the lighthouse and Gran’s cottage.', + child: Column( + children: [ + Padding( + padding: const EdgeInsets.fromLTRB(28, 34, 28, 8), + child: Center( + child: ConstrainedBox( + constraints: const BoxConstraints(maxWidth: 650), + child: SizedBox( + width: double.infinity, + child: folio('L U M E N / AN ISLAND STORY'), + ), ), - writing( - 'Some things are worth keeping. — Gran', - size: 25, - color: const Color(0xff70503b), - ), - Cover(onTap: g.openNotebook), - action( - 'Open Mara’s notebook · ${g.recoveredCount} / 12', - g.openNotebook, - primary: true, - ), - gap(), - Row( - mainAxisAlignment: MainAxisAlignment.spaceAround, - children: [ - Text( - '${g.streak}\nDAY STREAK', - textAlign: TextAlign.center, - style: hand(18, color: blue), - ), - Text( - '${g.solved}\nPATTERNS FOUND', - textAlign: TextAlign.center, - style: hand(18, color: blue), - ), - ], - ), - divider(), - folio('A SMALL DAILY RITUAL'), - writing( - DateFormat('EEEE, d MMMM').format(DateTime.now()), - size: 27, - ), - action( - 'Play today’s puzzle →', - () => g.startDaily(DateTime.now()), - ), - gap(), - folio('BY THE COTTAGE WINDOW'), - writing( - 'A few spare pages for practice. For overlapping-area puzzles, follow the notebook’s story.', - size: 22, - color: muted, - ), - action('Difficulty · ${g.difficulty.label} ▾', chooseDifficulty), - action( - 'Practice · ${g.difficulty.label} · Level ${g.practiceLevel}', - () => unawaited(g.startPractice()), - ), - action('How to play', rules), - action('Sound & atmosphere', soundSettings), - action('Privacy & advertising', privacy), - action( - 'Open-source licenses', - () => - showLicensePage(context: context, applicationName: 'Lumen'), - ), - gap(), - writing( - 'Leave a light in the window.', - size: 26, - color: const Color(0xff70503b), - ), - ]), + ), ), - ), + Expanded( + child: SingleChildScrollView( + key: const ValueKey('home-scroll'), + padding: const EdgeInsets.fromLTRB(28, 0, 28, 36), + child: Center( + child: ConstrainedBox( + constraints: const BoxConstraints(maxWidth: 650), + child: column([ + writing('A light to come\nhome to.', size: 40), + Image.asset( + 'assets/artwork/home-harbour-v2.png', + height: 220, + fit: BoxFit.contain, + semanticLabel: 'Watercolour of the island at dusk, with the lighthouse and Gran’s cottage.', + ), + writing( + 'Some things are worth keeping. — Gran', + size: 25, + color: const Color(0xff70503b), + ), + Cover(onTap: g.openNotebook), + action( + 'Open Mara’s notebook · ${g.recoveredCount} / 12', + g.openNotebook, + primary: true, + ), + gap(), + Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + Text( + '${g.streak}\nDAY STREAK', + textAlign: TextAlign.center, + style: hand(18, color: blue), + ), + Text( + '${g.solved}\nPATTERNS FOUND', + textAlign: TextAlign.center, + style: hand(18, color: blue), + ), + ], + ), + divider(), + folio('A SMALL DAILY RITUAL'), + writing( + DateFormat('EEEE, d MMMM').format(DateTime.now()), + size: 27, + ), + action( + 'Play today’s puzzle →', + () => g.startDaily(DateTime.now()), + ), + gap(), + folio('BY THE COTTAGE WINDOW'), + writing( + 'A few spare pages for practice. For overlapping-area puzzles, follow the notebook’s story.', + size: 22, + color: muted, + ), + action( + 'Difficulty · ${g.difficulty.label} ▾', + chooseDifficulty, + ), + action( + 'Practice · ${g.difficulty.label} · Level ${g.practiceLevel}', + () => unawaited(g.startPractice()), + ), + action('How to play', rules), + action('Sound & atmosphere', soundSettings), + action('Privacy & advertising', privacy), + action( + 'Open-source licenses', + () => showLicensePage( + context: context, + applicationName: 'Lumen', + ), + ), + gap(), + writing( + 'Leave a light in the window.', + size: 26, + color: const Color(0xff70503b), + ), + ]), + ), + ), + ), + ), + ], ), ), ); @@ -1069,8 +1091,8 @@ class _NotebookState extends State with WidgetsBindingObserver { const SizedBox(width: 18), Expanded( child: SingleChildScrollView( - key: const PageStorageKey('leaf-side-scroll'), - padding: const EdgeInsets.fromLTRB(2, 0, 2, 8), + key: const ValueKey('leaf-side-scroll'), + padding: const EdgeInsets.fromLTRB(2, 8, 2, 8), child: column(side), ), ), diff --git a/lib/ui/paper.dart b/lib/ui/paper.dart index c787c3e..3695b6d 100644 --- a/lib/ui/paper.dart +++ b/lib/ui/paper.dart @@ -195,8 +195,10 @@ class Leaf extends StatelessWidget { child: wide ? wideBody! : SingleChildScrollView( - key: const PageStorageKey('leaf-scroll'), - padding: const EdgeInsets.fromLTRB(4, 0, 4, 8), + // Each newly opened leaf starts at the top, including + // leaves revisited with Previous or a bookmark. + key: const ValueKey('leaf-scroll'), + padding: const EdgeInsets.fromLTRB(4, 8, 4, 8), child: body, ), ), diff --git a/test/widget_test.dart b/test/widget_test.dart index 2062bba..dd098c7 100644 --- a/test/widget_test.dart +++ b/test/widget_test.dart @@ -28,6 +28,97 @@ class _RewardAds extends Ads { } void main() { + testWidgets('home lettering stays fully above the scrolling content', ( + tester, + ) async { + addTearDown(tester.view.reset); + await tester.runAsync(() async { + final font = FontLoader('MaraHand') + ..addFont(rootBundle.load('assets/fonts/DancingScript.ttf')); + await font.load(); + }); + final book = (await tester.runAsync(Book.load))!; + for (final size in [const Size(360, 640), const Size(960, 600)]) { + tester.view.physicalSize = size; + tester.view.devicePixelRatio = 1; + await tester.pumpWidget( + LumenApp(game: Game(book, Progress.memory()), adsEnabled: false), + ); + await tester.pumpAndSettle(); + final heading = find.text('L U M E N / AN ISLAND STORY'); + final scroll = find.byKey(const ValueKey('home-scroll')); + final headingRect = tester.getRect(heading); + expect(headingRect.bottom, lessThan(tester.getRect(scroll).top)); + for (final dy in [-40.0, -300.0, 500.0]) { + await tester.drag(scroll, Offset(0, dy)); + await tester.pumpAndSettle(); + expect(tester.getRect(heading), headingRect); + expect(heading.hitTestable(), findsOneWidget); + expect(tester.takeException(), isNull); + } + await tester.pumpWidget(const SizedBox()); + } + }); + + testWidgets( + 'opening and revisiting leaves starts at the top in both layouts', + (tester) async { + addTearDown(tester.view.reset); + final book = (await tester.runAsync(Book.load))!; + for (final size in [const Size(360, 640), const Size(960, 600)]) { + tester.view.physicalSize = size; + tester.view.devicePixelRatio = 1; + final wide = size.width > size.height; + final g = Game(book, Progress.memory({'story_access_level': 11})); + final first = wide ? 2 : 1; + final second = wide ? 7 : 3; + g.showStory(first); + await tester.pumpWidget( + MaterialApp( + home: MediaQuery( + data: MediaQueryData( + size: size, + textScaler: const TextScaler.linear(1.5), + ), + child: Notebook(game: g, adsEnabled: false), + ), + ), + ); + await tester.pumpAndSettle(); + final pane = find.byKey( + ValueKey(wide ? 'leaf-side-scroll' : 'leaf-scroll'), + ); + ScrollPosition position() => tester + .state( + find + .descendant(of: pane, matching: find.byType(Scrollable)) + .first, + ) + .position; + expect(position().pixels, 0); + await tester.drag(pane, const Offset(0, -220)); + await tester.pumpAndSettle(); + expect(position().pixels, greaterThan(0)); + // Updates within a page should still preserve its reading position. + final offset = position().pixels; + g.showStory(first); + await tester.pumpAndSettle(); + expect(position().pixels, offset); + g.showStory(second); + await tester.pumpAndSettle(); + expect(position().pixels, 0); + await tester.drag(pane, const Offset(0, -180)); + await tester.pumpAndSettle(); + expect(position().pixels, greaterThan(0)); + g.showStory(first); + await tester.pumpAndSettle(); + expect(position().pixels, 0); + expect(tester.takeException(), isNull); + await tester.pumpWidget(const SizedBox()); + } + }, + ); + testWidgets('atmosphere controls fit large text and remember mute', ( tester, ) async {