Skip to content

Take the zoom from the node editor rather than doing it here - #21

Merged
matt-edmondson merged 1 commit into
mainfrom
claude/auto-layout-expression-editor-ugcdvj
Sep 8, 2026
Merged

Take the zoom from the node editor rather than doing it here#21
matt-edmondson merged 1 commit into
mainfrom
claude/auto-layout-expression-editor-ugcdvj

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

ktsu.ImGui.NodeEditor 3.20.0 carries NodeEditorRenderer.Zoom and FitToView (ktsu-dev/ImGuiApp#359), so this application's own copy comes out. Net −197 lines.

What goes

EnterViewSpace, LeaveViewSpace, IsUnzoomed, the ViewState record and the dictionary it lived in, the fontScaled flag, the MinZoom/MaxZoom/FitMargin constants, and FittingZoom.

Zoom now forwards to renderer.Zoom rather than holding a second value beside it. FitView calls renderer.FitToView(Graph.Engine, Graph.Engine.WorldOrigin * 2f) and keeps its own return value and status message — the world origin is kept on the middle of the canvas, so twice the origin is the whole of it. The toolbar slider takes its bounds from NodeEditorRenderer.MinZoom/MaxZoom.

Why the library's is better, not just tidier

Three things the version here could not do from outside the renderer:

  • Nothing zoomed reaches the engine at all. The transform now sits at the seam between the engine and ImNodes. This application had to wrap it around the whole frame — scale the engine's positions, draw, unscale them — because from outside there was nowhere else to put it.
  • The node editor's own lengths scale too: padding, corner rounding, pin sizes, grid spacing. Unreachable from here, and visible — the background grid now shrinks with the graph instead of staying put underneath it.
  • A size measured while zoomed is no longer trusted as the node's size. The font size rounds to whole pixels and ImGui's spacing inside a node doesn't scale, so a measurement taken at 0.5× and scaled back is off by the padding. That is the part the copy here got wrong first time round, in the way that compounds: sizes only arrive when they change, so unscaling every frame re-divided the same value and within a second the nodes were thousands of times their real size.

Tests

328 passing (329 before; two zoom tests removed, one rewritten).

FitView_DoesNotMagnifyAGraphThatAlreadyFits only restated library behaviour, so it goes — the library tests it. The two kept are the ones the library cannot cover:

  • FitView_ZoomsOutUntilTheGraphFits now stands for the plumbing: that this application hands over the right canvas. Passing the wrong rectangle would fit the graph to the wrong thing and no library test would notice.
  • Zoom_IsTheRenderersOwn (was Zoom_IsHeldWithinTheRangeTheSliderOffers) asserts the property forwards, using the renderer's clamping as the evidence: a value it would refuse coming back changed is what says the property didn't just store what it was given.

Verified visually through the harness: the graph at 100%, at 50% with grid and node chrome scaled together, and back to 100% in exactly its original size and place.

🤖 Generated with Claude Code

https://claude.ai/code/session_01QwzCFb8zhd263sZeRbF7ba


Generated by Claude Code

…e [patch]

ktsu.ImGui.NodeEditor 3.20.0 has NodeEditorRenderer.Zoom and FitToView, so
this application's own copy comes out: EnterViewSpace, LeaveViewSpace,
IsUnzoomed, the ViewState record and its dictionary, the min/max/margin
constants, and FittingZoom. Zoom now forwards to the renderer's, and
FitView hands it the canvas — the world origin is kept on the middle of
the canvas, so twice the origin is the whole of it.

The library does it better than this could from outside. The transform now
sits at the seam between the engine and ImNodes rather than being wrapped
around the whole frame, so nothing zoomed ever reaches the engine at all
rather than being put back afterwards; the node editor's own lengths —
padding, corner rounding, pin sizes, grid spacing — scale with the text,
which is not reachable from here; and a size measured while zoomed is no
longer trusted as the node's size, which is what the version here got
wrong first time round.

Of the three tests, the two that only restated library behaviour go: what
is left is that the editor hands over the right canvas, which no test in
the library could catch, and that Zoom really is the renderer's rather
than a second value beside it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QwzCFb8zhd263sZeRbF7ba
@sonarqubecloud

sonarqubecloud Bot commented Sep 8, 2026

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit bd96c86 into main Sep 8, 2026
12 checks passed
@matt-edmondson
matt-edmondson deleted the claude/auto-layout-expression-editor-ugcdvj branch September 8, 2026 08:37
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.

2 participants