Skip to main content

dais_ui/presenter/
current_slide.rs

1//! Current slide display in the presenter console.
2//!
3//! Renders the current slide with correct aspect ratio, letterboxed, in the
4//! presenter's left panel.
5
6use crate::widgets::SlideThumbnail;
7use dais_document::page::RenderedPage;
8
9/// Manages the current slide display in the presenter console.
10pub struct CurrentSlidePanel {
11    thumbnail: SlideThumbnail,
12    /// Stored image rect from the last render (for mouse coordinate mapping).
13    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    /// Update the texture data when the page changes.
22    pub fn update(&mut self, ctx: &egui::Context, page: &RenderedPage, page_index: usize) {
23        self.thumbnail.update(ctx, page, page_index);
24    }
25
26    /// Render the current slide in the given area.
27    /// Returns the response and the image rect for mouse handling.
28    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    /// Render the current slide with a caller-provided interaction sense.
33    /// Returns the response and the image rect for mouse handling.
34    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    /// The image rect from the most recent render.
52    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}