a863b0ca93
Landscape leaves now lay the puzzle out in two columns: the whole grid keeps one column (square, sized to the page) with the heading, area totals, hint/undo and notes beside it, and the leaf navigation folds into a single row. The game leaf also keeps its actions in a compact bottom bar, so the board and controls are visible without scrolling. - Leaf gains an optional wideBody used on landscape pages. - Board gains maxWidth, defaulting to the previous 350. - Split the puzzle body into area, board and note builders so both layouts share the same controls. - Add a landscape widget regression test and document the layout. This snapshot also carries the pending 2.0.2 notebook work already in the tree: read-ahead restore, bundled PCM WAV narration assets, the audio consistency comment, version 2.0.2+11, and the related unit, integration and script updates.
326 lines
9.8 KiB
Dart
326 lines
9.8 KiB
Dart
import 'dart:math' as math;
|
||
|
||
import 'package:flutter/material.dart';
|
||
import 'package:flutter/gestures.dart';
|
||
|
||
const ink = Color(0xff36413c),
|
||
blue = Color(0xff274956),
|
||
muted = Color(0xff796b55),
|
||
cream = Color(0xfff3e7cc),
|
||
amber = Color(0xffe0b568);
|
||
TextStyle hand(double size, {Color color = ink}) => TextStyle(
|
||
fontFamily: 'MaraHand',
|
||
fontSize: size,
|
||
height: 1.30,
|
||
color: color,
|
||
);
|
||
Widget writing(String value, {double size = 23, Color color = ink}) => Padding(
|
||
padding: const EdgeInsets.symmetric(vertical: 5),
|
||
child: Text(value, style: hand(size, color: color)),
|
||
);
|
||
|
||
class InkButton extends StatelessWidget {
|
||
const InkButton(
|
||
this.label,
|
||
this.onPressed, {
|
||
super.key,
|
||
this.size = 23,
|
||
this.primary = false,
|
||
});
|
||
final String label;
|
||
final VoidCallback? onPressed;
|
||
final double size;
|
||
final bool primary;
|
||
@override
|
||
Widget build(BuildContext context) => PageSwipeBlocker(
|
||
child: DecoratedBox(
|
||
decoration: BoxDecoration(
|
||
border: Border(
|
||
bottom: BorderSide(color: blue.withValues(alpha: primary ? .5 : .18)),
|
||
),
|
||
),
|
||
child: TextButton(
|
||
onPressed: onPressed,
|
||
style: TextButton.styleFrom(
|
||
foregroundColor: blue,
|
||
disabledForegroundColor: muted.withValues(alpha: .4),
|
||
textStyle: hand(size),
|
||
minimumSize: const Size(48, 48),
|
||
padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 8),
|
||
shape: const RoundedRectangleBorder(),
|
||
),
|
||
child: Text(label, textAlign: TextAlign.center),
|
||
),
|
||
),
|
||
);
|
||
}
|
||
|
||
class Paper extends StatefulWidget {
|
||
const Paper({super.key, required this.child, this.onTurn});
|
||
final Widget child;
|
||
final ValueChanged<int>? onTurn;
|
||
@override
|
||
State<Paper> createState() => _PaperState();
|
||
}
|
||
|
||
class _PaperState extends State<Paper> {
|
||
Offset _drag = Offset.zero;
|
||
Offset _origin = Offset.zero;
|
||
@override
|
||
Widget build(BuildContext context) => ColoredBox(
|
||
color: const Color(0xff314345),
|
||
child: SafeArea(
|
||
child: LayoutBuilder(
|
||
builder: (context, c) {
|
||
final landscape = c.maxWidth > c.maxHeight;
|
||
final scale = landscape
|
||
? c.maxWidth / 1024
|
||
: math.min(c.maxWidth / 1024, c.maxHeight / 1536);
|
||
final w = 1024 * scale,
|
||
h = 1536 * scale,
|
||
left = (c.maxWidth - w) / 2,
|
||
top = (c.maxHeight - h) / 2;
|
||
final narrow = c.maxWidth < 480;
|
||
final content = landscape
|
||
? Rect.fromLTRB(
|
||
c.maxWidth * .10,
|
||
c.maxHeight * .06,
|
||
c.maxWidth * .83,
|
||
c.maxHeight * .94,
|
||
)
|
||
: Rect.fromLTRB(
|
||
left + w * (narrow ? .08 : .11),
|
||
top + h * .12,
|
||
left + w * (narrow ? .91 : .83),
|
||
top + h * .91,
|
||
);
|
||
return Listener(
|
||
onPointerCancel: (_) {
|
||
_drag = Offset.zero;
|
||
},
|
||
child: GestureDetector(
|
||
behavior: HitTestBehavior.opaque,
|
||
dragStartBehavior: DragStartBehavior.down,
|
||
onHorizontalDragStart: widget.onTurn == null
|
||
? null
|
||
: (details) {
|
||
_origin = details.globalPosition;
|
||
_drag = Offset.zero;
|
||
},
|
||
onHorizontalDragUpdate: widget.onTurn == null
|
||
? null
|
||
: (details) {
|
||
_drag = details.globalPosition - _origin;
|
||
},
|
||
onHorizontalDragCancel: widget.onTurn == null
|
||
? null
|
||
: () {
|
||
_drag = Offset.zero;
|
||
},
|
||
onHorizontalDragEnd: widget.onTurn == null
|
||
? null
|
||
: (_) {
|
||
final drag = _drag;
|
||
_drag = Offset.zero;
|
||
if (drag.dx.abs() >= 48 &&
|
||
drag.dx.abs() > drag.dy.abs() * 1.3) {
|
||
widget.onTurn?.call(drag.dx < 0 ? 1 : -1);
|
||
}
|
||
},
|
||
child: Stack(
|
||
clipBehavior: Clip.hardEdge,
|
||
children: [
|
||
Positioned(
|
||
left: left,
|
||
top: top,
|
||
width: w,
|
||
height: h,
|
||
child: Image.asset(
|
||
'assets/artwork/mara-single-page-v2.png',
|
||
fit: BoxFit.fill,
|
||
excludeFromSemantics: true,
|
||
),
|
||
),
|
||
Positioned.fromRect(rect: content, child: widget.child),
|
||
],
|
||
),
|
||
),
|
||
);
|
||
},
|
||
),
|
||
),
|
||
);
|
||
}
|
||
|
||
/// A descendant horizontal recognizer wins over the page recognizer on drags.
|
||
/// Taps still reach the controls, and vertical drags can reach a ScrollView.
|
||
class PageSwipeBlocker extends StatelessWidget {
|
||
const PageSwipeBlocker({super.key, required this.child});
|
||
final Widget child;
|
||
@override
|
||
Widget build(BuildContext context) => GestureDetector(
|
||
behavior: HitTestBehavior.opaque,
|
||
onHorizontalDragStart: (_) {},
|
||
onHorizontalDragUpdate: (_) {},
|
||
onHorizontalDragEnd: (_) {},
|
||
child: child,
|
||
);
|
||
}
|
||
|
||
class Leaf extends StatelessWidget {
|
||
const Leaf({
|
||
super.key,
|
||
required this.body,
|
||
this.wideBody,
|
||
this.footer,
|
||
this.onTurn,
|
||
});
|
||
final Widget body;
|
||
|
||
/// Replaces [body] on a landscape page. The shorter page suits side-by-side
|
||
/// columns better than one long scroll, so it should arrange its own panes.
|
||
final Widget? wideBody;
|
||
final Widget? footer;
|
||
final ValueChanged<int>? onTurn;
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
final wide =
|
||
wideBody != null &&
|
||
MediaQuery.orientationOf(context) == Orientation.landscape;
|
||
return Paper(
|
||
onTurn: onTurn,
|
||
child: Column(
|
||
children: [
|
||
Expanded(
|
||
child: wide
|
||
? wideBody!
|
||
: SingleChildScrollView(
|
||
key: const PageStorageKey('leaf-scroll'),
|
||
padding: const EdgeInsets.fromLTRB(4, 0, 4, 8),
|
||
child: body,
|
||
),
|
||
),
|
||
?footer,
|
||
],
|
||
),
|
||
);
|
||
}
|
||
}
|
||
|
||
class Cover extends StatelessWidget {
|
||
const Cover({super.key, required this.onTap});
|
||
final VoidCallback onTap;
|
||
@override
|
||
Widget build(BuildContext context) => Semantics(
|
||
button: true,
|
||
label: 'Open Mara’s cloth-bound island notebook',
|
||
child: GestureDetector(
|
||
onTap: onTap,
|
||
child: SizedBox(
|
||
height: 230,
|
||
child: Center(
|
||
child: AspectRatio(
|
||
aspectRatio: 1.5,
|
||
child: LayoutBuilder(
|
||
builder: (context, c) => Stack(
|
||
children: [
|
||
Positioned.fill(
|
||
child: Image.asset(
|
||
'assets/artwork/home-notebook-cover-v2.png',
|
||
fit: BoxFit.fill,
|
||
excludeFromSemantics: true,
|
||
),
|
||
),
|
||
Positioned(
|
||
left: c.maxWidth * .27,
|
||
top: c.maxHeight * .32,
|
||
width: c.maxWidth * .49,
|
||
height: c.maxHeight * .34,
|
||
child: Center(
|
||
child: Transform.rotate(
|
||
angle: -.044,
|
||
child: Text(
|
||
'Mara’s\nisland notebook',
|
||
textAlign: TextAlign.center,
|
||
style: hand(28),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
);
|
||
}
|
||
|
||
class Sketch extends StatelessWidget {
|
||
const Sketch(this.kind, {super.key, this.height = 140});
|
||
final String kind;
|
||
final double height;
|
||
@override
|
||
Widget build(BuildContext context) => Semantics(
|
||
image: true,
|
||
label: kind == 'match'
|
||
? 'A pencil sketch of a match and a small amber flame'
|
||
: 'A folded note sealed with red wax',
|
||
child: SizedBox(
|
||
height: height,
|
||
width: double.infinity,
|
||
child: CustomPaint(painter: _SketchPainter(kind)),
|
||
),
|
||
);
|
||
}
|
||
|
||
class _SketchPainter extends CustomPainter {
|
||
_SketchPainter(this.kind);
|
||
final String kind;
|
||
@override
|
||
void paint(Canvas c, Size s) {
|
||
final p = Paint()..isAntiAlias = true;
|
||
final x = s.width * .51, h = s.height;
|
||
if (kind == 'match') {
|
||
p
|
||
..color = const Color(0xff997445)
|
||
..strokeWidth = h * .045;
|
||
c.drawLine(Offset(x - 25, h * .88), Offset(x + 12, h * .36), p);
|
||
p.color = const Color(0xff654539);
|
||
c.drawOval(Rect.fromLTRB(x + 2, h * .27, x + 26, h * .41), p);
|
||
p.color = amber;
|
||
final f = Path()
|
||
..moveTo(x + 12, h * .33)
|
||
..cubicTo(x - 24, h * .17, x + 30, h * .19, x + 17, h * .05)
|
||
..cubicTo(x + 56, h * .20, x + 32, h * .33, x + 12, h * .33);
|
||
c.drawPath(f, p);
|
||
} else {
|
||
final r = Rect.fromLTRB(s.width * .10, h * .15, s.width * .90, h * .86);
|
||
p.color = const Color(0xffead9b2);
|
||
c.drawRect(r, p);
|
||
p
|
||
..color = const Color(0xffb8a17c)
|
||
..style = PaintingStyle.stroke
|
||
..strokeWidth = 1.5;
|
||
c.drawRect(r, p);
|
||
c.drawPath(
|
||
Path()
|
||
..moveTo(r.left, r.top)
|
||
..lineTo(s.width * .5, h * .59)
|
||
..lineTo(r.right, r.top),
|
||
p,
|
||
);
|
||
c.drawLine(r.bottomLeft, Offset(s.width * .4, h * .5), p);
|
||
c.drawLine(r.bottomRight, Offset(s.width * .6, h * .5), p);
|
||
p
|
||
..style = PaintingStyle.fill
|
||
..color = const Color(0xff9e5f49);
|
||
c.drawCircle(Offset(s.width * .5, h * .57), h * .075, p);
|
||
}
|
||
}
|
||
|
||
@override
|
||
bool shouldRepaint(_SketchPainter old) => old.kind != kind;
|
||
}
|