mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
Status bar as one memo view: StatusProps with the values, item, view, messages and progresses, events through an Outbox; the job's progress is a pure value (jobs_ui::status_job)
This commit is contained in:
1 parent
292cdc6dc5
commit
4a97e311c8
4 files changed
+125
-54
No files matched your search
@@ -416,9 +416,9 @@ fn collect(r: &mut Redraw, p: Piece) {
|
||||
}
|
||||
|
||||
/// The active document's redraw as the status bar shows it: "Redrawing" and how much is done.
|
||||
pub(crate) fn progress(app: &PhotocraftApp) -> Option<craft::ui::bars::StatusProgress> {
|
||||
pub(crate) fn progress(app: &PhotocraftApp) -> Option<crate::panels::status_bar::Progress> {
|
||||
let r = app.session.active().and_then(|st| app.redraws.get(&st.doc.id))?;
|
||||
Some(craft::ui::bars::StatusProgress::new(tl!("Redrawing"), Some(r.fraction())))
|
||||
Some(crate::panels::status_bar::Progress { label: tl!("Redrawing").to_owned(), fraction: Some(r.fraction()), cancel: None, refused: None })
|
||||
}
|
||||
|
||||
/// Stop document `doc`'s redraw (its canvas was redrawn some other way, or is gone).
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
|
||||
use craft::ui::bars::StatusProgress;
|
||||
use craft::ui::contract::{Bind, Props as _, Show as _, ShowContainer as _, Sizing};
|
||||
use craft::ui::dialog::{BlockingOverlay, PromptAnswer, PromptChoice, StandardPrompt};
|
||||
use craft::ui::display::{Picture, Progress, Shade, Text};
|
||||
@@ -825,27 +824,22 @@ pub fn save_progress(app: &PhotocraftApp, doc: DocId) -> Option<String> {
|
||||
app.session.job(save.job).map(|j| saving_percent(&j))
|
||||
}
|
||||
|
||||
/// The status bar's job readout (the bar's trailing group): the job's label, a progress bar, the percentage and a
|
||||
/// cancel button, "Saving" for a save. A print's cancel is shown refused: the system print queue owns it. Draws
|
||||
/// nothing when no job runs.
|
||||
pub fn status_progress(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
|
||||
let Some(j) = job_in_view(app) else { return };
|
||||
/// The job the status bar's trailing group shows, and its progress: the job's label, the fraction and a cancel
|
||||
/// button, "Saving" for a save. A print's cancel is shown refused: the system print queue owns it. `None` when no job
|
||||
/// runs.
|
||||
pub(crate) fn status_job(app: &PhotocraftApp) -> Option<(JobId, crate::panels::status_bar::Progress)> {
|
||||
let j = job_in_view(app)?;
|
||||
if j.command == "file.automate.batch" {
|
||||
return;
|
||||
return None;
|
||||
}
|
||||
let saving = app.jobs.saves.iter().any(|s| s.job == j.id);
|
||||
let more = app.session.jobs().len().saturating_sub(1);
|
||||
// A save's percentage is the component's own.
|
||||
let name = if saving { tl!("Saving").to_owned() } else { tl!(&j.label).to_owned() };
|
||||
let label = if more > 0 { format!("{name} (+{more})") } else { name };
|
||||
let mut progress = StatusProgress::new(label, shown_fraction(&j)).cancel(tl!("Cancel (Esc)").to_owned());
|
||||
// A print has already reached the spool worker; cancellation belongs to the system queue.
|
||||
if matches!(j.command.as_str(), "file.print" | "file.printOneCopy") {
|
||||
progress = progress.cancel_refused(tl!("Manage submitted jobs in the system print queue").to_owned());
|
||||
}
|
||||
if progress.show(ui).cancelled {
|
||||
cancel(app, j.id);
|
||||
}
|
||||
let refused = matches!(j.command.as_str(), "file.print" | "file.printOneCopy").then(|| tl!("Manage submitted jobs in the system print queue").to_owned());
|
||||
Some((j.id, crate::panels::status_bar::Progress { label, fraction: shown_fraction(&j), cancel: Some(tl!("Cancel (Esc)").to_owned()), refused }))
|
||||
}
|
||||
|
||||
/// Show the folder Batch worker's immutable current document in the canvas area. The worker
|
||||
|
||||
@@ -59,7 +59,7 @@ pub mod preset_panels;
|
||||
mod properties;
|
||||
pub(crate) mod registry;
|
||||
pub mod smart_ui;
|
||||
mod status_bar;
|
||||
pub(crate) mod status_bar;
|
||||
pub mod swatches_ui;
|
||||
pub(super) mod timeline_ui;
|
||||
pub(crate) mod title_bar;
|
||||
|
||||
@@ -1,54 +1,130 @@
|
||||
use std::cell::RefCell;
|
||||
|
||||
use craft::behavior::canvas::CanvasView;
|
||||
use craft::behavior::kurbo::Size;
|
||||
use craft::theme::variant::Tone;
|
||||
use craft::ui::bars::{Bar, BarKind, StatusMessage, StatusReadout};
|
||||
use craft::ui::contract::{Bind, ShowContainer as _};
|
||||
use craft::ui::bars::{Bar, BarKind, InvalidZoom, StatusItem, StatusMessage, StatusProgress, StatusReadout, StatusValues};
|
||||
use craft::ui::contract::{Bind, MemoProps, MemoView, Outbox, ShowContainer as _};
|
||||
use craft::ui::runtime::commands::CommandRef;
|
||||
|
||||
use super::{PhotocraftApp, chrome_ui};
|
||||
|
||||
// ----------------------------------------------------------------------------- status bar
|
||||
|
||||
/// A task's progress as the bar's trailing group shows it: its name, how much is done (`None` while it has reported
|
||||
/// nothing), the cancel button's label, and why it can't be cancelled.
|
||||
#[derive(Clone, Debug, PartialEq, MemoProps)]
|
||||
pub(crate) struct Progress {
|
||||
pub label: String,
|
||||
pub fraction: Option<f32>,
|
||||
pub cancel: Option<String>,
|
||||
pub refused: Option<String>,
|
||||
}
|
||||
|
||||
impl Progress {
|
||||
fn widget(&self) -> StatusProgress {
|
||||
let mut progress = StatusProgress::new(self.label.clone(), self.fraction);
|
||||
if let Some(cancel) = &self.cancel {
|
||||
progress = progress.cancel(cancel.clone());
|
||||
}
|
||||
if let Some(refused) = &self.refused {
|
||||
progress = progress.cancel_refused(refused.clone());
|
||||
}
|
||||
progress
|
||||
}
|
||||
}
|
||||
|
||||
/// Every input of the status bar.
|
||||
#[derive(MemoProps)]
|
||||
struct StatusProps<'a> {
|
||||
values: StatusValues,
|
||||
item: StatusItem,
|
||||
document: Option<Size>,
|
||||
/// The active document's main canvas as its last pass showed it; a document not yet shown has no readout.
|
||||
view: Option<CanvasView>,
|
||||
message: Option<StatusMessage>,
|
||||
render_path: Option<StatusMessage>,
|
||||
redraw: Option<Progress>,
|
||||
job: Option<Progress>,
|
||||
out: Outbox<'a, StatusEvent>,
|
||||
}
|
||||
|
||||
/// What a run of the status bar reports.
|
||||
enum StatusEvent {
|
||||
/// The readout's item was picked.
|
||||
Item(StatusItem),
|
||||
/// The zoom field edited the view.
|
||||
View(CanvasView),
|
||||
/// The zoom field cut an entry to its range.
|
||||
InvalidZoom(InvalidZoom),
|
||||
/// The job's Cancel was clicked.
|
||||
CancelJob,
|
||||
}
|
||||
|
||||
/// The status bar, in the shell's status slot: the zoom readout of the active document and the latest status
|
||||
/// message, and at the far end the render-path note, the background redraw and the background jobs' progress with
|
||||
/// Cancel (#210).
|
||||
/// Cancel (#210). One view holds the whole bar, so a frame where none of it changed replays it.
|
||||
pub fn status_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
|
||||
let values = chrome_ui::status_values(app);
|
||||
let item = chrome_ui::status_item(&app.ui.chrome);
|
||||
let document = app.session.active().map(|st| Size::new(st.doc.size.width as f64, st.doc.size.height as f64));
|
||||
// The active document's main canvas as its last pass showed it; a document not yet shown has no readout.
|
||||
let mut view = crate::canvas::active_view(app);
|
||||
let message =
|
||||
(!app.ui.status.is_empty()).then(|| StatusMessage::new(app.ui.status.clone()).tone(if app.ui.status_error { Tone::Warn } else { Tone::Neutral }));
|
||||
let render_path = chrome_ui::render_path_label(app)
|
||||
.map(|(label, tip, command)| StatusMessage::new(label).tone(Tone::Warn).command(CommandRef::new(command)).tooltip(tip));
|
||||
// The passes of a frame each report their own entries; the last pass's are the ones applied below.
|
||||
let job = crate::jobs_ui::status_job(app);
|
||||
let mut sent = Vec::new();
|
||||
let props = StatusProps {
|
||||
values: chrome_ui::status_values(app),
|
||||
item: chrome_ui::status_item(&app.ui.chrome),
|
||||
document: app.session.active().map(|st| Size::new(st.doc.size.width as f64, st.doc.size.height as f64)),
|
||||
view: crate::canvas::active_view(app),
|
||||
message: (!app.ui.status.is_empty())
|
||||
.then(|| StatusMessage::new(app.ui.status.clone()).tone(if app.ui.status_error { Tone::Warn } else { Tone::Neutral })),
|
||||
render_path: chrome_ui::render_path_label(app)
|
||||
.map(|(label, tip, command)| StatusMessage::new(label).tone(Tone::Warn).command(CommandRef::new(command)).tooltip(tip)),
|
||||
redraw: crate::background_redraw::progress(app),
|
||||
job: job.as_ref().map(|(_, progress)| progress.clone()),
|
||||
out: Outbox::new(&mut sent),
|
||||
};
|
||||
let _ = MemoView::new("status-bar", props, status_view).show(ui);
|
||||
let mut invalid_zoom = None;
|
||||
for event in sent {
|
||||
match event {
|
||||
StatusEvent::Item(picked) => chrome_ui::set_status_item(&mut app.ui.chrome, picked),
|
||||
StatusEvent::View(new) => {
|
||||
if let Some(i) = app.session.active_index() {
|
||||
let ppp = app.canvas_ppp();
|
||||
app.ui.views[i].set_from(&new, ppp);
|
||||
}
|
||||
}
|
||||
StatusEvent::InvalidZoom(invalid) => invalid_zoom = Some(invalid),
|
||||
StatusEvent::CancelJob => {
|
||||
if let Some((id, _)) = &job {
|
||||
crate::jobs_ui::cancel(app, *id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
chrome_ui::zoom_alert(app, invalid_zoom);
|
||||
}
|
||||
|
||||
/// The status bar's view.
|
||||
fn status_view(props: &mut StatusProps<'_>, ui: &mut egui::Ui) {
|
||||
let mut cancelled = false;
|
||||
let mut picked = None;
|
||||
let mut invalid_zoom = None;
|
||||
let mut view_edited = false;
|
||||
// The bar runs the trailing group before the body when it measures, so the app is borrowed by one closure at a
|
||||
// time.
|
||||
let cell = RefCell::new(&mut *app);
|
||||
let mut edited = None;
|
||||
Bar::new("", BarKind::Status)
|
||||
.trailing(|ui, _| {
|
||||
if let Some(shown) = &render_path {
|
||||
if let Some(shown) = &props.render_path {
|
||||
shown.show(ui);
|
||||
}
|
||||
let mut guard = cell.borrow_mut();
|
||||
let app = &mut **guard;
|
||||
if let Some(progress) = crate::background_redraw::progress(app) {
|
||||
progress.show(ui);
|
||||
if let Some(progress) = &props.redraw {
|
||||
progress.widget().show(ui);
|
||||
}
|
||||
if let Some(progress) = &props.job {
|
||||
cancelled |= progress.widget().show(ui).cancelled;
|
||||
}
|
||||
crate::jobs_ui::status_progress(app, ui);
|
||||
})
|
||||
.show(ui, |ui, _| {
|
||||
match (document, view.as_mut()) {
|
||||
match (props.document, props.view) {
|
||||
(Some(size), Some(view)) => {
|
||||
let out = StatusReadout::new(Bind::bound(view), size, item, &values).show(ui);
|
||||
let out = StatusReadout::new(Bind::given(view), size, props.item, &props.values).show(ui);
|
||||
picked = out.item.or(picked);
|
||||
invalid_zoom = out.invalid_zoom.or(invalid_zoom.take());
|
||||
view_edited |= !out.view.is_empty();
|
||||
edited = out.view.value().copied().or(edited);
|
||||
}
|
||||
(Some(_), None) => {}
|
||||
(None, _) => {
|
||||
@@ -56,19 +132,20 @@ pub fn status_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
|
||||
}
|
||||
}
|
||||
// A command run with no document open still reports here (#1567: File › Automate › Batch).
|
||||
if let Some(shown) = &message {
|
||||
if let Some(shown) = &props.message {
|
||||
shown.show(ui);
|
||||
}
|
||||
});
|
||||
if let Some(picked) = picked {
|
||||
chrome_ui::set_status_item(&mut app.ui.chrome, picked);
|
||||
props.out.send(StatusEvent::Item(picked));
|
||||
}
|
||||
if view_edited
|
||||
&& let Some(new) = &view
|
||||
&& let Some(i) = app.session.active_index()
|
||||
{
|
||||
let ppp = app.canvas_ppp();
|
||||
app.ui.views[i].set_from(new, ppp);
|
||||
if let Some(view) = edited {
|
||||
props.out.send(StatusEvent::View(view));
|
||||
}
|
||||
if let Some(invalid) = invalid_zoom {
|
||||
props.out.send(StatusEvent::InvalidZoom(invalid));
|
||||
}
|
||||
if cancelled {
|
||||
props.out.send(StatusEvent::CancelJob);
|
||||
}
|
||||
chrome_ui::zoom_alert(app, invalid_zoom);
|
||||
}
|
||||
Reference in new issue
Block a user