fixed aspect ratio layout
This commit is contained in:
parent
dc353bac63
commit
22ecdca784
2 changed files with 12 additions and 4 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -1419,7 +1419,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "iced_video_player"
|
||||
version = "0.1.1"
|
||||
version = "0.1.3"
|
||||
dependencies = [
|
||||
"glib",
|
||||
"gstreamer",
|
||||
|
|
|
@ -70,12 +70,20 @@ where
|
|||
limits: &layout::Limits,
|
||||
) -> layout::Node {
|
||||
let (width, height) = self.video.size();
|
||||
let (width, height) = (width as f32, height as f32);
|
||||
let size = limits.resolve(
|
||||
iced::Length::Shrink,
|
||||
iced::Length::Shrink,
|
||||
iced::Size::new(width as _, height as _),
|
||||
iced::Length::Fill,
|
||||
iced::Length::Fill,
|
||||
iced::Size::new(width, height),
|
||||
);
|
||||
|
||||
// fixed aspect ratio + never exceed available size
|
||||
let size = if (size.width / size.height) > (width / height) {
|
||||
iced::Size::new(size.height * (width / height), size.height)
|
||||
} else {
|
||||
iced::Size::new(size.width, size.width * (height / width))
|
||||
};
|
||||
|
||||
layout::Node::new(size)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue