Skip to content

fix: refit images after canvas layout changes - #2634

Merged
wkentaro merged 4 commits into
mainfrom
fix/fit-window-layout
Sep 6, 2026
Merged

wkentaro merged 4 commits into
mainfrom
fix/fit-window-layout

Conversation

@wkentaro

@wkentaro wkentaro commented Sep 6, 2026

Copy link
Copy Markdown
Owner

Fixes the Fit to Window regression introduced by #2524 (659c2e68): the urban-plaza image opened at 40.2% with fit selected, despite requiring 95.4% to fill the available canvas. The same reproduction passes on v7.4.1 and the introducing commit's parent.

Before After
Before After

Fit modes now follow layout changes and recompute when navigating between images. Saved pan and scroll positions are restored in every zoom mode after the fitted scale is recalculated.

Validation: 46 targeted tests passed across zoom, empty-state, window-geometry persistence, and middle-drag scrolling; Ruff, gruff, and type checks passed. Desktop verification covered startup, window resizing, navigation, retained manual zoom, and Fit Width scroll restoration (240 → 240). Dock resizing is covered by automated Qt tests; native pointer automation could not drive the dock divider.

The changelog entry covers dock resizing and navigation behavior reproduced on released v7.4.1; the startup regression itself was unreleased.

The stacked empty-state layout introduced in #2524 resizes its scroll
area after the outer window resize event. Initial fitting therefore
used a stale 640x480 area and left Fit to Window selected at 40.2%.

Observe scroll-area resizing and recompute saved fit modes against the
current image and available space. Preserve manual zoom and pan, with
regressions for startup, dock resizing, and image navigation.
@wkentaro wkentaro self-assigned this Sep 6, 2026
Record the corrected fit behavior for startup, layout changes, and
image navigation in the release notes.
@wkentaro
wkentaro marked this pull request as ready for review September 6, 2026 11:44
@wkentaro wkentaro added recommend-merge pr: Agent finalized and endorses it: review and merge and removed recommend-merge pr: Agent finalized and endorses it: review and merge labels Sep 6, 2026
The introducing commit is not contained in any release tag. Omit the
fragment for the startup regression fixed before the next release.
@wkentaro wkentaro added recommend-merge pr: Agent finalized and endorses it: review and merge and removed recommend-merge pr: Agent finalized and endorses it: review and merge labels Sep 6, 2026
@wkentaro

wkentaro commented Sep 6, 2026

Copy link
Copy Markdown
Owner Author

Verdict: request changes. Worth adding, but not ready to merge. Reviewed head 4f07e66af768ae4a69ded674b07a1b2819e978e0.

  • P2 — Navigation loses pan/scroll in fit modes. The new restoration guard restores positions only in manual zoom, although the pan and scroll handlers leave fit mode selected. Reproduced with real Qt widgets, two 400×800 images, an 800×600 window, and keep_prev_scale=False: select Fit Width, scroll down, then navigate next/previous. Base restores vertical scroll position 240 → 240; this PR resets 240 → 0. Fit Window pan likewise restores (17, 23) → (17, 23) on base but resets to (0, 0) here. Preserve saved pan/scroll positions while recalculating fitted scale.

  • P3 — Missing changelog fragment. AGENTS.md requires a towncrier fragment for user-facing application changes. The startup regression is unreleased, but the navigation and resize behavior changed here is also present in released v7.4.1. Restore a fragment covering those fixes.

Worth adding and minimal: Yes. The production diff is small, reuses existing scale calculations, and observes the relevant widget through native Qt event handling. No new dependencies or speculative abstractions.

Test quality: The added tests are meaningful integration tests, consistent with preferring integrated coverage over excessive unit testing. They exercise real application loading, Qt layout, window/dock resizing, and navigation, with geometric assertions rather than mocked calls. Seven of the nine added parameter cases fail against the base and all nine pass on the PR. However, changing the existing retained-brightness pan test to enter manual zoom hides the fit-mode pan regression. Retain coverage for panning while fitted, and cover Fit Width scroll restoration.

Validation: 42 targeted tests passed on the PR; targeted Ruff formatting/lint, Gruff, and type checks passed. Regression comparisons used Qt's offscreen platform and real application handlers; native desktop QA and the exact historical 40.2% → 95.4% reproduction were not independently repeated. Removed the existing recommend-merge label pending correction.

Pan and scroll do not switch the canvas to manual zoom. Restore their
saved positions after recalculating fit scale, including when previous
zoom is retained. Keep the fitted brightness-navigation regression and
cover Fit Width scroll restoration and Fit Window pan restoration.

Restore a release note scoped to dock resizing and navigation: these
behaviors also fail on v7.4.1, unlike the unreleased startup regression.
@wkentaro

wkentaro commented Sep 6, 2026

Copy link
Copy Markdown
Owner Author

Addressed both findings in f491c33.

  • P2: Restored position handling for every zoom mode after fitted scale recalculation. Reverted the retained-brightness test's forced switch to manual zoom, and added Fit Window pan / Fit Width scroll restoration coverage with Keep Previous Zoom both enabled and disabled. All five affected cases fail on the previous PR head and pass with the correction. Native desktop navigation now restores Fit Width scroll 240 → 240.

  • P3: Restored changelog.d/2634.fixed.md, scoped to dock resizing and navigation. I verified six existing regression cases fail against released v7.4.1 (using a test-only alias for the old scroll-area accessor). My earlier removal treated the whole PR as an unreleased startup fix; that missed the shipped behavior also corrected here.

Validation: 46 targeted tests passed, plus Ruff formatting/lint, gruff, type checking, and fragment formatting. The existing startup before/after screenshots remain valid; the additional navigation correction is covered by the regression tests and desktop check above.

@wkentaro wkentaro added the recommend-merge pr: Agent finalized and endorses it: review and merge label Sep 6, 2026
@wkentaro

wkentaro commented Sep 6, 2026

Copy link
Copy Markdown
Owner Author

Re-review verdict: recommend merge after required CI passes. Reviewed f491c332a35691b3d09827258db10fb24d12e0c0. No remaining verified findings; both previous findings are addressed.

  • Correctness: Fitted scale is recalculated before restoring saved positions in every zoom mode. Independently verified Fit Width scroll 240 → 240 and Fit Window pan (17, 23) → (17, 23) using real application handlers and Qt event processing, with Keep Previous Zoom enabled and disabled. The changelog fragment is restored.

  • Value and minimality: Worth adding. The implementation addresses layout timing and navigation with existing scale calculations and native Qt event handling. The correction removes the unnecessary restoration guard; no additional abstraction is needed.

  • Tests: Meaningful integration coverage, consistent with preferring integrated tests over excessive unit testing. The original fitted-pan/brightness test is restored, and four parameterized cases cover fitted positions across both retention settings. All five affected cases fail against the previous PR head and pass on this revision.

Validation: 46 targeted tests passed, plus targeted Ruff formatting/lint, Gruff, and type checks. Completed CI jobs pass; macOS test and artifact-install jobs remain queued at review time. This re-review used Qt's offscreen platform; native desktop QA was not repeated.

@wkentaro
wkentaro merged commit 4aea82e into main Sep 6, 2026
21 checks passed
@wkentaro
wkentaro deleted the fix/fit-window-layout branch September 6, 2026 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

recommend-merge pr: Agent finalized and endorses it: review and merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant