Skip to content

Conversation

@HalfWhitt
Copy link
Member

Fixes #4044

Adding the test first...

So far I have a fix that seems to work for Cocoa, but breaks iOS in new and interesting ways.

PR Checklist:

  • All new features have been tested
  • All new features have been documented
  • I have read the CONTRIBUTING.md file
  • I will abide by the code of conduct

@HalfWhitt
Copy link
Member Author

HalfWhitt commented Jan 1, 2026

This is odd... from both Linux Wayland Gtk4 tests (with and without adwaita):

 File "/home/runner/work/toga/toga/testbed/build/testbed/ubuntu/noble/testbed-0.0.1/usr/lib/testbed/app/tests/widgets/test_canvas.py", line 715, in test_reset_transform
    screenshot = canvas.window.as_image(format=Image.Image).crop((0, 0, 200, 200))
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/toga/toga/testbed/build/testbed/ubuntu/noble/testbed-0.0.1/usr/lib/testbed/app_packages/toga/window.py", line 619, in as_image
    return Image(self._impl.get_image_data()).as_format(format)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/toga/toga/testbed/build/testbed/ubuntu/noble/testbed-0.0.1/usr/lib/testbed/app_packages/toga/images.py", line 194, in __init__
    raise TypeError("Unsupported source type for Image")

And the screenshot on Linux Wayland Gtk3 is just... entirely transparent. Great.

Edit: didn't realize some platforms don't support Window.as_image(). That's fine, I should only be testing that step on Cocoa and iOS anyway.

)

inverse_transform = core_graphics.CGAffineTransformInvert(transform)
if inverse_transform == transform:
Copy link
Contributor

@corranwebster corranwebster Jan 1, 2026

Choose a reason for hiding this comment

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

This is also true for the identity transform and a few others which are their own inverses (like (-1, 0, 0, -1, 0, 0) and (-1, 0, 0, 1, 0, 0)).

Edit: to be constructive, I think it suffices to check if the determinant a * d - b * c == 0.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm. As I understand it, if the transform (relative to the original) is the identity matrix, then the current would equal the original and we would've already exited. But I hadn't actually realized other matrices are their own inverse as well, thanks! Math is wild.

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.

Cocoa/iOS Canvas reset_transform incorrect behavior

2 participants