1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
use crate::i18n::{I18N, Language};
use crate::messages::Msg;
use crate::progress::{Job, Stage};
use std::sync::{
Arc,
atomic::{AtomicBool, Ordering},
};
pub struct BlockingOverlay {
title: String,
description: Option<String>,
}
impl BlockingOverlay {
#[must_use]
pub fn new(title: impl Into<String>) -> Self {
Self {
title: title.into(),
description: None,
}
}
#[must_use]
pub fn description(mut self, desc: impl Into<String>) -> Self {
self.description = Some(desc.into());
self
}
pub fn show(
self,
ctx: &egui::Context,
open: &mut bool,
job: Option<&Job<Stage>>,
cancel: &Arc<AtomicBool>,
lang: Language,
) {
if !*open {
return;
}
let theme = crate::theme::shadcn_theme_ext::ShadcnThemeExt::shadcn_theme(ctx);
let spacing = crate::responsive::responsive_ext::ResponsiveExt::responsive_spacing(ctx);
let screen = ctx.input(egui::InputState::viewport_rect);
let _ = crate::widgets::overlay_common::paint_backdrop(
ctx,
"blocking_backdrop",
crate::widgets::overlay_common::BACKDROP_ALPHA,
);
let max_panel_width = (screen.width() - 2.0 * spacing.page_padding - 50.0).max(0.0);
let panel_width = 380.0_f32.clamp(0.0, max_panel_width);
let _ = egui::Area::new(egui::Id::new("blocking_panel"))
.order(egui::Order::Foreground)
.anchor(egui::Align2::CENTER_CENTER, egui::Vec2::ZERO)
.show(ctx, |ui| {
let frame = egui::Frame::NONE
.fill(theme.card)
.inner_margin(egui::Margin::same(24))
.corner_radius(egui::CornerRadius::same(crate::utils::f32_to_u8_clamped(
theme.radius + 2.0,
)))
.stroke(egui::Stroke::new(1.0, theme.border))
.shadow(egui::Shadow {
offset: [0, 8],
blur: 24,
spread: 0,
color: egui::Color32::from_black_alpha(12),
});
let _ = frame.show(ui, |content_ui| {
content_ui.set_max_width(panel_width);
let _ = content_ui.vertical(|inner| {
let _ = inner.horizontal(|row| {
let _ = row.add(crate::Spinner::new().size(18.0));
row.add_space(8.0);
let _ = row.label(
egui::RichText::new(&self.title)
.color(theme.foreground)
.size(16.0)
.strong(),
);
});
if let Some(desc) = &self.description {
inner.add_space(8.0);
let _ = inner.label(
egui::RichText::new(desc)
.color(theme.muted_foreground)
.size(13.0),
);
}
if let Some(j) = job {
inner.add_space(12.0);
let pct = f32::from(j.percent()) / 100.0;
let _ = inner.add(crate::Progress::new(pct));
inner.add_space(6.0);
let name = j.name.as_deref().unwrap_or("");
let label = if name.is_empty() {
format!(
"{} / {} ({}%)",
functora_core::files::format_size(j.done),
functora_core::files::format_size(j.total),
j.percent()
)
} else {
format!(
"{name}: {} / {} ({}%)",
functora_core::files::format_size(j.done),
functora_core::files::format_size(j.total),
j.percent()
)
};
let _ = inner.label(
egui::RichText::new(label)
.color(theme.muted_foreground)
.size(12.0),
);
} else {
inner.add_space(12.0);
let _ = inner.label(
egui::RichText::new(Msg::Preparing.render(lang))
.color(theme.muted_foreground)
.size(12.0),
);
}
inner.add_space(16.0);
let is_cancelling = cancel.load(Ordering::Relaxed);
let _ = inner.with_layout(
egui::Layout::right_to_left(egui::Align::Center),
|right| {
if is_cancelling {
let _ = right.add(
crate::Button::new(Msg::Cancelling.render(lang))
.variant(crate::ButtonVariant::Outline)
.size(crate::ComponentSize::Sm)
.enabled(false),
);
} else if right
.add(
crate::Button::new(Msg::Cancel.render(lang))
.variant(crate::ButtonVariant::Outline)
.size(crate::ComponentSize::Sm),
)
.clicked()
{
cancel.store(true, Ordering::Relaxed);
}
},
);
});
});
});
ctx.request_repaint();
}
}