Skip to content

Commit

Permalink
Merge pull request #291 from diegostafa/fix-high-cpu-usage
Browse files Browse the repository at this point in the history
Fix high cpu usage when started without images
  • Loading branch information
woelper authored Mar 7, 2024
2 parents 83d6325 + be6f192 commit 8489e0a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
13 changes: 6 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1034,13 +1034,12 @@ fn drawe(app: &mut App, gfx: &mut Graphics, plugins: &mut Plugins, state: &mut O
}

if state.reset_image {
let draw_area = ctx.available_rect();
let window_size = nalgebra::Vector2::new(
draw_area.width().min(app.window().width() as f32),
draw_area.height().min(app.window().height() as f32),
);

if let Some(current_image) = &state.current_image {
let draw_area = ctx.available_rect();
let window_size = nalgebra::Vector2::new(
draw_area.width().min(app.window().width() as f32),
draw_area.height().min(app.window().height() as f32),
);
let img_size = current_image.size_vec();
state.image_geometry.scale = (window_size.x / img_size.x)
.min(window_size.y / img_size.y)
Expand All @@ -1053,8 +1052,8 @@ fn drawe(app: &mut App, gfx: &mut Graphics, plugins: &mut Plugins, state: &mut O
state.image_geometry.offset.y += draw_area.top();
debug!("Image has been reset.");
state.reset_image = false;
app.window().request_frame();
}
app.window().request_frame();
}

// Settings come last, as they block keyboard grab (for hotkey assigment)
Expand Down
6 changes: 2 additions & 4 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2047,16 +2047,14 @@ pub fn main_menu(ui: &mut Ui, state: &mut OculanteState, app: &mut App, gfx: &mu
.unwrap_or_default()
));
}
}

if !state.is_loaded {
if let Some(p) = &state.current_path {
if !state.is_loaded {
ui.horizontal(|ui| {
ui.add(egui::Spinner::default());
ui.label(format!("Loading {}", p.display()));
});
app.window().request_frame();
}
app.window().request_frame();
}

drag_area(ui, state, app);
Expand Down

0 comments on commit 8489e0a

Please sign in to comment.