Rearrange landscape puzzle layout
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.
This commit is contained in:
+211
-127
@@ -1,3 +1,5 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../domain/puzzle.dart';
|
||||
@@ -11,163 +13,245 @@ class Board extends StatelessWidget {
|
||||
required this.onMark,
|
||||
this.selectedArea = 0,
|
||||
this.won = false,
|
||||
this.maxWidth = 350,
|
||||
});
|
||||
final Puzzle puzzle;
|
||||
final List<int> cells;
|
||||
final ValueChanged<int> onMark;
|
||||
final int selectedArea;
|
||||
final bool won;
|
||||
|
||||
/// Wide leaves give the grid more room; it still stays a square.
|
||||
final double maxWidth;
|
||||
@override
|
||||
Widget build(BuildContext context) => Center(
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 350),
|
||||
child: AspectRatio(
|
||||
aspectRatio: 1,
|
||||
child: LayoutBuilder(
|
||||
builder: (context, c) {
|
||||
final n = puzzle.size,
|
||||
u = c.maxWidth / (n + 1.3),
|
||||
r = puzzle.regions.isEmpty
|
||||
? null
|
||||
: puzzle.regions[selectedArea];
|
||||
Widget clue(String text, bool complete) => SizedBox(
|
||||
width: u,
|
||||
height: u,
|
||||
child: Center(
|
||||
child: Text(
|
||||
text,
|
||||
style: hand(
|
||||
(u * .42).clamp(16, 23),
|
||||
color: complete ? blue : muted,
|
||||
Widget build(BuildContext context) => PageSwipeBlocker(
|
||||
child: Center(
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(maxWidth: maxWidth),
|
||||
child: AspectRatio(
|
||||
aspectRatio: 1,
|
||||
child: LayoutBuilder(
|
||||
builder: (context, c) {
|
||||
final n = puzzle.size,
|
||||
u = c.maxWidth / (n + 1.3),
|
||||
r = puzzle.regions.isEmpty
|
||||
? null
|
||||
: puzzle.regions[selectedArea];
|
||||
Widget clue(String text, bool complete) => SizedBox(
|
||||
width: u,
|
||||
height: u,
|
||||
child: Center(
|
||||
child: Text(
|
||||
text,
|
||||
style: hand(
|
||||
(u * .42).clamp(16, 23),
|
||||
color: complete ? blue : muted,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
bool complete(Iterable<int> indices, int total) =>
|
||||
indices.where((i) => cells[i] == 1).length == total;
|
||||
return Align(
|
||||
alignment: Alignment.center,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
SizedBox(width: u, height: u),
|
||||
for (var col = 0; col < n; col++)
|
||||
clue(
|
||||
'${puzzle.cols[col]}',
|
||||
complete(
|
||||
List.generate(n, (i) => i * n + col),
|
||||
puzzle.cols[col],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
for (var row = 0; row < n; row++)
|
||||
);
|
||||
bool complete(Iterable<int> indices, int total) =>
|
||||
indices.where((i) => cells[i] == 1).length == total;
|
||||
return Align(
|
||||
alignment: Alignment.center,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
clue(
|
||||
'${puzzle.rows[row]}',
|
||||
complete(
|
||||
List.generate(n, (i) => row * n + i),
|
||||
puzzle.rows[row],
|
||||
),
|
||||
),
|
||||
SizedBox(width: u, height: u),
|
||||
for (var col = 0; col < n; col++)
|
||||
Builder(
|
||||
builder: (context) {
|
||||
final i = row * n + col,
|
||||
value = cells[i],
|
||||
fixed = puzzle.given[i],
|
||||
inside = r?.contains(i, n) ?? false;
|
||||
final state = value == 0
|
||||
? 'empty'
|
||||
: value == 1
|
||||
? 'lit'
|
||||
: 'crossed out';
|
||||
return Semantics(
|
||||
label:
|
||||
'Row ${row + 1}, column ${col + 1}, $state${fixed ? ', fixed clue' : ''}',
|
||||
button: !fixed && !won,
|
||||
enabled: !fixed && !won,
|
||||
onTap: fixed || won ? null : () => onMark(i),
|
||||
excludeSemantics: true,
|
||||
child: GestureDetector(
|
||||
key: ValueKey('cell-$i'),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
clue(
|
||||
'${puzzle.cols[col]}',
|
||||
complete(
|
||||
List.generate(n, (i) => i * n + col),
|
||||
puzzle.cols[col],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
for (var row = 0; row < n; row++)
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
clue(
|
||||
'${puzzle.rows[row]}',
|
||||
complete(
|
||||
List.generate(n, (i) => row * n + i),
|
||||
puzzle.rows[row],
|
||||
),
|
||||
),
|
||||
for (var col = 0; col < n; col++)
|
||||
Builder(
|
||||
builder: (context) {
|
||||
final i = row * n + col,
|
||||
value = cells[i],
|
||||
fixed = puzzle.given[i],
|
||||
inside = r?.contains(i, n) ?? false;
|
||||
final state = value == 0
|
||||
? 'empty'
|
||||
: value == 1
|
||||
? 'lit'
|
||||
: 'crossed out';
|
||||
return Semantics(
|
||||
label:
|
||||
'Row ${row + 1}, column ${col + 1}, $state${fixed ? ', fixed clue' : ''}',
|
||||
button: !fixed && !won,
|
||||
enabled: !fixed && !won,
|
||||
onTap: fixed || won ? null : () => onMark(i),
|
||||
child: SizedBox(
|
||||
width: u,
|
||||
height: u,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(2),
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: value == 1
|
||||
? blue
|
||||
: inside
|
||||
? amber.withValues(alpha: .22)
|
||||
: Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(
|
||||
2,
|
||||
),
|
||||
border: Border.all(
|
||||
excludeSemantics: true,
|
||||
child: GestureDetector(
|
||||
key: ValueKey('cell-$i'),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: fixed || won
|
||||
? null
|
||||
: () => onMark(i),
|
||||
child: SizedBox(
|
||||
width: u,
|
||||
height: u,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(2),
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: inside
|
||||
? const Color(0xffaa5b2a)
|
||||
: muted.withValues(alpha: .48),
|
||||
width: inside ? 1.4 : .65,
|
||||
? amber.withValues(alpha: .22)
|
||||
: Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(
|
||||
2,
|
||||
),
|
||||
border: Border.all(
|
||||
color: inside
|
||||
? const Color(0xffaa5b2a)
|
||||
: muted.withValues(
|
||||
alpha: .48,
|
||||
),
|
||||
width: inside ? 1.4 : .65,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: Stack(
|
||||
children: [
|
||||
if (value == 2)
|
||||
Center(
|
||||
child: Text(
|
||||
'×',
|
||||
style: hand(
|
||||
u * .62,
|
||||
color: muted,
|
||||
child: Stack(
|
||||
children: [
|
||||
if (value != 0)
|
||||
Positioned.fill(
|
||||
child: CustomPaint(
|
||||
painter: PencilMark(
|
||||
value: value,
|
||||
variation: i,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (fixed)
|
||||
Positioned(
|
||||
right: 3,
|
||||
bottom: 3,
|
||||
child: Container(
|
||||
width: 4,
|
||||
height: 4,
|
||||
decoration: BoxDecoration(
|
||||
color: value == 1
|
||||
? cream
|
||||
: muted,
|
||||
shape: BoxShape.circle,
|
||||
if (fixed)
|
||||
Positioned(
|
||||
right: 3,
|
||||
bottom: 3,
|
||||
child: Container(
|
||||
width: 4,
|
||||
height: 4,
|
||||
decoration: BoxDecoration(
|
||||
color: muted,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Deterministic pencil strokes stay put when the player revisits a cell.
|
||||
/// Both marks use paths, so their appearance never depends on a fallback font.
|
||||
class PencilMark extends CustomPainter {
|
||||
const PencilMark({required this.value, required this.variation});
|
||||
final int value, variation;
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
final unit = math.min(size.width, size.height);
|
||||
final wobble = ((variation % 5) - 2) * .006;
|
||||
final paint = Paint()
|
||||
..isAntiAlias = true
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeCap = StrokeCap.round
|
||||
..strokeJoin = StrokeJoin.round;
|
||||
canvas.save();
|
||||
canvas.scale(size.width, size.height);
|
||||
if (value == 1) {
|
||||
paint
|
||||
..color = blue.withValues(alpha: .78)
|
||||
..strokeWidth = 1.65 / unit;
|
||||
// Closely spaced, slightly wandering strokes shade the cell by hand.
|
||||
canvas.clipRect(const Rect.fromLTWH(.13, .13, .74, .74));
|
||||
for (var line = -12; line <= 20; line++) {
|
||||
final x = line * .065;
|
||||
canvas.drawPath(
|
||||
Path()
|
||||
..moveTo(x, .90)
|
||||
..quadraticBezierTo(x + .34 + wobble, .52, x + .68, .09),
|
||||
paint,
|
||||
);
|
||||
}
|
||||
paint
|
||||
..color = blue.withValues(alpha: .34)
|
||||
..strokeWidth = .8 / unit;
|
||||
for (var line = -6; line <= 12; line++) {
|
||||
final x = line * .13;
|
||||
canvas.drawPath(
|
||||
Path()
|
||||
..moveTo(x, .12)
|
||||
..quadraticBezierTo(x + .3, .50 + wobble, x + .59, .89),
|
||||
paint,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
paint
|
||||
..color = muted
|
||||
..strokeWidth = 1.8 / unit;
|
||||
canvas.drawPath(
|
||||
Path()
|
||||
..moveTo(.26, .24 + wobble)
|
||||
..cubicTo(.43, .38, .58, .64, .76, .77),
|
||||
paint,
|
||||
);
|
||||
canvas.drawPath(
|
||||
Path()
|
||||
..moveTo(.75, .22)
|
||||
..cubicTo(.61, .42 + wobble, .40, .59, .24, .78),
|
||||
paint,
|
||||
);
|
||||
paint
|
||||
..color = muted.withValues(alpha: .30)
|
||||
..strokeWidth = .65 / unit;
|
||||
canvas.drawPath(
|
||||
Path()
|
||||
..moveTo(.28, .25)
|
||||
..quadraticBezierTo(.54, .56, .74, .79),
|
||||
paint,
|
||||
);
|
||||
}
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(PencilMark old) =>
|
||||
value != old.value || variation != old.variation;
|
||||
}
|
||||
|
||||
class PixelPicture extends StatelessWidget {
|
||||
const PixelPicture(
|
||||
this.picture, {
|
||||
|
||||
Reference in New Issue
Block a user