From aa340e66ecaffaeb4d2052f58472aa05ca916511 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Fri, 20 Nov 2026 07:10:32 +0100 Subject: [PATCH] Make floating windows and browser controls respond to resizing --- Cargo.lock | 2 +- Cargo.toml | 2 +- crates/pdf-presenter/src/presenter_ui.rs | 142 ++++++++++++--------- crates/pdf-presenter/tests/presenter_ui.rs | 71 +++++++++++ docs/changelog.md | 7 + 5 files changed, 162 insertions(+), 62 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ab55d64..9433423 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2212,7 +2212,7 @@ dependencies = [ [[package]] name = "pdf-presenter" -version = "0.1.43" +version = "0.1.44" dependencies = [ "bytemuck", "chrono", diff --git a/Cargo.toml b/Cargo.toml index db471ab..b8fd95c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ default-members = ["crates/pdf-presenter"] resolver = "3" [workspace.package] -version = "0.1.43" +version = "0.1.44" edition = "2024" license = "MIT" repository = "https://proxy.dandaedre.com/gitea/idle-org/pdf-presenter" diff --git a/crates/pdf-presenter/src/presenter_ui.rs b/crates/pdf-presenter/src/presenter_ui.rs index 4fa459f..df3b939 100644 --- a/crates/pdf-presenter/src/presenter_ui.rs +++ b/crates/pdf-presenter/src/presenter_ui.rs @@ -174,6 +174,7 @@ fn widget( size_label: &str, ) { let locale = ui.ctx().clone(); + ui.spacing_mut().slider_width = (ui.available_width() - 155.).clamp(60., 160.); ui.horizontal_wrapped(|ui| { ui.add_sized([150., 30.], egui::Checkbox::new(&mut w.show, label)); ui.add_enabled( @@ -713,7 +714,9 @@ pub fn presenter(ui: &mut Ui, s: &mut Studio, native: &mut UiState) { egui::Window::new(tr(&locale, "Your presenter view")) .id(egui::Id::new("layout-window")) .open(&mut open) - .default_width(560.) + .default_size(Vec2::new(560., 680.).min(ctx.content_rect().size() - Vec2::splat(48.))) + .min_size(Vec2::new(320., 320.)) + .max_size((ctx.content_rect().size() - Vec2::splat(32.)).max(Vec2::splat(1.))) .resizable(true) .show(&ctx, |ui| { ui.spacing_mut().item_spacing = Vec2::new(12., 8.); @@ -726,8 +729,16 @@ pub fn presenter(ui: &mut Ui, s: &mut Studio, native: &mut UiState) { )); egui::ScrollArea::vertical() .id_salt("layout-settings-scroll") - .max_height((ctx.content_rect().height() - 260.).max(160.)) - .auto_shrink([false, true]) + .max_height( + (ui.available_height() + - if ui.available_width() < 510. { + 190. + } else { + 140. + }) + .max(48.), + ) + .auto_shrink([false, false]) .show(ui, |ui| { layout_section(ui, tr(&locale, "Start with a preset"), |ui| { ui.horizontal_wrapped(|ui| { @@ -886,7 +897,10 @@ pub fn presenter(ui: &mut Ui, s: &mut Studio, native: &mut UiState) { egui::Window::new(tr(&locale, "Displays")) .id(egui::Id::new("displays-window")) .open(&mut open) - .default_width(600.) + .default_size(Vec2::new(600., 580.).min(ctx.content_rect().size() - Vec2::splat(48.))) + .min_size(Vec2::new(320., 240.)) + .max_size((ctx.content_rect().size() - Vec2::splat(32.)).max(Vec2::splat(1.))) + .resizable(true) .vscroll(true) .show(&ctx, |ui| { ui.label(tr( @@ -897,7 +911,7 @@ pub fn presenter(ui: &mut Ui, s: &mut Studio, native: &mut UiState) { egui::Frame::group(ui.style()) .inner_margin(12.) .show(ui, |ui| { - ui.set_min_width(540.); + ui.set_width(ui.available_width()); ui.horizontal(|ui| { let (slot, _) = ui.allocate_exact_size(Vec2::splat(64.), Sense::hover()); @@ -925,7 +939,7 @@ pub fn presenter(ui: &mut Ui, s: &mut Studio, native: &mut UiState) { ui.visuals().text_color(), ); ui.vertical(|ui| { - ui.strong(&m.name); + ui.add(egui::Label::new(egui::RichText::new(&m.name).strong()).wrap()); ui.small(format!("{} × {} px", m.size.0, m.size.1)); }); }); @@ -938,7 +952,7 @@ pub fn presenter(ui: &mut Ui, s: &mut Studio, native: &mut UiState) { 0 }; ui.push_id(&m.id, |ui| { - ui.horizontal(|ui| { + ui.horizontal_wrapped(|ui| { for (i, name) in [ tr(&locale, "Unused"), tr(&locale, "Presenter"), @@ -1085,60 +1099,65 @@ pub fn browser(ui: &mut Ui, s: &mut Studio, native: &mut UiState) { "Open a PDF or picture folder to browse slides.", )); } - egui::Frame::group(ui.style()) - .inner_margin(12.) + egui::ScrollArea::vertical() + .id_salt("browser-controls-scroll") + .max_height(((footer_rect.top() - ui.cursor().top()) * 0.5).max(60.)) + .auto_shrink([false, true]) .show(ui, |ui| { - ui.set_width(ui.available_width()); - ui.spacing_mut().item_spacing = Vec2::new(16., 10.); - ui.spacing_mut().button_padding = Vec2::new(12., 7.); - ui.spacing_mut().interact_size.y = 30.; - if ui.available_width() >= 680. { - ui.columns(2, |columns| { - browser_preview_settings(&mut columns[0], s); - browser_screen_settings(&mut columns[1], s); - }); - } else { - browser_preview_settings(ui, s); - browser_screen_settings(ui, s); - } - ui.separator(); - ui.horizontal_wrapped(|ui| { - let accent = ui.visuals().selection.bg_fill; - let text = ui.visuals().selection.stroke.color; - if ui - .add_enabled( - s.count() > 0, - egui::Button::new( - egui::RichText::new(tr(&locale, "Show selected")) - .strong() - .color(text), - ) - .fill(accent) - .min_size(Vec2::new(160., 38.)), - ) - .clicked() - { - s.actions.push(Action::Go(s.browser_selected)); - } - ui.checkbox(&mut s.change_on_click, tr(&locale, "Change on click")); - }); - ui.horizontal_wrapped(|ui| { - ui.colored_label( - if s.change_on_click { - ui.visuals().warn_fg_color + egui::Frame::group(ui.style()) + .inner_margin(12.) + .show(ui, |ui| { + ui.set_width(ui.available_width()); + ui.spacing_mut().item_spacing = Vec2::new(16., 10.); + ui.spacing_mut().button_padding = Vec2::new(12., 7.); + ui.spacing_mut().interact_size.y = 30.; + if ui.available_width() >= 680. { + ui.columns(2, |columns| { + browser_preview_settings(&mut columns[0], s); + browser_screen_settings(&mut columns[1], s); + }); } else { - ui.visuals().hyperlink_color - }, - tr( - &locale, - if s.change_on_click { - "Live browsing" - } else { - "Safe browsing" - }, - ), - ); - ui.label(tr( + browser_preview_settings(ui, s); + browser_screen_settings(ui, s); + } + ui.separator(); + ui.horizontal_wrapped(|ui| { + let accent = ui.visuals().selection.bg_fill; + let text = ui.visuals().selection.stroke.color; + if ui + .add_enabled( + s.count() > 0, + egui::Button::new( + egui::RichText::new(tr(&locale, "Show selected")) + .strong() + .color(text), + ) + .fill(accent) + .min_size(Vec2::new(160., 38.)), + ) + .clicked() + { + s.actions.push(Action::Go(s.browser_selected)); + } + ui.checkbox(&mut s.change_on_click, tr(&locale, "Change on click")); + }); + ui.horizontal_wrapped(|ui| { + ui.colored_label( + if s.change_on_click { + ui.visuals().warn_fg_color + } else { + ui.visuals().hyperlink_color + }, + tr( + &locale, + if s.change_on_click { + "Live browsing" + } else { + "Safe browsing" + }, + ), + ); + ui.label(tr( &locale, if s.change_on_click { "Click changes presentation" @@ -1146,7 +1165,8 @@ pub fn browser(ui: &mut Ui, s: &mut Studio, native: &mut UiState) { "Click to select. Double-click to preview. Show selected to present." }, )); - }); + }); + }); }); ui.add_space(8.); ui.label(format!( @@ -1281,6 +1301,8 @@ pub fn browser(ui: &mut Ui, s: &mut Studio, native: &mut UiState) { .collapsible(false) .resizable(true) .default_size(Vec2::new(800., 500.).min(screen * 0.8)) + .min_size(Vec2::new(240., 180.)) + .max_size((screen - Vec2::splat(32.)).max(Vec2::splat(1.))) .show(ui.ctx(), |ui| { ui.label(tr(&locale, "Preview only — presentation unchanged")); let (rect, _) = diff --git a/crates/pdf-presenter/tests/presenter_ui.rs b/crates/pdf-presenter/tests/presenter_ui.rs index e35eb6b..78b643e 100644 --- a/crates/pdf-presenter/tests/presenter_ui.rs +++ b/crates/pdf-presenter/tests/presenter_ui.rs @@ -767,3 +767,74 @@ fn browser_thumbnails_fill_resized_window_without_stretching_tiles() { assert!(s.visible_thumbs.len() < s.count()); } } + +#[test] +fn floating_windows_can_grow_and_shrink_after_content_is_drawn() { + for id in ["layout-window", "displays-window", "slide-preview"] { + let ctx = Context::default(); + let mut s = studio(); + s.layout_open = id == "layout-window"; + s.displays_open = id == "displays-window"; + if id == "slide-preview" { + s.browser_preview = Some((s.generation, 0)); + } + let mut native = UiState::default(); + let mut frame = |events| { + let mut raw = input(Vec2::new(1920., 1200.)); + raw.events = events; + let _ = ctx.run_ui(raw, |ui| { + if id == "slide-preview" { + presenter_ui::browser(ui, &mut s, &mut native); + } else { + presenter_ui::presenter(ui, &mut s, &mut native); + } + }); + }; + for _ in 0..4 { + frame(vec![]); + } + let rect = || ctx.memory(|m| m.area_rect(egui::Id::new(id))).unwrap(); + for delta in [Vec2::new(120., 80.), Vec2::new(-180., -180.)] { + let before = rect(); + let start = before.right_bottom() - Vec2::splat(2.); + frame(vec![egui::Event::PointerMoved(start)]); + frame(vec![egui::Event::PointerButton { + pos: start, + button: egui::PointerButton::Primary, + pressed: true, + modifiers: Default::default(), + }]); + let end = start + delta; + frame(vec![egui::Event::PointerMoved(end)]); + frame(vec![egui::Event::PointerButton { + pos: end, + button: egui::PointerButton::Primary, + pressed: false, + modifiers: Default::default(), + }]); + for _ in 0..4 { + frame(vec![]); + } + let after = rect(); + if delta.x > 0. { + assert!( + after.width() > before.width() + 50., + "{id}: {before:?} -> {after:?}" + ); + assert!( + after.height() > before.height() + 30., + "{id}: {before:?} -> {after:?}" + ); + } else { + assert!( + after.width() < before.width() - 50., + "{id}: {before:?} -> {after:?}" + ); + assert!( + after.height() < before.height() - 50., + "{id}: {before:?} -> {after:?}" + ); + } + } + } +} diff --git a/docs/changelog.md b/docs/changelog.md index 93250b9..aa6e63c 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -2,6 +2,13 @@ ## Unreleased +### 0.1.44 + +- Size Layout scrolling from its resized window rather than the desktop. Remove + Displays’ forced content width, wrap roles/names, and constrain floating windows + to the viewport. Bound the browser toolbar separately so short windows retain + thumbnail space and the Close footer. + ### 0.1.43 - Reorganize Layout into padded preset, slide/notes, timer/progress and bar sections.