mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-09-08 12:51:53 +00:00
handle bitmap images
This commit is contained in:
parent
f2cdc7bc52
commit
bcf4f44cfb
@ -1,3 +1,4 @@
|
||||
mod image;
|
||||
mod status;
|
||||
mod text;
|
||||
|
||||
@ -24,6 +25,7 @@ impl File {
|
||||
glib::Priority,
|
||||
prelude::{FileExt, FileExtManual},
|
||||
};
|
||||
use image::Image;
|
||||
use status::Status;
|
||||
use text::Text;
|
||||
|
||||
@ -98,7 +100,10 @@ impl File {
|
||||
}
|
||||
}
|
||||
"image/png" | "image/gif" | "image/jpeg" | "image/webp" => {
|
||||
todo!()
|
||||
match gtk::gdk::Texture::from_file(&file) {
|
||||
Ok(texture) => Image::Bitmap(uri, texture).handle(page),
|
||||
Err(e) => Status::Failure(e.to_string()).handle(page),
|
||||
}
|
||||
}
|
||||
mime => Status::Failure(format!(
|
||||
"Content type `{mime}` yet not supported"
|
||||
|
22
src/app/browser/window/tab/item/client/driver/file/image.rs
Normal file
22
src/app/browser/window/tab/item/client/driver/file/image.rs
Normal file
@ -0,0 +1,22 @@
|
||||
use super::Page;
|
||||
use gtk::{gdk::Texture, glib::Uri};
|
||||
use std::rc::Rc;
|
||||
|
||||
pub enum Image {
|
||||
Bitmap(Uri, Texture),
|
||||
// @TODO Vector(Uri, String),
|
||||
}
|
||||
|
||||
impl Image {
|
||||
pub fn handle(&self, page: Rc<Page>) {
|
||||
let uri = match self {
|
||||
Self::Bitmap(uri, texture) => {
|
||||
page.content.to_image(texture);
|
||||
uri
|
||||
}
|
||||
};
|
||||
page.set_title(&crate::tool::uri_to_title(uri));
|
||||
page.set_progress(0.0);
|
||||
page.window_action.find.simple_action.set_enabled(false);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user