handle bitmap images

This commit is contained in:
yggverse 2025-02-13 19:19:09 +02:00
parent f2cdc7bc52
commit bcf4f44cfb
2 changed files with 28 additions and 1 deletions

View File

@ -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"

View 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);
}
}