-
Notifications
You must be signed in to change notification settings - Fork 112
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
feat(#574): reimplementation of Image
widget layout
function
#605
Open
failingprovince
wants to merge
4
commits into
linebender:main
Choose a base branch
from
failingprovince:issue-574
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
23855b2
feat(#574): `Image` widget layout reimplementation
failingprovince 172b810
feat(#574): add tests
failingprovince e8dcd0b
fix(#574): rename `FillStrat` to `ObjectFit`
failingprovince 8fb39c2
fix(#574): replace `FillStrat` in documentation
failingprovince 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 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,7 +61,7 @@ | |
// These are based on https://api.flutter.dev/flutter/painting/BoxFit-class.html | ||
/// Strategies for inscribing a rectangle inside another rectangle. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we link to https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit in these docs? |
||
#[derive(Clone, Copy, Default, PartialEq)] | ||
pub enum FillStrat { | ||
pub enum ObjectFit { | ||
/// As large as possible without changing aspect ratio of image and all of image shown | ||
#[default] | ||
Contain, | ||
|
@@ -81,8 +81,8 @@ | |
|
||
// TODO - Need to write tests for this, in a way that's relatively easy to visualize. | ||
|
||
impl FillStrat { | ||
impl ObjectFit { | ||
/// Calculate an origin and scale for an image with a given `FillStrat`. | ||
/// | ||
/// This takes some properties of a widget and a fill strategy and returns an affine matrix | ||
/// used to position and scale the image in the widget. | ||
|
@@ -91,22 +91,22 @@ | |
let raw_scaley = parent.height / fit_box.height; | ||
|
||
let (scalex, scaley) = match self { | ||
FillStrat::Contain => { | ||
ObjectFit::Contain => { | ||
let scale = raw_scalex.min(raw_scaley); | ||
(scale, scale) | ||
} | ||
FillStrat::Cover => { | ||
ObjectFit::Cover => { | ||
let scale = raw_scalex.max(raw_scaley); | ||
(scale, scale) | ||
} | ||
FillStrat::Fill => (raw_scalex, raw_scaley), | ||
FillStrat::FitHeight => (raw_scaley, raw_scaley), | ||
FillStrat::FitWidth => (raw_scalex, raw_scalex), | ||
FillStrat::ScaleDown => { | ||
ObjectFit::Fill => (raw_scalex, raw_scaley), | ||
ObjectFit::FitHeight => (raw_scaley, raw_scaley), | ||
ObjectFit::FitWidth => (raw_scalex, raw_scalex), | ||
ObjectFit::ScaleDown => { | ||
let scale = raw_scalex.min(raw_scaley).min(1.0); | ||
(scale, scale) | ||
} | ||
FillStrat::None => (1.0, 1.0), | ||
ObjectFit::None => (1.0, 1.0), | ||
}; | ||
|
||
let origin_x = (parent.width - (fit_box.width * scalex)) / 2.0; | ||
|
@@ -115,13 +115,3 @@ | |
Affine::new([scalex, 0., 0., scaley, origin_x, origin_y]) | ||
} | ||
} | ||
|
||
// TODO - remove prelude | ||
#[allow(missing_docs)] | ||
pub mod prelude { | ||
#[doc(hidden)] | ||
pub use crate::{ | ||
BoxConstraints, EventCtx, LayoutCtx, LifeCycle, LifeCycleCtx, PaintCtx, PointerEvent, Size, | ||
StatusChange, TextEvent, Widget, WidgetId, | ||
}; | ||
} |
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
Oops, something went wrong.
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.
Should we rename this field? I'd suggest either
fit
orobject_fit
?