Reduce nesting in Rectangle::offset
This commit is contained in:
parent
00e4de88bf
commit
61b96caf21
2 changed files with 19 additions and 20 deletions
|
|
@ -160,25 +160,25 @@ impl Rectangle<f32> {
|
|||
/// Computes the offset that must be applied to the [`Rectangle`] to be placed
|
||||
/// inside the given `container`.
|
||||
pub fn offset(&self, container: &Rectangle) -> Vector {
|
||||
if let Some(intersection) = self.intersection(container) {
|
||||
let left = intersection.x - self.x;
|
||||
let top = intersection.y - self.y;
|
||||
let Some(intersection) = self.intersection(container) else {
|
||||
return Vector::ZERO;
|
||||
};
|
||||
|
||||
Vector::new(
|
||||
if left > 0.0 {
|
||||
left
|
||||
} else {
|
||||
intersection.x + intersection.width - self.x - self.width
|
||||
},
|
||||
if top > 0.0 {
|
||||
top
|
||||
} else {
|
||||
intersection.y + intersection.height - self.y - self.height
|
||||
},
|
||||
)
|
||||
} else {
|
||||
Vector::ZERO
|
||||
}
|
||||
let left = intersection.x - self.x;
|
||||
let top = intersection.y - self.y;
|
||||
|
||||
Vector::new(
|
||||
if left > 0.0 {
|
||||
left
|
||||
} else {
|
||||
intersection.x + intersection.width - self.x - self.width
|
||||
},
|
||||
if top > 0.0 {
|
||||
top
|
||||
} else {
|
||||
intersection.y + intersection.height - self.y - self.height
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
/// Returns true if the current [`Rectangle`] is completely within the given
|
||||
|
|
|
|||
|
|
@ -211,8 +211,7 @@ fn card<'a>(
|
|||
.opacity(thumbnail.fade_in.interpolate(0.0, 1.0, now))
|
||||
.scale(thumbnail.zoom.interpolate(1.0, 1.1, now))
|
||||
.translate(move |bounds, viewport| {
|
||||
let final_bounds = bounds.zoom(1.1);
|
||||
final_bounds.offset(&viewport.shrink(10))
|
||||
bounds.zoom(1.1).offset(&viewport.shrink(10))
|
||||
* thumbnail.zoom.interpolate(0.0, 1.0, now)
|
||||
})
|
||||
.style(move |_theme| image::Style {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue