note media: unnest full screen media

Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
kernelkind
2025-04-29 12:39:54 -04:00
parent 01636786be
commit 953496fc74

View File

@@ -1,5 +1,7 @@
use std::collections::HashMap;
use egui::{Button, Color32, Image, Response, Sense, Window}; use egui::{Button, Color32, Image, Response, Sense, Window};
use notedeck::{Images, MediaCacheType}; use notedeck::{GifState, Images, MediaCacheType, TexturedImage};
use crate::{ use crate::{
gif::{handle_repaint, retrieve_latest_texture}, gif::{handle_repaint, retrieve_latest_texture},
@@ -86,12 +88,19 @@ pub(crate) fn image_carousel(
}); });
if show_popup { if show_popup {
let current_image = current_image if let Some((image_url, cache_type)) = current_image {
.as_ref() show_full_screen_media(ui, &image_url, cache_type, img_cache, carousel_id);
.expect("the image was actually clicked"); }
let image = current_image.clone().0; }
let cache_type = current_image.clone().1; }
fn show_full_screen_media(
ui: &mut egui::Ui,
image_url: &str,
cache_type: MediaCacheType,
img_cache: &mut Images,
carousel_id: egui::Id,
) {
Window::new("image_popup") Window::new("image_popup")
.title_bar(false) .title_bar(false)
.fixed_size(ui.ctx().screen_rect().size()) .fixed_size(ui.ctx().screen_rect().size())
@@ -102,12 +111,26 @@ pub(crate) fn image_carousel(
render_images( render_images(
ui, ui,
img_cache, img_cache,
&image, image_url,
ImageType::Content, ImageType::Content,
cache_type, cache_type,
|_| {}, |_| {},
|_, _| {}, |_, _| {},
|ui, url, renderable_media, gifs| { |ui, url, renderable_media, gifs| {
render_full_screen_media(ui, renderable_media, gifs, url, carousel_id);
},
);
});
});
}
fn render_full_screen_media(
ui: &mut egui::Ui,
renderable_media: &mut TexturedImage,
gifs: &mut HashMap<String, GifState>,
image_url: &str,
carousel_id: egui::Id,
) {
let screen_rect = ui.ctx().screen_rect(); let screen_rect = ui.ctx().screen_rect();
// escape // escape
@@ -118,11 +141,8 @@ pub(crate) fn image_carousel(
} }
// background // background
ui.painter().rect_filled( ui.painter()
screen_rect, .rect_filled(screen_rect, 0.0, Color32::from_black_alpha(230));
0.0,
Color32::from_black_alpha(230),
);
// zoom init // zoom init
let zoom_id = carousel_id.with("zoom_level"); let zoom_id = carousel_id.with("zoom_level");
@@ -132,16 +152,15 @@ pub(crate) fn image_carousel(
// pan init // pan init
let pan_id = carousel_id.with("pan_offset"); let pan_id = carousel_id.with("pan_offset");
let mut pan_offset = ui.ctx().memory(|mem| { let mut pan_offset = ui
mem.data.get_temp(pan_id).unwrap_or(egui::Vec2::ZERO) .ctx()
}); .memory(|mem| mem.data.get_temp(pan_id).unwrap_or(egui::Vec2::ZERO));
// zoom & scroll // zoom & scroll
if ui.input(|i| i.pointer.hover_pos()).is_some() { if ui.input(|i| i.pointer.hover_pos()).is_some() {
let scroll_delta = ui.input(|i| i.smooth_scroll_delta); let scroll_delta = ui.input(|i| i.smooth_scroll_delta);
if scroll_delta.y != 0.0 { if scroll_delta.y != 0.0 {
let zoom_factor = let zoom_factor = if scroll_delta.y > 0.0 { 1.05 } else { 0.95 };
if scroll_delta.y > 0.0 { 1.05 } else { 0.95 };
zoom *= zoom_factor; zoom *= zoom_factor;
zoom = zoom.clamp(0.1, 5.0); zoom = zoom.clamp(0.1, 5.0);
@@ -158,7 +177,7 @@ pub(crate) fn image_carousel(
let texture = handle_repaint( let texture = handle_repaint(
ui, ui,
retrieve_latest_texture(&image, gifs, renderable_media), retrieve_latest_texture(image_url, gifs, renderable_media),
); );
let texture_size = texture.size_vec2(); let texture_size = texture.size_vec2();
@@ -192,10 +211,8 @@ pub(crate) fn image_carousel(
); );
let uv_min = egui::pos2( let uv_min = egui::pos2(
0.5 - (visible_width / scaled_size.x) / 2.0 0.5 - (visible_width / scaled_size.x) / 2.0 + pan_offset.x / scaled_size.x,
+ pan_offset.x / scaled_size.x, 0.5 - (visible_height / scaled_size.y) / 2.0 + pan_offset.y / scaled_size.y,
0.5 - (visible_height / scaled_size.y) / 2.0
+ pan_offset.y / scaled_size.y,
); );
let uv_max = egui::pos2( let uv_max = egui::pos2(
@@ -253,12 +270,7 @@ pub(crate) fn image_carousel(
}); });
} }
copy_link(url, response); copy_link(image_url, response);
},
);
});
});
}
} }
fn copy_link(url: &str, img_resp: Response) { fn copy_link(url: &str, img_resp: Response) {