Skip to content

Commit

Permalink
Show precise time in progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
Shtoyan committed Oct 11, 2023
1 parent 9a6aff8 commit 281cd0a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
12 changes: 12 additions & 0 deletions crates/kfuz2_egui/src/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,13 @@ fn parse_decompression_result(
gui_app
.pbar
.time_elapsed
.0
.swap(start.elapsed().as_secs(), Ordering::Relaxed);
gui_app
.pbar
.time_elapsed
.1
.swap(start.elapsed().subsec_millis(), Ordering::Relaxed);
}

fn parse_compression_result(
Expand Down Expand Up @@ -182,7 +188,13 @@ fn parse_compression_result(
gui_app
.pbar
.time_elapsed
.0
.swap(start.elapsed().as_secs(), Ordering::Relaxed);
gui_app
.pbar
.time_elapsed
.1
.swap(start.elapsed().subsec_millis(), Ordering::Relaxed);
}

/// Try to compress given file.
Expand Down
10 changes: 6 additions & 4 deletions crates/kfuz2_egui/src/ui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use kfuz2_lib::types::LogLevel;
use std::{
path::PathBuf,
sync::{
atomic::{AtomicBool, AtomicU16, AtomicU64, Ordering},
atomic::{AtomicBool, AtomicU16, AtomicU32, AtomicU64, Ordering},
Arc,
},
};
Expand Down Expand Up @@ -60,15 +60,17 @@ pub struct ProgressBarStuff {
pub file_num_failed: Arc<AtomicU16>,
/// Ignored files number.
pub file_num_ignored: Arc<AtomicU16>,
pub time_elapsed: Arc<AtomicU64>,
/// Time elapsed for current operation, as `seconds` + `milliseconds`
pub time_elapsed: Arc<(AtomicU64, AtomicU32)>,
}

impl ProgressBarStuff {
pub fn reset(&self) {
self.file_num_success.swap(0u16, Ordering::Relaxed);
self.file_num_failed.swap(0u16, Ordering::Relaxed);
self.file_num_ignored.swap(0u16, Ordering::Relaxed);
self.time_elapsed.swap(0u64, Ordering::Relaxed);
self.time_elapsed.0.swap(0u64, Ordering::Relaxed);
self.time_elapsed.1.swap(0u32, Ordering::Relaxed);
}
}

Expand All @@ -81,7 +83,7 @@ impl Default for ProgressBarStuff {
file_num_success: Arc::new(AtomicU16::new(0u16)),
file_num_failed: Arc::new(AtomicU16::new(0u16)),
file_num_ignored: Arc::new(AtomicU16::new(0u16)),
time_elapsed: Arc::new(AtomicU64::new(0u64)),
time_elapsed: Arc::new((AtomicU64::new(0u64), AtomicU32::new(0u32))),
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions crates/kfuz2_egui/src/ui/panel_center.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,10 @@ fn render_progress(ui: &mut egui::Ui, gui_app: &mut super::app::Kfuz2Egui) {
}
let progress_bar = egui::ProgressBar::new(progress)
.text(format!(
"{:.1}% Time elapsed: {} seconds.",
"{:.1}% Time elapsed: {}.{} seconds.",
progress * 100f32,
gui_app.pbar.time_elapsed.load(Ordering::Relaxed)
gui_app.pbar.time_elapsed.0.load(Ordering::Relaxed),
gui_app.pbar.time_elapsed.1.load(Ordering::Relaxed)
))
.animate(gui_app.pbar.animate);

Expand Down

0 comments on commit 281cd0a

Please sign in to comment.