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

Enforce min layout size as window size #2020

Merged
merged 30 commits into from
Aug 15, 2023

Conversation

freakboy3742
Copy link
Member

@freakboy3742 freakboy3742 commented Jul 2, 2023

On every platform other than GTK, Toga computes an initial minimum layout when a window is first displayed, and applies that minimum size. If the layout changes, the minimum is never recomputed.

This is at least in part because computing the minimum size requires a second run through the layout algorithm.

GTK does do a second layout pass on every layout change... but there's no reason we can't track the minimum size at the same time we're computing the actual layout.

This PR modifies the Pack algorithm to compute the minimum possible layout at the same time as performing actual layout. When a layout has been applied, this the minimum size is then updated onto the window as a new minimum size constraint. On desktop, if that size is larger than the current window size, the window is made larger. On mobile, the window size can't change, so a warning is logged if the minimum layout size exceeds the available size.

This builds on #1996, as it requires the new Container handling. As part of the change, viewport has been completely removed, and Pack calculations have been made scale independent. The layout is now done in an ideal, 96dpi coordinate system; all user-provided sizes are assumed to be in that coordinate system. If the runtime device and platform uses has a different density (something that affects Windows and Android; GTK, cocoa and iOS autoscale to 96dpi equivalents), any container sizing or widget intrinsic size hints provided to the layout algorithm must be scaled into 96dpi layout-compatible sizing, and then scaled back to device coordinates when applied.

This PR requires beeware/travertino#78, adding min size tracking to layout.

Fixes:

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

@mhsmith
Copy link
Member

mhsmith commented Jul 4, 2023

Other things that should be addressed in this PR:

dummy/src/toga_dummy/widgets/base.py Outdated Show resolved Hide resolved
cocoa/src/toga_cocoa/container.py Outdated Show resolved Hide resolved
@freakboy3742 freakboy3742 mentioned this pull request Jul 7, 2023
42 tasks
@freakboy3742 freakboy3742 force-pushed the min-width-no-scale branch 2 times, most recently from 7380035 to 02b4c35 Compare August 1, 2023 08:18
@freakboy3742 freakboy3742 mentioned this pull request Aug 6, 2023
4 tasks
@mhsmith mhsmith marked this pull request as ready for review August 11, 2023 07:30
@mhsmith
Copy link
Member

mhsmith commented Aug 14, 2023

Done.

  • On Winforms, there is a known bug that the minimum window height is too short because it doesn't take the menu bar and toolbar into account. For example, see examples/resize.

Fixed.

The original issue is now fixed (though possibly by an earlier PR), so I've added it to the "fixes" list above.

However, it looks like there's a bug with Pack propagating minimum sizes through intermediate boxes. Try the example at #968 (comment). The inner Box height is unspecified, so it now correctly has a constant height of 100 (from the MultilineTextInput's minimum size), and the minimum window height is also correct. And if I set the inner Box to flex=1, it correctly expands to fill the extra space. But then the minimum height of the window doesn’t take account of the MultiLineTextInput anymore, only the Button. This behavior is the same on both Cocoa and Winforms.

@freakboy3742
Copy link
Member Author

However, it looks like there's a bug with Pack propagating minimum sizes through intermediate boxes.

Confirmed I can reproduce this problem; still digging to find the cause.

@freakboy3742
Copy link
Member Author

However, it looks like there's a bug with Pack propagating minimum sizes through intermediate boxes.

Confirmed I can reproduce this problem; still digging to find the cause.

Found it - the minimum allocation of grandchildren wasn't being propagated into the minimum size of flexible children. Fix and test pushed.

Copy link
Member

@mhsmith mhsmith left a comment

Choose a reason for hiding this comment

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

I've fixed the Android JavaScript problem, and all tests are now passing in CI with the second most recent commit.

The final commit isn't passing yet because Travertino 0.3.0 doesn't exist yet, but it should pass on a rerun once it's been released (beeware/travertino#78 (comment)).

@freakboy3742 freakboy3742 merged commit 6096823 into beeware:main Aug 15, 2023
@freakboy3742 freakboy3742 deleted the min-width-no-scale branch August 15, 2023 23:40
@freakboy3742 freakboy3742 mentioned this pull request Sep 13, 2023
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants