Center Image inside available bounds when possible
This commit is contained in:
parent
0aff444941
commit
6822d1d9f2
1 changed files with 14 additions and 9 deletions
|
|
@ -6,7 +6,8 @@ use crate::image;
|
||||||
use crate::layout;
|
use crate::layout;
|
||||||
use crate::renderer;
|
use crate::renderer;
|
||||||
use crate::{
|
use crate::{
|
||||||
ContentFit, Element, Hasher, Layout, Length, Point, Rectangle, Size, Widget,
|
ContentFit, Element, Hasher, Layout, Length, Point, Rectangle, Size,
|
||||||
|
Vector, Widget,
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
|
|
@ -128,14 +129,18 @@ where
|
||||||
let bounds = layout.bounds();
|
let bounds = layout.bounds();
|
||||||
|
|
||||||
let render = |renderer: &mut Renderer| {
|
let render = |renderer: &mut Renderer| {
|
||||||
renderer.draw(
|
let offset = Vector::new(
|
||||||
self.handle.clone(),
|
(bounds.width - adjusted_fit.width).max(0.0) / 2.0,
|
||||||
Rectangle {
|
(bounds.height - adjusted_fit.height).max(0.0) / 2.0,
|
||||||
width: adjusted_fit.width,
|
);
|
||||||
height: adjusted_fit.height,
|
|
||||||
..layout.bounds()
|
let bounds = Rectangle {
|
||||||
},
|
width: adjusted_fit.width,
|
||||||
)
|
height: adjusted_fit.height,
|
||||||
|
..layout.bounds()
|
||||||
|
};
|
||||||
|
|
||||||
|
renderer.draw(self.handle.clone(), bounds + offset)
|
||||||
};
|
};
|
||||||
|
|
||||||
if adjusted_fit.width > bounds.width
|
if adjusted_fit.width > bounds.width
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue