diff --git a/Cargo.lock b/Cargo.lock index e22d405..ae3a7de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2221,7 +2221,7 @@ dependencies = [ [[package]] name = "pdf-presenter" -version = "0.1.47" +version = "0.1.48" dependencies = [ "bytemuck", "chrono", diff --git a/Cargo.toml b/Cargo.toml index 2f9ad35..3c071c9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ default-members = ["crates/pdf-presenter"] resolver = "3" [workspace.package] -version = "0.1.47" +version = "0.1.48" edition = "2024" license = "MIT" repository = "https://proxy.dandaedre.com/gitea/idle-org/pdf-presenter" diff --git a/crates/pdf-presenter/src/localization.rs b/crates/pdf-presenter/src/localization.rs index 51137ab..f6a655d 100644 --- a/crates/pdf-presenter/src/localization.rs +++ b/crates/pdf-presenter/src/localization.rs @@ -64,6 +64,10 @@ pub fn tr<'a>(ctx: &egui::Context, text: &'a str) -> &'a str { "Header" => "En-tête", "Above slides" => "Au-dessus des diapositives", "Below notes" => "Sous les notes", + "Left of notes" => "À gauche des notes", + "Right of notes" => "À droite des notes", + "Left of slides" => "À gauche des diapositives", + "Right of slides" => "À droite des diapositives", "Elapsed time position" => "Position du temps écoulé", "Clock position" => "Position de l’horloge", "Slide progress bar" => "Barre de progression des diapositives", diff --git a/crates/pdf-presenter/src/presenter_ui.rs b/crates/pdf-presenter/src/presenter_ui.rs index a1ab393..ef9961b 100644 --- a/crates/pdf-presenter/src/presenter_ui.rs +++ b/crates/pdf-presenter/src/presenter_ui.rs @@ -223,7 +223,7 @@ fn timer_height(s: &Studio, position: TimerPosition) -> f32 { fn timers(ui: &mut Ui, s: &Studio, position: TimerPosition) { let locale = ui.ctx().clone(); let secs = s.started.elapsed().as_secs(); - for (w, p, label, value) in [ + let entries = [ ( &s.layout.elapsed, s.layout.elapsed_position, @@ -236,18 +236,124 @@ fn timers(ui: &mut Ui, s: &Studio, position: TimerPosition) { "Time · HH:MM", chrono::Local::now().format("%H:%M").to_string(), ), - ] { - if w.show && p == position { - ui.add_space(16.); - egui::Frame::group(ui.style()).show(ui, |ui| { - ui.vertical(|ui| { - ui.small(tr(&locale, label)); - ui.label(egui::RichText::new(value).size(w.size)); - }); - }); + ]; + let count = entries + .iter() + .filter(|(w, p, _, _)| w.show && *p == position) + .count(); + if count == 0 { + return; + } + let stacked = matches!( + position, + TimerPosition::LeftOfNotes + | TimerPosition::RightOfNotes + | TimerPosition::LeftOfSlides + | TimerPosition::RightOfSlides + ); + let available = ui.available_size(); + let width = if stacked { + available.x + } else { + (available.x - (12. + ui.spacing().item_spacing.x) * count.saturating_sub(1) as f32) + / count as f32 + } + .max(1.); + let height = if stacked { + (available.y - (12. + ui.spacing().item_spacing.y) * count.saturating_sub(1) as f32) + / count as f32 + } else { + available.y + } + .max(1.); + for (index, (w, _, label, value)) in entries + .into_iter() + .filter(|(w, p, _, _)| w.show && *p == position) + .enumerate() + { + if index > 0 { + ui.add_space(12.); + } + let desired = ui.painter().layout_no_wrap( + value.clone(), + FontId::proportional(w.size), + ui.visuals().text_color(), + ); + let size = if stacked { + Vec2::new(width, height) + } else { + Vec2::new( + (desired.size().x + 24.).min(width), + (w.size * 1.3 + 36.).min(height), + ) + }; + let (rect, _) = ui.allocate_exact_size(size, Sense::hover()); + let painter = ui.painter().with_clip_rect(rect); + painter.rect_filled(rect, 6., ui.visuals().extreme_bg_color); + painter.text( + rect.min + Vec2::splat(8.), + egui::Align2::LEFT_TOP, + tr(&locale, label), + FontId::proportional(12.), + ui.visuals().weak_text_color(), + ); + let area = Rect::from_min_max(rect.min + Vec2::new(8., 28.), rect.max - Vec2::splat(8.)); + if area.is_positive() { + let scale = (area.width() / desired.size().x) + .min(area.height() / desired.size().y) + .min(1.); + painter.text( + area.center(), + egui::Align2::CENTER_CENTER, + value, + FontId::proportional((w.size * scale).max(1.)), + ui.visuals().text_color(), + ); } } } +fn side_timers( + ui: &mut Ui, + s: &Studio, + rect: &mut Rect, + left: TimerPosition, + right: TimerPosition, +) { + let original = *rect; + for (position, is_left) in [(left, true), (right, false)] { + let size = timer_height(s, position); + if size == 0. || !original.is_positive() { + continue; + } + let width = ((size - 32.) * 3.6 + 24.).min(original.width() * 0.32); + let column = if is_left { + Rect::from_min_max( + original.min, + Pos2::new(original.left() + width, original.bottom()), + ) + } else { + Rect::from_min_max( + Pos2::new(original.right() - width, original.top()), + original.max, + ) + }; + if is_left { + rect.min.x = column.right() + 8.; + } else { + rect.max.x = column.left() - 8.; + } + ui.scope_builder( + egui::UiBuilder::new() + .max_rect(column) + .layout(egui::Layout::top_down(egui::Align::Min)), + |ui| { + ui.set_clip_rect(ui.clip_rect().intersect(column)); + timers(ui, s, position); + }, + ); + } +} + pub fn presenter(ui: &mut Ui, s: &mut Studio, native: &mut UiState) { let locale = ui.ctx().clone(); native.trim(s); @@ -296,7 +402,9 @@ pub fn presenter(ui: &mut Ui, s: &mut Studio, native: &mut UiState) { ui.close(); } }); - let header_height = (timer_height(s, TimerPosition::Header) + 20.).max(64.); + let header_height = (timer_height(s, TimerPosition::Header) + 20.) + .max(64.) + .min(screen.height() * 0.35); let mut body = screen.shrink(16.); if s.layout.header { body.min.y += header_height; @@ -326,7 +434,7 @@ pub fn presenter(ui: &mut Ui, s: &mut Studio, native: &mut UiState) { }); } for position in [TimerPosition::AboveSlides, TimerPosition::BelowNotes] { - let height = timer_height(s, position); + let height = timer_height(s, position).min(body.height().max(0.) * 0.35); if height > 0. { let top = if position == TimerPosition::AboveSlides { body.top() @@ -355,7 +463,7 @@ pub fn presenter(ui: &mut Ui, s: &mut Studio, native: &mut UiState) { } else { 0. }; - let preview = Rect::from_min_max( + let mut preview = Rect::from_min_max( body.min, Pos2::new( body.max.x, @@ -368,6 +476,38 @@ pub fn presenter(ui: &mut Ui, s: &mut Studio, native: &mut UiState) { }, ), ); + let mut notes_rect = + Rect::from_min_max(Pos2::new(body.left(), body.bottom() - notes_h), body.max); + // When a pane is hidden, use the remaining body so enabled timers stay accessible. + if !preview_visible { + preview = body; + } + if !s.layout.notes.show { + notes_rect = body; + } + side_timers( + ui, + s, + &mut preview, + TimerPosition::LeftOfSlides, + TimerPosition::RightOfSlides, + ); + if !preview_visible { + notes_rect = preview; + } + if !s.layout.notes.show { + notes_rect = preview; + } + side_timers( + ui, + s, + &mut notes_rect, + TimerPosition::LeftOfNotes, + TimerPosition::RightOfNotes, + ); + if !s.layout.notes.show { + preview = notes_rect; + } if preview_visible { let items = [ ( @@ -440,7 +580,7 @@ pub fn presenter(ui: &mut Ui, s: &mut Studio, native: &mut UiState) { } } if s.layout.notes.show { - let rect = Rect::from_min_max(Pos2::new(body.left(), body.bottom() - notes_h), body.max); + let rect = notes_rect; ui.painter().rect_filled(rect, 8., ui.visuals().window_fill); ui.painter().text( rect.min + Vec2::splat(14.), @@ -823,7 +963,7 @@ pub fn presenter(ui: &mut Ui, s: &mut Studio, native: &mut UiState) { tr(&locale, "Elapsed time"), &mut s.layout.elapsed, 16., - 72., + 320., "Text size", ); ui.add_enabled_ui(s.layout.elapsed.show, |ui| { @@ -842,7 +982,7 @@ pub fn presenter(ui: &mut Ui, s: &mut Studio, native: &mut UiState) { tr(&locale, "Time · HH:MM"), &mut s.layout.clock, 16., - 72., + 320., "Text size", ); ui.add_enabled_ui(s.layout.clock.show, |ui| { diff --git a/crates/pdf-presenter/src/settings.rs b/crates/pdf-presenter/src/settings.rs index d3c6233..457058a 100644 --- a/crates/pdf-presenter/src/settings.rs +++ b/crates/pdf-presenter/src/settings.rs @@ -19,14 +19,30 @@ pub enum TimerPosition { Header, AboveSlides, BelowNotes, + LeftOfNotes, + RightOfNotes, + LeftOfSlides, + RightOfSlides, } impl TimerPosition { - pub const ALL: [Self; 3] = [Self::Header, Self::AboveSlides, Self::BelowNotes]; + pub const ALL: [Self; 7] = [ + Self::Header, + Self::AboveSlides, + Self::BelowNotes, + Self::LeftOfNotes, + Self::RightOfNotes, + Self::LeftOfSlides, + Self::RightOfSlides, + ]; pub fn label(self) -> &'static str { match self { Self::Header => "Header", Self::AboveSlides => "Above slides", Self::BelowNotes => "Below notes", + Self::LeftOfNotes => "Left of notes", + Self::RightOfNotes => "Right of notes", + Self::LeftOfSlides => "Left of slides", + Self::RightOfSlides => "Right of slides", } } } @@ -87,8 +103,8 @@ impl Layout { (&self.current, 60., 200.), (&self.next, 30., 160.), (&self.notes, 12., 65.), - (&self.elapsed, 16., 72.), - (&self.clock, 16., 72.), + (&self.elapsed, 16., 320.), + (&self.clock, 16., 320.), ] { if !w.size.is_finite() || w.size < min || w.size > max { return Err("Invalid layout size".into()); diff --git a/crates/pdf-presenter/tests/presenter_ui.rs b/crates/pdf-presenter/tests/presenter_ui.rs index 57c57e9..b8b161d 100644 --- a/crates/pdf-presenter/tests/presenter_ui.rs +++ b/crates/pdf-presenter/tests/presenter_ui.rs @@ -596,6 +596,38 @@ fn timer_presets_reserve_space_and_progress_tracks_navigation() { let progress = text_rect(&output.shapes, &format!("Slide {} / 30", page + 1)).unwrap(); assert!(progress.top() > text_rect(&output.shapes, "Time · HH:MM").unwrap().bottom()); } + s.requested = 0; + s.layout.elapsed.size = 320.; + s.layout.clock.size = 320.; + for (left, right, anchor) in [ + ( + TimerPosition::LeftOfSlides, + TimerPosition::RightOfSlides, + "CURRENT 1 / 30", + ), + ( + TimerPosition::LeftOfNotes, + TimerPosition::RightOfNotes, + "PRESENTER NOTES · AUTO-FIT", + ), + ] { + s.layout.elapsed_position = left; + s.layout.clock_position = right; + let output = render(&mut s); + let elapsed = text_rect(&output.shapes, "Elapsed time").unwrap(); + let clock = text_rect(&output.shapes, "Time · HH:MM").unwrap(); + let pane = text_rect(&output.shapes, anchor).unwrap(); + assert!(elapsed.right() < pane.left()); + assert!(clock.left() > pane.right()); + assert!(text_rect(&output.shapes, "00:00").unwrap().height() > 72.); + // Sharing a side stacks the controls without overlapping their labels. + s.layout.clock_position = left; + let output = render(&mut s); + let elapsed = text_rect(&output.shapes, "Elapsed time").unwrap(); + let clock = text_rect(&output.shapes, "Time · HH:MM").unwrap(); + assert!(clock.top() > elapsed.bottom()); + assert!((clock.left() - elapsed.left()).abs() < 1.); + } s.deck = None; assert!(text_rect(&render(&mut s).shapes, "Slide 0 / 0").is_some()); s.layout.elapsed.show = false; diff --git a/crates/pdf-presenter/tests/settings.rs b/crates/pdf-presenter/tests/settings.rs index 8f968ed..9fb0445 100644 --- a/crates/pdf-presenter/tests/settings.rs +++ b/crates/pdf-presenter/tests/settings.rs @@ -190,3 +190,19 @@ fn automatic_buffer_budget_softens_floor_under_memory_pressure() { .unwrap(); } } + +#[test] +fn side_timer_positions_and_large_sizes_roundtrip() { + for position in settings::TimerPosition::ALL { + let mut s = Settings::default(); + s.layout.elapsed_position = position; + s.layout.clock_position = position; + s.layout.elapsed.size = 320.; + s.layout.clock.size = 320.; + s.validate().unwrap(); + let restored: Settings = toml::from_str(&toml::to_string(&s).unwrap()).unwrap(); + assert_eq!(restored.layout, s.layout); + s.layout.elapsed.size = 321.; + assert!(s.validate().is_err()); + } +} diff --git a/docs/changelog.md b/docs/changelog.md index 956e926..dbae7f1 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -2,6 +2,12 @@ ## Unreleased +### 0.1.48 + +- Add independent left/right of notes/slides timer positions and raise clock/elapsed + text size to 320 logical pixels. Reserve side columns, stack shared-side timers, + fit large timer text to its panel and refit notes in the remaining space. + ### 0.1.47 - Escape in the presenter dismisses transient UI without leaving fullscreen or diff --git a/docs/interfaces/settings.md b/docs/interfaces/settings.md index 4f61ca8..5effb27 100644 --- a/docs/interfaces/settings.md +++ b/docs/interfaces/settings.md @@ -35,12 +35,17 @@ flushed temporary file. Unknown fields are ignored and not preserved on round tr - `layout`: `previous`, `current`, `next`, `notes`, `elapsed`, `clock`, each with boolean `show` and finite floating `size`; plus boolean `header`/`footer`. Previous/next sizes are relative weights 30–160, current 60–200; notes size - is percentage 12–65; elapsed/clock sizes are logical pixels 16–72. Defaults are in `settings.rs`. Since 0.1.35, the previous-slide widget defaults + is percentage 12–65; elapsed/clock sizes are logical pixels 16–320. Defaults are in `settings.rs`. Since 0.1.35, the previous-slide widget defaults to hidden; an explicitly saved `previous.show` value is preserved. - `layout.elapsed_position` and `layout.clock_position`: `header` (default), - `above_slides`, or `below_notes`, added in 0.1.24. Independent presenter-only + `above_slides`, or `below_notes`, added in 0.1.24; `left_of_notes`, + `right_of_notes`, `left_of_slides`, `right_of_slides` added in 0.1.48. Independent presenter-only placement presets; unknown values are rejected. Body timer rows reserve space - and remain visible with hidden bars. Header timers follow header visibility. + and remain visible with hidden bars. Header timers follow header visibility. Side timers reserve up to 32% of their + pane per side, stack if sharing a side, and fit their text to available space. + If the target pane is hidden, side timers use the remaining body. Notes refit + to the reduced pane. Existing layouts retain their sizes/positions; older binaries + reject the new positions and sizes over 72. - `layout.slide_progress`: boolean, default false, added in 0.1.24. Shows requested slide / total and its fraction in a reserved bottom body row; empty decks show 0 / 0 with zero fill. This is navigation progress, not render/output readiness. diff --git a/docs/user-guide.md b/docs/user-guide.md index 1a601b1..a81fe2e 100644 --- a/docs/user-guide.md +++ b/docs/user-guide.md @@ -220,7 +220,9 @@ Window-manager focus restrictions may still require clicking the browser on some ### Timer placement and slide progress In Layout, set **Elapsed time position** and **Clock position** independently to -Header, Above slides or Below notes. Timers have separate labeled boxes; size and +Header, Above slides, Below notes, or left/right of the notes or slides. +Timer text can be set up to 320 logical pixels; it scales down only to fit its +allocated space. Timers on the same side stack vertically. Timers have separate labeled boxes; size and visibility controls still apply. Body positions remain visible when bars are hidden. Enable **Slide progress bar** for a presenter-only current slide / total indicator at the bottom of the content area. It starts disabled and tracks requested slide