Scale background appropriately

This commit is contained in:
Jeremy Soller 2023-10-06 20:24:03 -06:00
parent e028c2eac5
commit 55ef1dc54f
No known key found for this signature in database
GPG key ID: DCFCA852D3906975
3 changed files with 15 additions and 2 deletions

View file

@ -655,6 +655,7 @@ impl cosmic::Application for App {
.style(cosmic::theme::Container::Transparent),
)
.image(self.flags.background.clone())
.content_fit(iced::ContentFit::Cover)
.into()
}
}

View file

@ -1,4 +1,8 @@
use cosmic::iced::widget::{image::Handle, Container};
use cosmic::iced::widget::{
image::{draw, Handle},
Container,
};
use cosmic::iced::ContentFit;
use cosmic::iced_core::event::{self, Event};
use cosmic::iced_core::layout;
use cosmic::iced_core::mouse;
@ -17,6 +21,7 @@ where
{
container: Container<'a, Message, Renderer>,
image_opt: Option<Handle>,
content_fit: ContentFit,
}
impl<'a, Message, Renderer> ImageContainer<'a, Message, Renderer>
@ -28,6 +33,7 @@ where
Self {
container,
image_opt: None,
content_fit: ContentFit::None,
}
}
@ -35,6 +41,11 @@ where
self.image_opt = Some(image);
self
}
pub fn content_fit(mut self, content_fit: ContentFit) -> Self {
self.content_fit = content_fit;
self
}
}
impl<'a, Message, Renderer> Widget<Message, Renderer> for ImageContainer<'a, Message, Renderer>
@ -111,7 +122,7 @@ where
viewport: &Rectangle,
) {
match &self.image_opt {
Some(image) => renderer.draw(image.clone(), layout.bounds()),
Some(image) => draw(renderer, layout, image, self.content_fit),
None => {}
}

View file

@ -524,6 +524,7 @@ impl cosmic::Application for App {
.style(cosmic::theme::Container::Transparent),
)
.image(self.flags.background.clone())
.content_fit(iced::ContentFit::Cover)
.into()
}