Skip to content

fix: add margin around modules when zooming (#61) - #62

Merged
charlesangus merged 1 commit into
mainfrom
fix/issue-61-module-zoom-margin
Jun 15, 2026
Merged

charlesangus merged 1 commit into
mainfrom
fix/issue-61-module-zoom-margin

Conversation

@charlesangus

Copy link
Copy Markdown
Owner

Closes #61.

Problem

Navigating to a module (an anchor plus its upstream nodes) framed the nodes edge-to-edge with no breathing room. Backdrops, by contrast, look well-framed because the backdrop node is physically larger than its contents, leaving natural margin.

Root cause

navigate_to_anchor() selects the module nodes and calls nuke.zoomToFitSelected(), which fits the selection's bounding box to fill the viewport with no padding. Nuke's API exposes no margin/padding parameter for that call.

Fix

Apply the margin as a post-fit zoom-out. After zoomToFitSelected(), read the resulting scale and center and re-zoom by a factor:

fitted_scale = nuke.zoom()
fitted_center = nuke.center()
nuke.zoom(fitted_scale * MODULE_ZOOM_MARGIN_FACTOR, fitted_center)

MODULE_ZOOM_MARGIN_FACTOR = 0.85 (new constant in constants.py) leaves ~7.5% of the viewport as margin on each side — roughly 100–200px on a typical DAG panel, matching the issue request — and adapts to any panel size rather than hard-coding a pixel count.

Alternatives considered

  • Fixed-pixel margin via Qt viewport query: would honor "100–200px" literally, but requires locating the DAG QWidget reliably across Nuke versions/docked panels and is much harder to unit-test. The proportional factor lands in the requested range with far less fragility.

Tests

  • test_zooms_out_for_margin_after_fit — verifies a single re-zoom at fitted_scale * MODULE_ZOOM_MARGIN_FACTOR with the fitted center.
  • test_margin_zoom_out_happens_after_fit — verifies ordering (fit first, margin zoom-out last).
  • setUp/tearDown hardened to reset shared zoom mocks so the new side_effects don't leak across test classes.

Full suite: 484 passed.

UAT

Pending — to be performed in Nuke by the maintainer (navigate to a module via Alt+A / leader key; confirm visible margin; confirm back-navigation and link-cycling still work).

navigate_to_anchor() framed the module (anchor + upstream nodes) with
nuke.zoomToFitSelected(), which fits the selection edge-to-edge with no
padding, so navigating to a module read as too tight.

Nuke's zoomToFitSelected() has no margin parameter, so apply the margin
as a post-fit zoom-out: after fitting, read the resulting scale/center
and re-zoom by MODULE_ZOOM_MARGIN_FACTOR (0.85). This leaves ~7.5% of
the viewport as margin per side (~100-200px on a typical DAG panel) and
adapts to any panel size, matching the breathing room backdrops have.
Copilot AI review requested due to automatic review settings June 15, 2026 21:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes overly tight framing when navigating to a module (anchor + upstream nodes) by adding post-fit “breathing room” around the selection, matching the nicer framing users see with backdrops.

Changes:

  • Add a new MODULE_ZOOM_MARGIN_FACTOR constant to apply proportional zoom-out margin after nuke.zoomToFitSelected().
  • Update navigate_to_anchor() to re-zoom after fitting using the fitted zoom + center as a baseline.
  • Extend navigation tests to verify the margin zoom-out behavior and ensure zoom/fit mocks don’t leak side_effects across tests.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
anchor.py Applies a post-zoomToFitSelected() zoom-out using fitted zoom/center to create module margin.
constants.py Introduces MODULE_ZOOM_MARGIN_FACTOR = 0.85 with rationale and framing notes.
tests/test_anchor_navigation.py Adds tests for margin zoom-out behavior and hardens mock reset/cleanup to prevent leakage.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@charlesangus
charlesangus merged commit 8e6b0be into main Jun 15, 2026
1 check passed
@charlesangus
charlesangus deleted the fix/issue-61-module-zoom-margin branch June 15, 2026 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Need margin around modules when zooming

2 participants