mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-08-17 14:51:04 +02:00
refactor: take reference into image provider
This commit is contained in:
parent
df4bfc83d0
commit
cc6f21ed68
7 changed files with 11 additions and 10 deletions
|
@ -13,7 +13,7 @@ pub fn new_icon_button(input: &str, icon_theme: &IconTheme, size: i32) -> Button
|
||||||
image.add_class("icon");
|
image.add_class("icon");
|
||||||
|
|
||||||
match ImageProvider::parse(input, icon_theme, false, size)
|
match ImageProvider::parse(input, icon_theme, false, size)
|
||||||
.map(|provider| provider.load_into_image(image.clone()))
|
.map(|provider| provider.load_into_image(&image))
|
||||||
{
|
{
|
||||||
Some(_) => {
|
Some(_) => {
|
||||||
button.set_image(Some(&image));
|
button.set_image(Some(&image));
|
||||||
|
@ -42,7 +42,7 @@ pub fn new_icon_label(input: &str, icon_theme: &IconTheme, size: i32) -> gtk::Bo
|
||||||
container.add(&image);
|
container.add(&image);
|
||||||
|
|
||||||
ImageProvider::parse(input, icon_theme, false, size)
|
ImageProvider::parse(input, icon_theme, false, size)
|
||||||
.map(|provider| provider.load_into_image(image));
|
.map(|provider| provider.load_into_image(&image));
|
||||||
} else {
|
} else {
|
||||||
let label = Label::builder().use_markup(true).label(input).build();
|
let label = Label::builder().use_markup(true).label(input).build();
|
||||||
label.add_class("icon");
|
label.add_class("icon");
|
||||||
|
|
|
@ -141,7 +141,7 @@ impl<'a> ImageProvider<'a> {
|
||||||
|
|
||||||
/// Attempts to fetch the image from the location
|
/// Attempts to fetch the image from the location
|
||||||
/// and load it into the provided `GTK::Image` widget.
|
/// and load it into the provided `GTK::Image` widget.
|
||||||
pub fn load_into_image(&self, image: gtk::Image) -> Result<()> {
|
pub fn load_into_image(&self, image: >k::Image) -> Result<()> {
|
||||||
// handle remote locations async to avoid blocking UI thread while downloading
|
// handle remote locations async to avoid blocking UI thread while downloading
|
||||||
#[cfg(feature = "http")]
|
#[cfg(feature = "http")]
|
||||||
if let ImageLocation::Remote(url) = &self.location {
|
if let ImageLocation::Remote(url) = &self.location {
|
||||||
|
@ -157,6 +157,7 @@ impl<'a> ImageProvider<'a> {
|
||||||
|
|
||||||
{
|
{
|
||||||
let size = self.size;
|
let size = self.size;
|
||||||
|
let image = image.clone();
|
||||||
glib_recv_mpsc!(rx, bytes => {
|
glib_recv_mpsc!(rx, bytes => {
|
||||||
let stream = MemoryInputStream::from_bytes(&bytes);
|
let stream = MemoryInputStream::from_bytes(&bytes);
|
||||||
|
|
||||||
|
@ -181,11 +182,11 @@ impl<'a> ImageProvider<'a> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self.load_into_image_sync(&image)?;
|
self.load_into_image_sync(image)?;
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(not(feature = "http"))]
|
#[cfg(not(feature = "http"))]
|
||||||
self.load_into_image_sync(&image)?;
|
self.load_into_image_sync(image)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ impl CustomWidget for ImageWidget {
|
||||||
|
|
||||||
dynamic_string(&self.src, move |src| {
|
dynamic_string(&self.src, move |src| {
|
||||||
ImageProvider::parse(&src, &icon_theme, false, self.size)
|
ImageProvider::parse(&src, &icon_theme, false, self.size)
|
||||||
.map(|image| image.load_into_image(gtk_image.clone()));
|
.map(|image| image.load_into_image(>k_image));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -156,7 +156,7 @@ impl Module<gtk::Box> for FocusedModule {
|
||||||
if let Some((name, id)) = data {
|
if let Some((name, id)) = data {
|
||||||
if self.show_icon {
|
if self.show_icon {
|
||||||
match ImageProvider::parse(&id, &icon_theme, true, self.icon_size)
|
match ImageProvider::parse(&id, &icon_theme, true, self.icon_size)
|
||||||
.map(|image| image.load_into_image(icon.clone()))
|
.map(|image| image.load_into_image(&icon))
|
||||||
{
|
{
|
||||||
Some(Ok(())) => icon.show(),
|
Some(Ok(())) => icon.show(),
|
||||||
_ => icon.hide(),
|
_ => icon.hide(),
|
||||||
|
|
|
@ -176,7 +176,7 @@ impl ItemButton {
|
||||||
button.set_image(Some(>k_image));
|
button.set_image(Some(>k_image));
|
||||||
button.set_always_show_image(true);
|
button.set_always_show_image(true);
|
||||||
|
|
||||||
if let Err(err) = image.load_into_image(gtk_image) {
|
if let Err(err) = image.load_into_image(>k_image) {
|
||||||
error!("{err:?}");
|
error!("{err:?}");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -415,7 +415,7 @@ impl Module<Button> for MusicModule {
|
||||||
ImageProvider::parse(&cover_path, &icon_theme, false, image_size)
|
ImageProvider::parse(&cover_path, &icon_theme, false, image_size)
|
||||||
}) {
|
}) {
|
||||||
album_image.show();
|
album_image.show();
|
||||||
image.load_into_image(album_image.clone())
|
image.load_into_image(&album_image)
|
||||||
} else {
|
} else {
|
||||||
album_image.set_from_pixbuf(None);
|
album_image.set_from_pixbuf(None);
|
||||||
album_image.hide();
|
album_image.hide();
|
||||||
|
|
|
@ -210,7 +210,7 @@ impl Module<gtk::Button> for UpowerModule {
|
||||||
icon_name.push_str(&properties.icon_name);
|
icon_name.push_str(&properties.icon_name);
|
||||||
|
|
||||||
ImageProvider::parse(&icon_name, &icon_theme, false, self.icon_size)
|
ImageProvider::parse(&icon_name, &icon_theme, false, self.icon_size)
|
||||||
.map(|provider| provider.load_into_image(icon.clone()));
|
.map(|provider| provider.load_into_image(&icon));
|
||||||
|
|
||||||
label.set_label_escaped(&format);
|
label.set_label_escaped(&format);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue