This is a major refactor which updates GTK, GLib and GTK Layer Shell to their latest versions. GLib channels, previously used for receiving events on the GLib Main Context thread have been deprecated and a new method for running Futures on the main thread has been added instead. This commit also replaces all the deprecated code with this. As part of the above, a bug was uncovered related to creating the GLib main context inside the Tokio runtime. Spawning of Tokio tasks has been refactored to fix this.
43 lines
994 B
Rust
43 lines
994 B
Rust
use gtk::prelude::*;
|
|
use gtk::Image;
|
|
use serde::Deserialize;
|
|
|
|
use crate::build;
|
|
use crate::dynamic_value::dynamic_string;
|
|
use crate::image::ImageProvider;
|
|
|
|
use super::{CustomWidget, CustomWidgetContext};
|
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
pub struct ImageWidget {
|
|
name: Option<String>,
|
|
class: Option<String>,
|
|
src: String,
|
|
#[serde(default = "default_size")]
|
|
size: i32,
|
|
}
|
|
|
|
const fn default_size() -> i32 {
|
|
32
|
|
}
|
|
|
|
impl CustomWidget for ImageWidget {
|
|
type Widget = Image;
|
|
|
|
fn into_widget(self, context: CustomWidgetContext) -> Self::Widget {
|
|
let gtk_image = build!(self, Self::Widget);
|
|
|
|
{
|
|
let gtk_image = gtk_image.clone();
|
|
let icon_theme = context.icon_theme.clone();
|
|
|
|
dynamic_string(&self.src, move |src| {
|
|
ImageProvider::parse(&src, &icon_theme, false, self.size)
|
|
.map(|image| image.load_into_image(gtk_image.clone()));
|
|
});
|
|
}
|
|
|
|
gtk_image
|
|
}
|
|
}
|