-
Notifications
You must be signed in to change notification settings - Fork 433
Fix ImageViewer overlapping images during zoom and pan operations #3944
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
87 changes: 87 additions & 0 deletions
87
tests/core/test/com/codename1/components/ImageViewerCoordinateTest.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| package com.codename1.components; | ||
|
|
||
| import com.codename1.testing.AbstractTest; | ||
| import com.codename1.ui.Image; | ||
| import com.codename1.ui.Form; | ||
|
|
||
| /** | ||
| * Test for ImageViewer overlapping images fix | ||
| */ | ||
| public class ImageViewerCoordinateTest extends AbstractTest { | ||
|
|
||
| @Override | ||
| public boolean shouldExecuteOnEDT() { | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean runTest() throws Exception { | ||
| testZoomAndPanCoordinateConsistency(); | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Test that coordinate calculations in updatePositions and paint methods are consistent | ||
| */ | ||
| public void testZoomAndPanCoordinateConsistency() throws Exception { | ||
| System.out.println("Testing ImageViewer coordinate consistency"); | ||
|
|
||
| // Create a test form and image viewer | ||
| Form testForm = new Form(); | ||
| ImageViewer viewer = new ImageViewer(); | ||
|
|
||
| // Create a large test image (bigger than typical screen) | ||
| Image testImage = Image.createImage(2000, 1500); | ||
| viewer.setImage(testImage); | ||
|
|
||
| // Set viewer size (simulate a typical mobile screen) | ||
| viewer.setX(50); // Not starting at 0,0 to test coordinate translation | ||
| viewer.setY(100); | ||
| viewer.setWidth(400); | ||
| viewer.setHeight(600); | ||
|
|
||
| // Add to form and lay out | ||
| testForm.addComponent(viewer); | ||
| testForm.show(); | ||
| testForm.revalidate(); | ||
|
|
||
| // Test scenario 1: High zoom with right pan | ||
| float zoom = 3.0f; | ||
| float panX = 0.8f; // Panned to the right | ||
| float panY = 0.5f; // Centered vertically | ||
|
|
||
| viewer.setZoom(zoom, panX, panY); | ||
|
|
||
| // The key test: verify that the image coordinates are properly constrained | ||
| // With the fix, the image should not extend beyond the viewer bounds | ||
| int imageX = viewer.getImageX(); | ||
| int imageY = viewer.getImageY(); | ||
|
|
||
| // Log the values for debugging | ||
| System.out.println("Zoom: " + zoom + ", PanX: " + panX + ", PanY: " + panY); | ||
| System.out.println("ImageX: " + imageX + ", ImageY: " + imageY); | ||
| System.out.println("Viewer bounds: X=" + viewer.getX() + ", Y=" + viewer.getY() + | ||
| ", W=" + viewer.getWidth() + ", H=" + viewer.getHeight()); | ||
|
|
||
| // Test scenario 2: Maximum reasonable zoom at far right | ||
| zoom = 5.0f; | ||
| panX = 1.0f; // Fully right | ||
| viewer.setZoom(zoom, panX, panY); | ||
|
|
||
| imageX = viewer.getImageX(); | ||
| imageY = viewer.getImageY(); | ||
|
|
||
| System.out.println("High zoom test - ImageX: " + imageX + ", ImageY: " + imageY); | ||
|
|
||
| // Test scenario 3: Test IMAGE_FILL mode to ensure it works with the fix | ||
| viewer.setImageInitialPosition(ImageViewer.IMAGE_FILL); | ||
| viewer.setZoom(2.0f, 0.9f, 0.5f); | ||
|
|
||
| imageX = viewer.getImageX(); | ||
| imageY = viewer.getImageY(); | ||
|
|
||
| System.out.println("IMAGE_FILL mode test - ImageX: " + imageX + ", ImageY: " + imageY); | ||
|
|
||
| System.out.println("ImageViewer coordinate consistency test completed successfully"); | ||
| } | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to have some asserts in this test to check and verify that the bug is fixed.