MCPcopy Create free account
hub / github.com/encounter/objdiff / jobs_ui

Function jobs_ui

objdiff-gui/src/views/jobs.rs:8–76  ·  view source on GitHub ↗
(ui: &mut egui::Ui, jobs: &mut JobQueue, appearance: &Appearance)

Source from the content-addressed store, hash-verified

6use crate::views::appearance::Appearance;
7
8pub fn jobs_ui(ui: &mut egui::Ui, jobs: &mut JobQueue, appearance: &Appearance) {
9 if ui.button("Clear").clicked() {
10 jobs.clear_errored();
11 }
12
13 let mut remove_job: Option<usize> = None;
14 let mut any_jobs = false;
15 for job in jobs.iter_mut() {
16 let Ok(status) = job.context.status.read() else {
17 continue;
18 };
19 any_jobs = true;
20 ui.separator();
21 ui.horizontal(|ui| {
22 ui.label(&status.title);
23 if ui.small_button("✖").clicked() {
24 if job.handle.is_some() {
25 if let Err(e) = job.cancel.send(()) {
26 log::error!("Failed to cancel job: {e:?}");
27 }
28 } else {
29 remove_job = Some(job.id);
30 }
31 }
32 });
33 let mut bar = ProgressBar::new(status.progress_percent);
34 if let Some(items) = &status.progress_items {
35 bar = bar.text(format!("{} / {}", items[0], items[1]));
36 }
37 bar.ui(ui);
38 const STATUS_LENGTH: usize = 80;
39 if let Some(err) = &status.error {
40 let err_string = format!("{err:#}");
41 ui.colored_label(
42 appearance.delete_color,
43 if err_string.len() > STATUS_LENGTH - 10 {
44 format!("Error: {}…", &err_string[0..STATUS_LENGTH - 10])
45 } else {
46 format!("Error: {:width$}", err_string, width = STATUS_LENGTH - 7)
47 },
48 )
49 .on_hover_text_at_pointer(RichText::new(&err_string).color(appearance.delete_color))
50 .context_menu(|ui| {
51 if ui.button("Copy full message").clicked() {
52 ui.ctx().copy_text(err_string);
53 }
54 });
55 } else {
56 ui.label(if status.status.len() > STATUS_LENGTH - 3 {
57 format!("{}…", &status.status[0..STATUS_LENGTH - 3])
58 } else {
59 format!("{:width$}", &status.status, width = STATUS_LENGTH)
60 })
61 .on_hover_text_at_pointer(&status.status)
62 .context_menu(|ui| {
63 if ui.button("Copy full message").clicked() {
64 ui.ctx().copy_text(status.status.clone());
65 }

Callers 1

jobs_windowFunction · 0.85

Calls 6

clear_erroredMethod · 0.80
iter_mutMethod · 0.80
is_someMethod · 0.80
uiMethod · 0.80
removeMethod · 0.80
separatorMethod · 0.45

Tested by

no test coverage detected