Skip to content

Commit

Permalink
Determine maximum image size from connected monitors
Browse files Browse the repository at this point in the history
  • Loading branch information
Futsch1 committed Feb 20, 2022
1 parent 1562012 commit a1f7631
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.

### Changed

-
- Max image size for caching now depends on the resolution of the largest connected monitor

### Added

Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ ffmpeg-next = {version = "4.4", features = ["format", "codec", "software-scaling
fast_image_resize = "0.7"
rawloader = "0.37.0"
imagepipe = "0.4.0"
winit = "0.26"

[dev-dependencies]
base64 = "0.13"
Expand Down
13 changes: 7 additions & 6 deletions src/controller/items_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ pub struct ItemsController {

impl ItemsController {
/// Create a new items controller instance
pub fn new(item_list: Arc<Mutex<ItemList>>) -> Self {
pub fn new(item_list: Arc<Mutex<ItemList>>, max_resolution: (u32, u32)) -> Self {
let mut image_cache = image_cache::ImageCache::new();
image_cache.restrict_size(1600, 1000);

image_cache.restrict_size(max_resolution.0, max_resolution.1);

Self {
item_list,
Expand Down Expand Up @@ -345,7 +346,7 @@ mod tests {
#[test]
fn test_populate() {
let item_list = Arc::new(Mutex::new(ItemList::new()));
let mut items_controller = ItemsController::new(item_list.clone());
let mut items_controller = ItemsController::new(item_list.clone(), (0, 0));
let mut filters = build_filters();
{
let mut item_list = item_list.lock().unwrap();
Expand Down Expand Up @@ -397,7 +398,7 @@ mod tests {
#[test]
fn test_take_over() {
let item_list = Arc::new(Mutex::new(ItemList::new()));
let mut items_controller = ItemsController::new(item_list.clone());
let mut items_controller = ItemsController::new(item_list.clone(), (0, 0));
let window = ImageSieve::new();
let window_weak = window.as_weak();
let filters = build_filters();
Expand Down Expand Up @@ -434,7 +435,7 @@ mod tests {
#[test]
fn test_select_item() {
let item_list = Arc::new(Mutex::new(ItemList::new()));
let mut items_controller = ItemsController::new(item_list.clone());
let mut items_controller = ItemsController::new(item_list.clone(), (0, 0));
let window = ImageSieve::new();
let window_weak = window.as_weak();
let filters = build_filters();
Expand Down Expand Up @@ -474,7 +475,7 @@ mod tests {
#[test]
fn test_update_list() {
let item_list = Arc::new(Mutex::new(ItemList::new()));
let mut items_controller = ItemsController::new(item_list.clone());
let mut items_controller = ItemsController::new(item_list.clone(), (0, 0));
assert!(!items_controller.update_list_model());
let filters = build_filters();
{
Expand Down
18 changes: 17 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,23 @@ extern crate image_sieve;
use image_sieve::main_window;

fn main() {
let main_window = main_window::MainWindow::new();
let main_window = main_window::MainWindow::new(get_max_resolution());

main_window.run();
}

/// Determines the maximum resolution of all available monitors.
fn get_max_resolution() -> (u32, u32) {
let mut resolution = (0, 0);
let event_loop = winit::event_loop::EventLoop::new();
for monitor in event_loop.available_monitors() {
if monitor.size().width > resolution.0 || monitor.size().height > resolution.1 {
resolution = (monitor.size().width, monitor.size().height);
}
}
if resolution.0 == 0 || resolution.1 == 0 {
(1920, 1080)
} else {
resolution
}
}
10 changes: 7 additions & 3 deletions src/main_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub struct MainWindow {

impl Default for MainWindow {
fn default() -> Self {
Self::new()
Self::new((0, 0))
}
}

Expand All @@ -62,7 +62,7 @@ impl Debug for MainWindow {

impl MainWindow {
/// Creates a new main window and initializes it from saved settings
pub fn new() -> Self {
pub fn new(max_resolution: (u32, u32)) -> Self {
// Load settings and item list
let settings: Settings =
JsonPersistence::load(&get_settings_filename()).unwrap_or_else(Settings::new);
Expand All @@ -72,7 +72,11 @@ impl MainWindow {
let item_list = Arc::new(Mutex::new(item_list));

let events_controller = Rc::new(RefCell::new(EventsController::new(item_list.clone())));
let items_controller = Rc::new(RefCell::new(ItemsController::new(item_list.clone())));
// Use the determinted max resolution and substract the width and height of on-screen controls not available for images
let items_controller = Rc::new(RefCell::new(ItemsController::new(
item_list.clone(),
(max_resolution.0 - 320, max_resolution.1 - 240),
)));
let sieve_result_model = Rc::new(slint::VecModel::<SieveResult>::default());

// Construct main window
Expand Down

0 comments on commit a1f7631

Please sign in to comment.