dais_ui/presenter/
current_slide.rs1use crate::widgets::SlideThumbnail;
7use dais_document::page::RenderedPage;
8
9pub struct CurrentSlidePanel {
11 thumbnail: SlideThumbnail,
12 last_image_rect: egui::Rect,
14}
15
16impl CurrentSlidePanel {
17 pub fn new() -> Self {
18 Self { thumbnail: SlideThumbnail::new(), last_image_rect: egui::Rect::NOTHING }
19 }
20
21 pub fn update(&mut self, ctx: &egui::Context, page: &RenderedPage, page_index: usize) {
23 self.thumbnail.update(ctx, page, page_index);
24 }
25
26 pub fn show(&mut self, ui: &mut egui::Ui, area: egui::Rect) -> (egui::Response, egui::Rect) {
29 self.show_with_sense(ui, area, egui::Sense::click_and_drag())
30 }
31
32 pub fn show_with_sense(
35 &mut self,
36 ui: &mut egui::Ui,
37 area: egui::Rect,
38 sense: egui::Sense,
39 ) -> (egui::Response, egui::Rect) {
40 let padding = egui::vec2(8.0, 8.0);
41 let content_rect = area.shrink2(padding);
42 let mut child_ui = ui.new_child(egui::UiBuilder::new().max_rect(content_rect));
43 let available = content_rect.size().max(egui::vec2(1.0, 1.0));
44
45 let (response, image_rect) =
46 self.thumbnail.show_with_sense(&mut child_ui, available, sense);
47 self.last_image_rect = image_rect;
48 (response, image_rect)
49 }
50
51 pub fn image_rect(&self) -> egui::Rect {
53 self.last_image_rect
54 }
55}
56
57impl Default for CurrentSlidePanel {
58 fn default() -> Self {
59 Self::new()
60 }
61}