Add independent timer placement presets and optional slide progress
This commit is contained in:
parent
3b160da5ad
commit
8ec51076d3
|
|
@ -2212,7 +2212,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "pdf-presenter"
|
||||
version = "0.1.23"
|
||||
version = "0.1.24"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"chrono",
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ default-members = ["crates/pdf-presenter"]
|
|||
resolver = "3"
|
||||
|
||||
[workspace.package]
|
||||
version = "0.1.23"
|
||||
version = "0.1.24"
|
||||
edition = "2024"
|
||||
license = "MIT"
|
||||
repository = "https://proxy.dandaedre.com/gitea/idle-org/pdf-presenter"
|
||||
|
|
|
|||
|
|
@ -55,6 +55,13 @@ pub fn tr<'a>(ctx: &egui::Context, text: &'a str) -> &'a str {
|
|||
"NEXT" => "SUIVANTE",
|
||||
"PRESENTER NOTES · AUTO-FIT" => "NOTES · TAILLE AUTOMATIQUE",
|
||||
"No notes for this slide" => "Aucune note pour cette diapositive",
|
||||
"Header" => "En-tête",
|
||||
"Above slides" => "Au-dessus des diapositives",
|
||||
"Below notes" => "Sous les notes",
|
||||
"Elapsed time position" => "Position du temps écoulé",
|
||||
"Clock position" => "Position de l’horloge",
|
||||
"Slide progress bar" => "Barre de progression des diapositives",
|
||||
"Slide" => "Diapositive",
|
||||
"Hide" => "Masquer",
|
||||
"Pin" => "Épingler",
|
||||
"Menu" => "Menu",
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use crate::localization::tr;
|
||||
// Native controls for the approved presenter layout and safe slide browser.
|
||||
use crate::{
|
||||
settings::Layout,
|
||||
settings::{Layout, TimerPosition},
|
||||
studio::{Action, Studio},
|
||||
};
|
||||
use egui::{Color32, Context, FontId, Pos2, Rect, Sense, TextureHandle, TextureOptions, Ui, Vec2};
|
||||
|
|
@ -113,6 +113,54 @@ fn widget(ui: &mut Ui, label: &str, w: &mut crate::settings::Widget, min: f32, m
|
|||
);
|
||||
ui.separator();
|
||||
}
|
||||
fn timer_position(ui: &mut Ui, id: &str, position: &mut TimerPosition) {
|
||||
let locale = ui.ctx().clone();
|
||||
egui::ComboBox::from_id_salt(id)
|
||||
.selected_text(tr(&locale, position.label()))
|
||||
.show_ui(ui, |ui| {
|
||||
for choice in TimerPosition::ALL {
|
||||
ui.selectable_value(position, choice, tr(&locale, choice.label()));
|
||||
}
|
||||
});
|
||||
}
|
||||
fn timer_height(s: &Studio, position: TimerPosition) -> f32 {
|
||||
[
|
||||
(&s.layout.elapsed, s.layout.elapsed_position),
|
||||
(&s.layout.clock, s.layout.clock_position),
|
||||
]
|
||||
.into_iter()
|
||||
.filter(|(w, p)| w.show && *p == position)
|
||||
.map(|(w, _)| w.size + 32.)
|
||||
.fold(0., f32::max)
|
||||
}
|
||||
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 [
|
||||
(
|
||||
&s.layout.elapsed,
|
||||
s.layout.elapsed_position,
|
||||
"Elapsed time",
|
||||
format!("{:02}:{:02}", secs / 60, secs % 60),
|
||||
),
|
||||
(
|
||||
&s.layout.clock,
|
||||
s.layout.clock_position,
|
||||
"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));
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn presenter(ui: &mut Ui, s: &mut Studio, native: &mut UiState) {
|
||||
let locale = ui.ctx().clone();
|
||||
native.trim(s);
|
||||
|
|
@ -161,13 +209,55 @@ 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 mut body = screen.shrink(16.);
|
||||
if s.layout.header {
|
||||
body.min.y += 64.;
|
||||
body.min.y += header_height;
|
||||
}
|
||||
if s.layout.footer {
|
||||
body.max.y -= 90.;
|
||||
}
|
||||
if s.layout.slide_progress {
|
||||
let rect = Rect::from_min_max(Pos2::new(body.left(), body.bottom() - 24.), body.max);
|
||||
body.max.y -= 32.;
|
||||
ui.scope_builder(egui::UiBuilder::new().max_rect(rect), |ui| {
|
||||
let current = if s.count() == 0 {
|
||||
0
|
||||
} else {
|
||||
s.requested.min(s.count() - 1) + 1
|
||||
};
|
||||
let fraction = current as f32 / s.count().max(1) as f32;
|
||||
ui.add(
|
||||
egui::ProgressBar::new(fraction)
|
||||
.desired_width(rect.width())
|
||||
.text(format!(
|
||||
"{} {current} / {}",
|
||||
tr(&locale, "Slide"),
|
||||
s.count()
|
||||
)),
|
||||
);
|
||||
});
|
||||
}
|
||||
for position in [TimerPosition::AboveSlides, TimerPosition::BelowNotes] {
|
||||
let height = timer_height(s, position);
|
||||
if height > 0. {
|
||||
let top = if position == TimerPosition::AboveSlides {
|
||||
body.top()
|
||||
} else {
|
||||
body.bottom() - height
|
||||
};
|
||||
let rect =
|
||||
Rect::from_min_size(Pos2::new(body.left(), top), Vec2::new(body.width(), height));
|
||||
if position == TimerPosition::AboveSlides {
|
||||
body.min.y += height + 8.;
|
||||
} else {
|
||||
body.max.y -= height + 8.;
|
||||
}
|
||||
ui.scope_builder(egui::UiBuilder::new().max_rect(rect), |ui| {
|
||||
ui.horizontal(|ui| timers(ui, s, position));
|
||||
});
|
||||
}
|
||||
}
|
||||
let preview_visible = s.layout.previous.show || s.layout.current.show || s.layout.next.show;
|
||||
let notes_h = if s.layout.notes.show {
|
||||
if preview_visible {
|
||||
|
|
@ -310,7 +400,7 @@ pub fn presenter(ui: &mut Ui, s: &mut Studio, native: &mut UiState) {
|
|||
}
|
||||
}
|
||||
if header {
|
||||
let rect = Rect::from_min_size(screen.min, Vec2::new(screen.width(), 64.));
|
||||
let rect = Rect::from_min_size(screen.min, Vec2::new(screen.width(), header_height));
|
||||
ui.painter().rect_filled(rect, 0., ui.visuals().window_fill);
|
||||
ui.scope_builder(egui::UiBuilder::new().max_rect(rect.shrink(10.)), |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
|
|
@ -387,19 +477,7 @@ pub fn presenter(ui: &mut Ui, s: &mut Studio, native: &mut UiState) {
|
|||
{
|
||||
s.actions.push(Action::Blank);
|
||||
}
|
||||
if s.layout.elapsed.show {
|
||||
let secs = s.started.elapsed().as_secs();
|
||||
ui.label(
|
||||
egui::RichText::new(format!("{:02}:{:02}", secs / 60, secs % 60))
|
||||
.size(s.layout.elapsed.size),
|
||||
);
|
||||
}
|
||||
if s.layout.clock.show {
|
||||
ui.label(
|
||||
egui::RichText::new(chrono::Local::now().format("%H:%M").to_string())
|
||||
.size(s.layout.clock.size),
|
||||
);
|
||||
}
|
||||
timers(ui, s, TimerPosition::Header);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -629,6 +707,15 @@ pub fn presenter(ui: &mut Ui, s: &mut Studio, native: &mut UiState) {
|
|||
16.,
|
||||
72.,
|
||||
);
|
||||
ui.label(tr(&locale, "Elapsed time position"));
|
||||
timer_position(ui, "elapsed-position", &mut s.layout.elapsed_position);
|
||||
ui.label(tr(&locale, "Clock position"));
|
||||
timer_position(ui, "clock-position", &mut s.layout.clock_position);
|
||||
ui.checkbox(
|
||||
&mut s.layout.slide_progress,
|
||||
tr(&locale, "Slide progress bar"),
|
||||
);
|
||||
ui.separator();
|
||||
button(
|
||||
ui,
|
||||
tr(&locale, "Save layout · This project"),
|
||||
|
|
|
|||
|
|
@ -11,6 +11,25 @@ pub struct Widget {
|
|||
pub show: bool,
|
||||
pub size: f32,
|
||||
}
|
||||
/// Fixed presenter-only timer locations; body rows remain visible with hidden bars.
|
||||
#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum TimerPosition {
|
||||
#[default]
|
||||
Header,
|
||||
AboveSlides,
|
||||
BelowNotes,
|
||||
}
|
||||
impl TimerPosition {
|
||||
pub const ALL: [Self; 3] = [Self::Header, Self::AboveSlides, Self::BelowNotes];
|
||||
pub fn label(self) -> &'static str {
|
||||
match self {
|
||||
Self::Header => "Header",
|
||||
Self::AboveSlides => "Above slides",
|
||||
Self::BelowNotes => "Below notes",
|
||||
}
|
||||
}
|
||||
}
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
||||
#[serde(default)]
|
||||
pub struct Layout {
|
||||
|
|
@ -20,6 +39,9 @@ pub struct Layout {
|
|||
pub notes: Widget,
|
||||
pub elapsed: Widget,
|
||||
pub clock: Widget,
|
||||
pub elapsed_position: TimerPosition,
|
||||
pub clock_position: TimerPosition,
|
||||
pub slide_progress: bool,
|
||||
pub header: bool,
|
||||
pub footer: bool,
|
||||
}
|
||||
|
|
@ -50,6 +72,9 @@ impl Default for Layout {
|
|||
show: true,
|
||||
size: 28.,
|
||||
},
|
||||
elapsed_position: TimerPosition::Header,
|
||||
clock_position: TimerPosition::Header,
|
||||
slide_progress: false,
|
||||
header: true,
|
||||
footer: true,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -544,3 +544,61 @@ fn nested_settings_remain_interactive_and_menu_still_dismisses() {
|
|||
);
|
||||
assert!(!s.menu_open, "Escape should dismiss the dropdown");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn timer_presets_reserve_space_and_progress_tracks_navigation() {
|
||||
use pdf_presenter::settings::TimerPosition;
|
||||
fn text_rect(shapes: &[egui::epaint::ClippedShape], label: &str) -> Option<Rect> {
|
||||
fn find(shape: &egui::Shape, label: &str) -> Option<Rect> {
|
||||
match shape {
|
||||
egui::Shape::Text(t) if t.galley.text() == label => {
|
||||
Some(Rect::from_min_size(t.pos, t.galley.size()))
|
||||
}
|
||||
egui::Shape::Vec(shapes) => shapes.iter().find_map(|s| find(s, label)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
shapes.iter().find_map(|s| find(&s.shape, label))
|
||||
}
|
||||
let ctx = Context::default();
|
||||
let mut s = studio();
|
||||
let mut native = UiState::default();
|
||||
s.layout.header = false;
|
||||
s.layout.footer = false;
|
||||
s.layout.elapsed_position = TimerPosition::AboveSlides;
|
||||
s.layout.clock_position = TimerPosition::BelowNotes;
|
||||
s.layout.elapsed.size = 72.;
|
||||
s.layout.clock.size = 72.;
|
||||
let mut render = |s: &mut Studio| {
|
||||
let mut output = ctx.run_ui(input(Vec2::new(1280., 900.)), |ui| {
|
||||
presenter_ui::presenter(ui, s, &mut native)
|
||||
});
|
||||
for _ in 0..3 {
|
||||
output = ctx.run_ui(input(Vec2::new(1280., 900.)), |ui| {
|
||||
presenter_ui::presenter(ui, s, &mut native)
|
||||
});
|
||||
}
|
||||
output
|
||||
};
|
||||
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 current = text_rect(&output.shapes, "CURRENT 1 / 30").unwrap();
|
||||
assert!(elapsed.bottom() < current.top());
|
||||
assert!(clock.top() > current.bottom());
|
||||
assert!(text_rect(&output.shapes, "Slide 1 / 30").is_none());
|
||||
s.layout.slide_progress = true;
|
||||
for page in [0, 14, 29] {
|
||||
s.requested = page;
|
||||
let output = render(&mut s);
|
||||
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.deck = None;
|
||||
assert!(text_rect(&render(&mut s).shapes, "Slide 0 / 0").is_some());
|
||||
s.layout.elapsed.show = false;
|
||||
s.layout.clock.show = false;
|
||||
let output = render(&mut s);
|
||||
assert!(text_rect(&output.shapes, "Elapsed time").is_none());
|
||||
assert!(text_rect(&output.shapes, "Time · HH:MM").is_none());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,9 @@ fn settings_roundtrip_preserves_project_overrides_and_hidden_bars() {
|
|||
project.current.show = false;
|
||||
project.header = false;
|
||||
project.footer = false;
|
||||
project.elapsed_position = settings::TimerPosition::AboveSlides;
|
||||
project.clock_position = settings::TimerPosition::BelowNotes;
|
||||
project.slide_progress = true;
|
||||
settings.projects.insert("show".into(), project.clone());
|
||||
settings.routes = Routes {
|
||||
presenter: vec!["one".into(), "two".into()],
|
||||
|
|
@ -94,3 +97,29 @@ fn monitor_recovery_preserves_survivors_and_distinct_groups() {
|
|||
.is_empty()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn legacy_layouts_default_timer_positions_and_progress_is_opt_in() {
|
||||
let legacy: Settings = toml::from_str("version=1\n[layout]\nheader=false").unwrap();
|
||||
assert_eq!(
|
||||
legacy.layout.elapsed_position,
|
||||
settings::TimerPosition::Header
|
||||
);
|
||||
assert_eq!(
|
||||
legacy.layout.clock_position,
|
||||
settings::TimerPosition::Header
|
||||
);
|
||||
assert!(!legacy.layout.slide_progress);
|
||||
assert!(toml::from_str::<Settings>("[layout]\nclock_position='anywhere'").is_err());
|
||||
let example: Settings = toml::from_str(include_str!(
|
||||
"../../../docs/interfaces/examples/settings-v1.toml"
|
||||
))
|
||||
.unwrap();
|
||||
example.validate().unwrap();
|
||||
assert_eq!(
|
||||
example.layout,
|
||||
toml::from_str::<Settings>(&toml::to_string(&example).unwrap())
|
||||
.unwrap()
|
||||
.layout
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,14 @@
|
|||
|
||||
## Unreleased
|
||||
|
||||
### 0.1.24
|
||||
|
||||
- Separate elapsed time and clock into labeled boxes with independent Header,
|
||||
Above slides and Below notes presets, saved in project/global layouts.
|
||||
- Add an opt-in presenter slide-progress bar (requested slide / total), distinct
|
||||
from loading progress and visible with hidden bars. Older layouts retain defaults.
|
||||
- Cover settings compatibility/round trips, timer placement and navigation progress.
|
||||
|
||||
### 0.1.23
|
||||
|
||||
- Put compact arrow icons at the far left of both header and footer to hide or pin
|
||||
|
|
|
|||
|
|
@ -12,6 +12,9 @@ presenter = ["Primary#1"]
|
|||
presentation = ["Projector#1"]
|
||||
|
||||
[layout]
|
||||
elapsed_position = "above_slides"
|
||||
clock_position = "below_notes"
|
||||
slide_progress = true
|
||||
header = true
|
||||
footer = false
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,15 @@ flushed temporary file. Unknown fields are ignored and not preserved on round tr
|
|||
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`.
|
||||
- `layout.elapsed_position` and `layout.clock_position`: `header` (default),
|
||||
`above_slides`, or `below_notes`, added in 0.1.24. 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.
|
||||
- `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.
|
||||
These three fields round-trip in both global and project layouts. Older v1
|
||||
layouts omit them and use defaults without migration.
|
||||
- `projects`: at most 4096 SHA-256 canonical-path keys mapping to full layouts.
|
||||
Path identity uses OS encoded bytes, not source content. Moving files or switching
|
||||
platforms may therefore select a different layout. Project overrides win globally.
|
||||
|
|
|
|||
|
|
@ -174,3 +174,13 @@ All slides opens a windowed browser above fullscreen windows and requests focus.
|
|||
Opening it again restores/focuses the existing browser. Close or Escape dismisses it.
|
||||
The destination remains configurable in the browser, defaulting to the presenter.
|
||||
Window-manager focus restrictions may still require clicking the browser on some systems.
|
||||
|
||||
### 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
|
||||
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
|
||||
navigation, even while output is blank or preparing; it is separate from loading
|
||||
progress. Use Save layout · This project or All projects to remember these choices.
|
||||
|
|
|
|||
Loading…
Reference in New Issue