All checks were successful
CI / Windows build (push) Successful in 11m34s
W1 — Custom pen width + pressure sensitivity (Saber-style):
- Root cause of "压感没用": perfect_freehand 1.0.4 IGNORES real stylus pressure
(hardcodes radius=size/2 when simulatePressure=false) — width never tracked pen
force. Upgraded perfect_freehand ^1.0.0 -> ^2.0.0 (honors real pressure); migrated
all 5 getStroke call sites to the 2.x API (PointVector / StrokeOptions / Offset).
- De-hardcoded `thinning` into `kDefaultPenThinning` (0.85), single source shared by
the on-screen painter and the PDF export path; exposed as PenConfig.pressureSensitivity
with a Pressure Sensitivity slider; live-applies via a config listener.
W3 — Native Windows pen plugin (tilt + barrel/eraser buttons):
- windows/runner/pen_channel.{h,cpp}: observe WM_POINTER at the TOP of MessageHandler
(before HandleTopLevelWindowProc, which Flutter uses to consume pen events), read
GetPointerPenInfo penFlags + tilt, stream over EventChannel('badnote/pen'); non-consuming.
- PenInputService: single latched hardware state (no Win32-pointerId<->event.pointer
correlation); graceful no-op off-Windows.
- pen_canvas maps barrel/inverted/eraser through PenConfig.sideButton/eraserEnd
(eraser/undo/toggleTool/pan) and captures tilt into PenPoint.tilt -> EditorPoint.tilt.
W2 — Zoom flicker: page raster isolated in its own RepaintBoundary (safe interim);
definitive crisp-on-zoom fix gated on the on-device root-cause probe (plan M3).
Plans: ralplan-consensus plan at docs/plans/2026-06-22-badnote-pen-polish.md
(Architect APPROVE-WITH-MUST-FIX M1-M4 + Critic ITERATE->APPROVE).
Tests: 58/58 pass incl. shared-thinning invariant + thinning-affects-outline +
tilt-adapter round-trip. flutter analyze clean; linux debug build OK.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
319 lines
10 KiB
Dart
319 lines
10 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../input/pen_config.dart';
|
|
|
|
/// Shows a Material You modal bottom sheet for configuring pen input.
|
|
///
|
|
/// Changes are applied and persisted immediately via [controller] setters,
|
|
/// so the sheet reflects the live configuration at all times.
|
|
Future<void> showPenSettingsSheet(
|
|
BuildContext context,
|
|
PenConfigController controller,
|
|
) {
|
|
return showModalBottomSheet<void>(
|
|
context: context,
|
|
isScrollControlled: true,
|
|
backgroundColor: Theme.of(context).colorScheme.surfaceContainerHigh,
|
|
shape: const RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.vertical(top: Radius.circular(28)),
|
|
),
|
|
builder: (context) => _PenSettingsSheet(controller: controller),
|
|
);
|
|
}
|
|
|
|
class _PenSettingsSheet extends StatelessWidget {
|
|
const _PenSettingsSheet({required this.controller});
|
|
|
|
final PenConfigController controller;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return ListenableBuilder(
|
|
listenable: controller,
|
|
builder: (context, _) {
|
|
final config = controller.value;
|
|
final colorScheme = Theme.of(context).colorScheme;
|
|
|
|
return DraggableScrollableSheet(
|
|
expand: false,
|
|
initialChildSize: 0.7,
|
|
minChildSize: 0.4,
|
|
maxChildSize: 0.95,
|
|
builder: (context, scrollController) {
|
|
return ListView(
|
|
controller: scrollController,
|
|
padding: const EdgeInsets.fromLTRB(16, 8, 16, 32),
|
|
children: [
|
|
// Drag handle
|
|
Center(
|
|
child: Container(
|
|
width: 32,
|
|
height: 4,
|
|
margin: const EdgeInsets.symmetric(vertical: 12),
|
|
decoration: BoxDecoration(
|
|
color: colorScheme.onSurfaceVariant.withAlpha(80),
|
|
borderRadius: BorderRadius.circular(2),
|
|
),
|
|
),
|
|
),
|
|
Text(
|
|
'Pen Settings',
|
|
style: Theme.of(context).textTheme.titleLarge,
|
|
textAlign: TextAlign.center,
|
|
),
|
|
const SizedBox(height: 16),
|
|
|
|
// ── Button Actions ────────────────────────────────────────
|
|
_SectionHeader(
|
|
title: 'Button Actions',
|
|
icon: Icons.touch_app,
|
|
colorScheme: colorScheme,
|
|
),
|
|
const SizedBox(height: 8),
|
|
_LabeledRow(
|
|
label: 'Side Button',
|
|
child: _ActionDropdown(
|
|
value: config.sideButton,
|
|
onChanged: controller.setSideButton,
|
|
),
|
|
),
|
|
const SizedBox(height: 8),
|
|
_LabeledRow(
|
|
label: 'Eraser End',
|
|
child: _ActionDropdown(
|
|
value: config.eraserEnd,
|
|
onChanged: controller.setEraserEnd,
|
|
),
|
|
),
|
|
const SizedBox(height: 16),
|
|
|
|
// ── Pressure ──────────────────────────────────────────────
|
|
_SectionHeader(
|
|
title: 'Pressure',
|
|
icon: Icons.compress,
|
|
colorScheme: colorScheme,
|
|
),
|
|
_SliderTile(
|
|
label: 'Pressure Sensitivity',
|
|
value: config.pressureSensitivity,
|
|
min: 0.0,
|
|
max: 1.0,
|
|
divisions: 20,
|
|
formatValue: (v) => v.toStringAsFixed(2),
|
|
onChanged: controller.setPressureSensitivity,
|
|
),
|
|
_SliderTile(
|
|
label: 'Pressure Gamma',
|
|
value: config.pressureGamma,
|
|
min: 0.3,
|
|
max: 3.0,
|
|
divisions: 27,
|
|
formatValue: (v) => v.toStringAsFixed(2),
|
|
onChanged: controller.setPressureGamma,
|
|
),
|
|
|
|
// ── Input ─────────────────────────────────────────────────
|
|
_SectionHeader(
|
|
title: 'Input',
|
|
icon: Icons.pan_tool_alt,
|
|
colorScheme: colorScheme,
|
|
),
|
|
_SliderTile(
|
|
label: 'Palm Rejection',
|
|
value: config.palmRejectionMs,
|
|
min: 0,
|
|
max: 500,
|
|
divisions: 50,
|
|
formatValue: (v) => '${v.round()} ms',
|
|
onChanged: controller.setPalmRejectionMs,
|
|
),
|
|
SwitchListTile(
|
|
title: const Text('Finger Drawing'),
|
|
subtitle: const Text(
|
|
'Allow touch strokes when no pen is detected',
|
|
),
|
|
value: config.fingerDrawing,
|
|
onChanged: controller.setFingerDrawing,
|
|
contentPadding: EdgeInsets.zero,
|
|
),
|
|
|
|
// ── Stroke Widths ─────────────────────────────────────────
|
|
_SectionHeader(
|
|
title: 'Stroke Widths',
|
|
icon: Icons.line_weight,
|
|
colorScheme: colorScheme,
|
|
),
|
|
_SliderTile(
|
|
label: 'Pen Width',
|
|
value: config.penWidth,
|
|
min: 0.001,
|
|
max: 0.02,
|
|
divisions: 19,
|
|
formatValue: (v) => v.toStringAsFixed(4),
|
|
onChanged: controller.setPenWidth,
|
|
),
|
|
_SliderTile(
|
|
label: 'Highlighter Width',
|
|
value: config.highlighterWidth,
|
|
min: 0.005,
|
|
max: 0.06,
|
|
divisions: 22,
|
|
formatValue: (v) => v.toStringAsFixed(4),
|
|
onChanged: controller.setHighlighterWidth,
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
// ── Shared section header ────────────────────────────────────────────────────
|
|
|
|
class _SectionHeader extends StatelessWidget {
|
|
const _SectionHeader({
|
|
required this.title,
|
|
required this.icon,
|
|
required this.colorScheme,
|
|
});
|
|
|
|
final String title;
|
|
final IconData icon;
|
|
final ColorScheme colorScheme;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Padding(
|
|
padding: const EdgeInsets.only(top: 8, bottom: 4),
|
|
child: Row(
|
|
children: [
|
|
Icon(icon, size: 18, color: colorScheme.primary),
|
|
const SizedBox(width: 8),
|
|
Text(
|
|
title,
|
|
style: Theme.of(context).textTheme.titleSmall?.copyWith(
|
|
color: colorScheme.primary,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
const SizedBox(width: 8),
|
|
Expanded(child: Divider(color: colorScheme.outlineVariant)),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
// ── Label + widget row ───────────────────────────────────────────────────────
|
|
|
|
class _LabeledRow extends StatelessWidget {
|
|
const _LabeledRow({required this.label, required this.child});
|
|
|
|
final String label;
|
|
final Widget child;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Row(
|
|
children: [
|
|
SizedBox(
|
|
width: 120,
|
|
child: Text(
|
|
label,
|
|
style: const TextStyle(fontWeight: FontWeight.w500),
|
|
),
|
|
),
|
|
Expanded(child: child),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
// ── Action dropdown ──────────────────────────────────────────────────────────
|
|
|
|
class _ActionDropdown extends StatelessWidget {
|
|
const _ActionDropdown({required this.value, required this.onChanged});
|
|
|
|
final PenButtonAction value;
|
|
final ValueChanged<PenButtonAction> onChanged;
|
|
|
|
static String _label(PenButtonAction action) => switch (action) {
|
|
PenButtonAction.none => 'None',
|
|
PenButtonAction.eraser => 'Eraser',
|
|
PenButtonAction.undo => 'Undo',
|
|
PenButtonAction.toggleTool => 'Toggle Tool',
|
|
PenButtonAction.pan => 'Pan',
|
|
};
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return DropdownMenu<PenButtonAction>(
|
|
initialSelection: value,
|
|
expandedInsets: EdgeInsets.zero,
|
|
onSelected: (action) {
|
|
if (action != null) onChanged(action);
|
|
},
|
|
dropdownMenuEntries: PenButtonAction.values
|
|
.map(
|
|
(a) => DropdownMenuEntry(value: a, label: _label(a)),
|
|
)
|
|
.toList(),
|
|
);
|
|
}
|
|
}
|
|
|
|
// ── Slider with live value label ─────────────────────────────────────────────
|
|
|
|
class _SliderTile extends StatelessWidget {
|
|
const _SliderTile({
|
|
required this.label,
|
|
required this.value,
|
|
required this.min,
|
|
required this.max,
|
|
required this.divisions,
|
|
required this.formatValue,
|
|
required this.onChanged,
|
|
});
|
|
|
|
final String label;
|
|
final double value;
|
|
final double min;
|
|
final double max;
|
|
final int divisions;
|
|
final String Function(double) formatValue;
|
|
final ValueChanged<double> onChanged;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(label, style: const TextStyle(fontWeight: FontWeight.w500)),
|
|
Text(
|
|
formatValue(value),
|
|
style: TextStyle(
|
|
fontFamily: 'monospace',
|
|
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
|
fontSize: 13,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
Slider(
|
|
value: value.clamp(min, max),
|
|
min: min,
|
|
max: max,
|
|
divisions: divisions,
|
|
label: formatValue(value),
|
|
onChanged: onChanged,
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|