Options bar keyed by the view fields its tool shows; status bar keyed by zoom alone (FW-365 F6)

This commit is contained in:
aiongg committed 2026-11-27 00:20:25 +00:00
1 parent 1975f8f1f7
commit bd89c1147c
4 files changed
+89 -18

No files matched your search

@@ -35,6 +35,11 @@ impl View {
.aspect(f64::from(aspect))
}
/// Takes `zoom` points per document unit, shown at `ppp` device pixels per point, and leaves the centre and rotation.
pub(crate) fn set_zoom(&mut self, zoom: f64, ppp: f32) {
self.zoom = (zoom * f64::from(ppp)) as f32;
}
/// Takes the zoom, centre and rotation of `view`, shown at `ppp` device pixels per point.
pub(crate) fn set_from(&mut self, view: &CanvasView, ppp: f32) {
self.zoom = (view.zoom * f64::from(ppp)) as f32;
@@ -201,3 +201,55 @@ fn the_menu_keys_open_a_menu_after_a_dialog_closes_with_escape() {
h.run_steps(4);
assert!(items(&h) > titles, "Alt+F opens the File menu: {} menu items, {titles} titles", items(&h));
}
/// The options bar and status bar views that ran over the next `steps` frames, summed.
fn ran_over(h: &mut H, steps: usize, name: &str) -> usize {
(0..steps)
.map(|_| {
h.run_steps(1);
views_ran(h, name)
})
.sum()
}
/// A pan with a tool whose bar shows no view field runs neither the options bar nor the status bar (it shows the zoom
/// only); a zoom runs the status bar, and the options bar only while the Zoom tool's bar shows the zoom.
#[test]
fn a_pan_runs_neither_bar_and_a_zoom_runs_the_status_bar() {
let mut h = harness();
h.state_mut().ui.tool = crate::state::Tool::Move;
h.run_steps(4);
h.state_mut().ui.views[0].center[0] += 40.0;
assert_eq!(ran_over(&mut h, 3, "OptionsSlot<"), 0, "a pan runs no options bar");
h.state_mut().ui.views[0].center[0] += 40.0;
assert_eq!(ran_over(&mut h, 3, "status_bar::StatusProps<"), 0, "a pan runs no status bar");
h.state_mut().ui.views[0].zoom *= 2.0;
let status = ran_over(&mut h, 3, "status_bar::StatusProps<");
assert!(status > 0, "a zoom runs the status bar: {status}");
}
/// The Zoom tool's bar shows the zoom, so a zoom runs it.
#[test]
fn a_zoom_runs_the_zoom_tools_options_bar() {
let mut h = harness();
h.state_mut().ui.tool = crate::state::Tool::Zoom;
h.run_steps(4);
h.state_mut().ui.views[0].zoom *= 2.0;
assert!(ran_over(&mut h, 3, "OptionsSlot<") > 0, "a zoom runs the Zoom tool's bar");
}
/// A tool option changed outside the bar runs the bar, and the frames after it replay it.
#[test]
fn a_tool_option_runs_the_options_bar_once() {
let mut h = harness();
h.state_mut().ui.tool = crate::state::Tool::Move;
h.run_steps(4);
assert_eq!(ran_over(&mut h, 2, "OptionsSlot<"), 0, "settled");
let on = h.state().ui.tool_options.move_auto_select;
h.state_mut().ui.tool_options.move_auto_select = !on;
assert!(ran_over(&mut h, 1, "OptionsSlot<") > 0, "a changed option runs the bar");
// The frame after the run settles (a run's second pass replays what the first ran); then two idle frames run nothing.
h.run_steps(1);
assert_eq!(ran_over(&mut h, 2, "OptionsSlot<"), 0, "the bar's own run leaves the version as it was");
}
+15 -4
View File
@@ -14,6 +14,7 @@ use craft::ui::contract::{MemoProps, MemoView};
use super::PhotocraftApp;
use crate::color_picker_ui::PickWindow;
use crate::state::Tool;
/// The props of a shell slot's view: the app the slot reads, which its version stands for. One type per slot, so a
/// trial and the frame's memo log tell the views apart.
@@ -65,7 +66,7 @@ pub(crate) fn show_panel(app: &mut PhotocraftApp, ui: &mut egui::Ui, id: &str) {
/// The version of the options bar: every tool option (`app.ui.tool_options`, all of which the bar shows; keys, the
/// canvas menu, the canvas and its task bars, panels and presets write them without a command), the commit and cancel
/// cells and hints of an edit the canvas opens or ends ([`options_bar::edit_key`](super::options_bar::edit_key)), the
/// Zoom tool's view, an open Free Transform, Puppet Warp or Perspective Warp, which shows its own members in place
/// Zoom and Rotate View tools' zoom and rotation ([`bar_view`]), an open Free Transform, Puppet Warp or Perspective Warp, which shows its own members in place
/// of the tool's, with what a drag on the canvas changes (the box, the picked pin, the planes; Escape ends them without
/// a command, #15547), the Crop tool's frame state, the type members' caret or selection, the brush and its presets, the
/// colours, and the vector bar's "Make" row's own two ingredients: the Pen draft's anchor count and the Work Path the
@@ -80,7 +81,7 @@ pub(crate) fn options_bar(app: &PhotocraftApp) -> u64 {
let gesture = crate::canvas::tools::in_gesture(app);
let hidden = app.session.active().map(|st| (st.doc.id.0, app.ui.hidden_work_path.as_ref().map(|(id, _)| *id)));
let paths = (app.ui.pen.as_ref().map(|p| p.draft.knots.len()), hidden);
version(app, (view(app), sessions, shown, brush(app), colours(app), gesture, paths))
version(app, (bar_view(app), sessions, shown, brush(app), colours(app), gesture, paths))
}
/// The version of the toolbar's footer: the colour chips' two colours, whether the active document is in Quick Mask and
@@ -148,7 +149,7 @@ pub(crate) fn panel(app: &PhotocraftApp, id: &str) -> u64 {
/// or `prefs.edit`, not as a counted command: units, the language, toolbar slots).
/// Whether running command `id` leaves every settling region's version as it is: a view command (zoom, fit, print size,
/// rotate) changes only the canvas view, which every region that shows it holds in its version (the Navigator, the Info
/// panel and the options bar through [`view`], the status bar in its own props), so it need not count as a command run
/// panel and the options bar through [`view`] and [`bar_view`], the status bar in its own props), so it need not count as a command run
/// and run every panel body in the next frame (#15493). While an action is recorded it counts: the Actions panel lists
/// the step it records.
pub(crate) fn changes_only_the_view(app: &PhotocraftApp, id: &str) -> bool {
@@ -226,6 +227,17 @@ fn colours(app: &PhotocraftApp) -> [u32; 8] {
bits
}
/// The part of the active document's view the options bar shows: the Zoom tool's bar the zoom, the Rotate View tool's
/// the rotation, every other tool's none (the Hand tool's bar has no view field).
fn bar_view(app: &PhotocraftApp) -> Option<u64> {
let view = crate::canvas::active_view(app)?;
match app.ui.tool {
Tool::Zoom => Some(view.zoom.to_bits()),
Tool::RotateView => Some(view.rotation.to_bits()),
_ => None,
}
}
/// The active document's view as the canvas showed it: its zoom, centre and turn.
fn view(app: &PhotocraftApp) -> Option<[u64; 5]> {
crate::canvas::active_view(app)
@@ -235,7 +247,6 @@ fn view(app: &PhotocraftApp) -> Option<[u64; 5]> {
#[cfg(test)]
mod tests {
use super::*;
use crate::state::Tool;
/// The brush, the colours, the type defaults, the tool options, the type caret, the Move tool's rollover and an
/// adjustment's live preview move the versions of the bars and panels that show them and of no other, so a drag that
+17 -14
View File
@@ -1,5 +1,5 @@
use craft::behavior::CanvasView;
use craft::behavior::kurbo::Size;
use craft::behavior::kurbo::{Point, Size};
use craft::theme::variant::Tone;
use craft::ui::bars::{Bar, BarKind, StatusItem, StatusMessage, StatusProgress, StatusReadout, StatusValues};
use craft::ui::contract::{Bind, MemoProps, MemoView, Outbox, ShowContainer as _};
@@ -40,8 +40,9 @@ 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>,
/// The zoom of the active document's main canvas as its last pass showed it, the one view field the readout shows
/// (a pan leaves it as it is); a document not yet shown has no readout.
zoom: Option<f64>,
message: Option<StatusMessage>,
out: Outbox<'a, StatusEvent>,
}
@@ -59,8 +60,8 @@ struct TrailingProps<'a> {
enum StatusEvent {
/// The readout's item was picked.
Item(StatusItem),
/// The zoom field edited the view.
View(CanvasView),
/// The zoom field set the zoom, about the view's centre.
Zoom(f64),
/// The zoom field cut an entry to its range.
InvalidZoom(InvalidZoom),
/// The job's Cancel was clicked.
@@ -77,7 +78,7 @@ 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));
let view = crate::canvas::active_view(app);
let zoom = crate::canvas::active_view(app).map(|view| view.zoom);
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)
@@ -93,14 +94,14 @@ pub fn status_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
let _ = MemoView::new("status-bar-trailing", props, trailing_view).show(ui);
})
.show(ui, |ui, _| {
let props = StatusProps { values: values.clone(), item, document, view, message: message.clone(), out: Outbox::new(&mut body_sent) };
let props = StatusProps { values: values.clone(), item, document, zoom, message: message.clone(), out: Outbox::new(&mut body_sent) };
let _ = MemoView::new("status-bar", props, body_view).show(ui);
});
let (mut picked, mut edited, mut invalid_zoom, mut cancelled) = (None, None, None, false);
for event in body_sent.into_iter().chain(trailing_sent) {
match event {
StatusEvent::Item(item) => picked = Some(item),
StatusEvent::View(new) => edited = Some(new),
StatusEvent::Zoom(new) => edited = Some(new),
StatusEvent::InvalidZoom(invalid) => invalid_zoom = Some(invalid),
StatusEvent::CancelJob => cancelled = true,
}
@@ -108,11 +109,11 @@ pub fn status_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
if let Some(picked) = picked {
chrome_ui::set_status_item(&mut app.ui.chrome, picked);
}
if let Some(new) = edited
if let Some(zoom) = edited
&& let Some(i) = app.session.active_index()
{
let ppp = app.canvas_ppp();
app.ui.views[i].set_from(&new, ppp);
app.ui.views[i].set_zoom(zoom, ppp);
}
if cancelled && let Some((id, _)) = &job {
crate::jobs_ui::cancel(app, *id);
@@ -151,14 +152,16 @@ fn body_view(props: &mut StatusProps<'_>, ui: &mut egui::Ui) {
/// The members of the status bar's body: the readout, or "No document", and the status message.
fn body_members(props: &mut StatusProps<'_>, ui: &mut egui::Ui) {
match (props.document, props.view) {
(Some(size), Some(view)) => {
match (props.document, props.zoom) {
(Some(size), Some(zoom)) => {
// The readout reads the zoom alone; the rest of the view is the document's own, which an edit leaves.
let view = CanvasView::new(egui::Rect::ZERO, Point::ZERO, zoom);
let out = StatusReadout::new(Bind::given(view), size, props.item, &props.values).show(ui);
if let Some(picked) = out.item {
props.out.send(StatusEvent::Item(picked));
}
if let Some(view) = out.view.value().copied() {
props.out.send(StatusEvent::View(view));
if let Some(view) = out.view.value() {
props.out.send(StatusEvent::Zoom(view.zoom));
}
if let Some(invalid) = out.invalid_zoom {
props.out.send(StatusEvent::InvalidZoom(invalid));