Skip to content
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

ImageView doesn't shrink images to fit #2275

Closed
freakboy3742 opened this issue Dec 12, 2023 · 0 comments · Fixed by #2276
Closed

ImageView doesn't shrink images to fit #2275

freakboy3742 opened this issue Dec 12, 2023 · 0 comments · Fixed by #2276
Labels
bug A crash or error in behavior.

Comments

@freakboy3742
Copy link
Member

freakboy3742 commented Dec 12, 2023

Describe the bug

The documentation for ImageView says that a flex=1 image will be expanded or shrunk to fit the available space. It definitely expands images to fit, but a large image will not be shrunk to fit.

Steps to reproduce

Use the following app code:

        main_box = toga.Box(style=Pack(direction=ROW))

        main_box.add(toga.ImageView("image.png", style=Pack(flex=1)))

        self.main_window = toga.MainWindow(title=self.formal_name)
        self.main_window.content = main_box
        self.main_window.show()

if image.png is smaller than the window, it will be expanded; if image.py is larger than the window, the window will be expanded to fit the natural size of the window (or, on mobile, show "content doesn't fit window" warnings).

Expected behavior

An ImageView with flex=1 should shrink large images to fit the available space, preserving aspect ratio.

Screenshots

No response

Environment

  • Operating System: all (tested on macOS and iOS)
  • Python version: All
  • Software versions:
    • Toga: 0.4.0

Logs

No response

Additional context

The underlying problem appears to be that the intrinsic constraint has been set to at_least(size) in each axis, rather than at_least(0). This enforces a minimum size that can't be shrunk.

@freakboy3742 freakboy3742 added the bug A crash or error in behavior. label Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A crash or error in behavior.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant