This repository has been archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix applyBoxFit's handling of fitWidth and fitHeight. (#117185)
* Fix applyBoxFit's handling of fitWidth and fitHeight. Previously, in `fitWidth` mode, if the input size had a wider aspect ratio than the output size, `applyBoxFit` would make the source rect taller than the input size in order to match the aspect ratio of the destination rect. Similarly, in `fitHeight` mode, if the input size had a taller aspect ratio than the output size, `applyBoxFit` would make the source rect wider than the input size in to match the aspect ratio of the destination rect. This is in contrast to all the other modes, which never output a source rect that's larger than the input size. Most of the time this worked as intended (since attempting to blit pixels that are outside the source image has no effect), however it meant that if a user attempted to create a `BoxDecoration` that used both `fitWidth` and `repeatY` (e.g. in an attempt to tile a background image), the image would not actually appear to repeat, since the logic in `paintImage` for determining the proper tiling stride is based on the destination image size, meaning that the entire destination rect would be covered in a single tile. This change modifies `applyBoxFit` so that in `fitWidth` mode, if the input size has a wider aspect ratio than the output size, it uses formulas that are equivalent to `contain`, whereas if the input size has a taller aspect ratio than the output size, it uses formulas that are equivalent to `cover`. And vice versa for `fitHeight` mode. This produces source and destination rects that match the behaviour specified in https://api.flutter.dev/flutter/painting/BoxFit.html. * Apply suggestions from code review Co-authored-by: Michael Goderbauer <goderbauer@google.com>
- Loading branch information
1 parent
6277520
commit 997d436
Showing
3 changed files
with
106 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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