Review: adaptive window resizing and image centering on zoom#531
Closed
armm77 wants to merge 1 commit into
Closed
Conversation
When the user changes the zoom level (via the scale popup or the new
Cmd+= / Cmd+- keyboard shortcuts), the window now resizes automatically
to follow the image:
- Zoom out: window shrinks to fit the scaled image, minimum 200×200 px.
- Zoom in: window grows with the image up to a hard cap of 70% of the
screen width and 70% of the screen height. Beyond that cap zooming
continues normally and scroll bars become active.
- The window center is kept fixed on every resize; if the result would
go off-screen it is clamped to the visible area.
- The same 70% rule is applied when an image is first opened, replacing
the previous ad-hoc margin calculations.
When the scaled image is smaller than the scroll view's visible area the
image view is expanded to fill that area so that NSImageAlignCenter keeps
the image horizontally and vertically centered instead of drifting to a
corner.
Zoom In / Zoom Out are wired to the existing Display menu items at
launch (Cmd+= and Cmd+-). The items are disabled automatically when no
image window is open.
trunkmaster
requested changes
May 19, 2026
trunkmaster
left a comment
Owner
There was a problem hiding this comment.
Nice work. Please see my comments.
Comment on lines
+40
to
+58
| NSMenu *mainMenu = [NSApp mainMenu]; | ||
| NSMenuItem *displayItem = (NSMenuItem *)[mainMenu itemWithTitle:@"Display"]; | ||
| if (displayItem) { | ||
| NSMenu *displayMenu = [displayItem submenu]; | ||
| NSMenuItem *zoomInItem = (NSMenuItem *)[displayMenu itemWithTitle:@"Zoom In"]; | ||
| NSMenuItem *zoomOutItem = (NSMenuItem *)[displayMenu itemWithTitle:@"Zoom Out"]; | ||
| if (zoomInItem) { | ||
| [zoomInItem setTarget:self]; | ||
| [zoomInItem setAction:@selector(zoomIn:)]; | ||
| [zoomInItem setKeyEquivalent:@"="]; | ||
| [zoomInItem setKeyEquivalentModifierMask:NSCommandKeyMask]; | ||
| } | ||
| if (zoomOutItem) { | ||
| [zoomOutItem setTarget:self]; | ||
| [zoomOutItem setAction:@selector(zoomOut:)]; | ||
| [zoomOutItem setKeyEquivalent:@"-"]; | ||
| [zoomOutItem setKeyEquivalentModifierMask:NSCommandKeyMask]; | ||
| } | ||
| } |
Owner
There was a problem hiding this comment.
It's better to change .gorm. No need to add any code.
|
|
||
| NSRect newFrame = [NSWindow frameRectForContentRect:NSMakeRect(0, 0, contentSize.width, contentSize.height) | ||
| styleMask:[_window styleMask]]; | ||
|
|
Owner
There was a problem hiding this comment.
You need to get ScrollView frame first. Here you got window frame based on image size excluding scroll view controls. You may check it if open image smaller then screen size (no scroller knobs visible), zoom it out (90%, scroller knobs appears), zoom it in (100%, scroller knobs still visible).
Comment on lines
+348
to
+351
| if (newFrame.origin.x < sf.origin.x) newFrame.origin.x = sf.origin.x; | ||
| if (newFrame.origin.y < sf.origin.y) newFrame.origin.y = sf.origin.y; | ||
| if (NSMaxX(newFrame) > NSMaxX(sf)) newFrame.origin.x = NSMaxX(sf) - newFrame.size.width; | ||
| if (NSMaxY(newFrame) > NSMaxY(sf)) newFrame.origin.y = NSMaxY(sf) - newFrame.size.height; |
Owner
There was a problem hiding this comment.
I've noticed window center drifting if you try to zoom in large image. Please check if this code is correct.
Collaborator
Author
|
@trunkmaster, Thanks for checking, I'll make another change. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the user changes the zoom level (via the scale popup or the new
Cmd+= / Cmd+- keyboard shortcuts), the window now resizes automatically
to follow the image:
When the scaled image is smaller than the scroll view's visible area the
image view is expanded to fill that area so that NSImageAlignCenter keeps
the image horizontally and vertically centered instead of drifting to a
corner.
Zoom In / Zoom Out are wired to the existing Display menu items at
launch (Cmd+= and Cmd+-). The items are disabled automatically when no
image window is open.