From eda0ee60063b73f57998f00b5bf4ddc5737aa218 Mon Sep 17 00:00:00 2001 From: Akiba So Date: Tue, 23 Jun 2026 03:43:44 +0800 Subject: [PATCH] refactor: pen_editor_screen._centerPage uses shared centerOffset MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Wires the now-tested viewport_fit.centerOffset into the live editor, replacing the inline ad-hoc arithmetic. Behavior-identical (same centering at scale 1) — makes the pure core load-bearing and kills the duplicate math. flutter analyze lib/editor clean; 228/228 tests pass (no behavior change). Co-Authored-By: Claude Opus 4.8 (1M context) --- lib/editor/canvas/pen_editor_screen.dart | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/editor/canvas/pen_editor_screen.dart b/lib/editor/canvas/pen_editor_screen.dart index c48e87b..b09a882 100644 --- a/lib/editor/canvas/pen_editor_screen.dart +++ b/lib/editor/canvas/pen_editor_screen.dart @@ -15,6 +15,7 @@ import '../engine/undo_stack.dart'; import '../input/diagnostic_logger.dart'; import '../input/pen_config.dart'; import '../input/pen_input_service.dart'; +import '../layout/viewport_fit.dart'; import '../persistence/editor_repository.dart'; import '../persistence/save_scheduler.dart'; import '../ui/pen_settings_page.dart'; @@ -381,11 +382,12 @@ class _PenEditorScreenState extends State { showPenSettingsSheet(context, config); } - /// Centre [pageSize] within [viewport] via the shared transform. + /// Centre [pageSize] within [viewport] via the shared transform. Uses the + /// shared, unit-tested [centerOffset] (pageSize is already fit to the viewport + /// at scale 1, so we center at scale 1). void _centerPage(Size viewport, Size pageSize) { - final tx = (viewport.width - pageSize.width) / 2; - final ty = (viewport.height - pageSize.height) / 2; - _transform.value = Matrix4.identity()..setTranslationRaw(tx, ty, 0); + final o = centerOffset(pageSize, viewport, 1.0); + _transform.value = Matrix4.identity()..setTranslationRaw(o.dx, o.dy, 0); } @override