Skip to content

A fast file manager for Windows and macOS that never freezes: tabs, dual panes, archives as folders, Quick Look-style previews. A File Explorer and Finder alternative written in Rust.

Preview pane asks for a picture as wide as the pane (805)

gelenmedyaa4a3ae9da495
diff --git a/crates/rf-app/src/preview.rs b/crates/rf-app/src/preview.rs
index 86b73fbb..00e79ccf 100644
--- a/crates/rf-app/src/preview.rs
+++ b/crates/rf-app/src/preview.rs
@@ -21,6 +21,27 @@ mod wide;
const TEXT_LIMIT: usize = 48 * 1024;
const PREVIEW_PX: u32 = 384;
+/// The picture size the pane asks for, for a pane `device_px` wide: the next of a few steps up (so a resize by a few pixels asks for
+/// no new picture), never under [`PREVIEW_PX`] and never over 2048.
+fn pane_picture_px(device_px: f32) -> u32 {
+ const STEPS: [u32; 5] = [PREVIEW_PX, 640, 960, 1440, 2048];
+ STEPS.into_iter().find(|&s| s as f32 >= device_px).unwrap_or(2048)
+}
+
+#[cfg(test)]
+mod pane_picture_tests {
+ use super::{PREVIEW_PX, pane_picture_px};
+
+ #[test]
+ fn the_picture_is_as_wide_as_the_pane_in_steps() {
+ assert_eq!(pane_picture_px(300.), PREVIEW_PX);
+ assert_eq!(pane_picture_px(384.), PREVIEW_PX);
+ assert_eq!(pane_picture_px(400. * 1.5), 640, "a 400 px pane at 150 %");
+ assert_eq!(pane_picture_px(700.), 960);
+ assert_eq!(pane_picture_px(5000.), 2048);
+ }
+}
+
/// Shared folder-size cache (Size column, preview pane, Properties window).
pub fn size_cache() -> &'static rf_win::foldersize::FolderSizeCache {
rf_win::foldersize::shared_cache()
@@ -1107,7 +1128,13 @@ impl Render for Preview {
.into_any_element()
} else {
self.hide_host();
- let thumb = self.thumb_or_hold(&dir, &e, PREVIEW_PX, cx);
+ // as many pixels as the pane shows (issue 805: a fixed 384 px picture was blown up in a wide pane or on a 150 % screen)
+ let want = {
+ let st = cx.global::<crate::settings::Settings>();
+ let logical = if st.preview_position.is_right() { st.preview_width } else { st.preview_height.max(st.preview_width) };
+ pane_picture_px(logical * window.scale_factor())
+ };
+ let thumb = self.thumb_or_hold(&dir, &e, want, cx);
// Settings › "Windows' icons while pictures load" › "Preview pane": what has no picture shows Windows' own big icon for its
// type (a folder's, a program's own), as Explorer's preview pane does, instead of ours
let preview_win_icons = cx.global::<crate::settings::Settings>().effective_windows_preview_icons().applies(e.is_dir());