From d296eea8b16c138306ecab9c1a6166f94376a2ff Mon Sep 17 00:00:00 2001 From: David Mann Date: Sun, 29 Nov 2026 17:24:28 +0100 Subject: [PATCH] Options bar: centre Home, the tool icon and its arrow on the bar's line (#17946) The lead is a memoized view, and a memoized view's children take no slots on the bar's row line: they stood at the top of the view, Home and the tool icon about 6 px above the options after them and the small arrow higher still. The lead's members now sit in a row of their own, as PaintBar's do. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/lib.rs | 3 ++ .../src/options_bar_lead_centred_tests.rs | 21 ++++++++++++++ crates/ui-egui/src/panels/options_bar.rs | 28 +++++++++++-------- 3 files changed, 40 insertions(+), 12 deletions(-) create mode 100644 crates/ui-egui/src/options_bar_lead_centred_tests.rs diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index dbf4286ee13..12d036930b9 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -1020,6 +1020,9 @@ mod hidden_layer_tests; #[cfg(test)] mod warp_text_dialog_tests; +#[cfg(test)] +mod options_bar_lead_centred_tests; + #[cfg(test)] mod options_bar_mode_wheel_tests; diff --git a/crates/ui-egui/src/options_bar_lead_centred_tests.rs b/crates/ui-egui/src/options_bar_lead_centred_tests.rs new file mode 100644 index 00000000000..600262fcbc8 --- /dev/null +++ b/crates/ui-egui/src/options_bar_lead_centred_tests.rs @@ -0,0 +1,21 @@ +//! #17946: the options bar's lead (Home, the tool icon and its arrow) stands on the bar's line, centred like the +//! tool's options after it, not at the top of the bar. + +use egui::Rect; +use egui_kittest::kittest::Queryable; + +use crate::options_bar_mode_wheel_tests::{harness, mode_dropdown}; +use crate::state::Tool; + +#[test] +fn home_and_the_tool_icon_share_the_bars_centre_line() { + let h = harness(Tool::Brush); + let mode = mode_dropdown(&h); + let home = h.get_by_label("Home").rect(); + // The toolbar has a Brush Tool button too; the options bar's is the one above the canvas. + let tool = h.query_all_by_label("Brush Tool").map(|n| n.rect()).filter(|r| r.top() < mode.bottom()).collect::>(); + let [tool] = tool[..] else { panic!("one Brush Tool icon in the options bar, got {tool:?}") }; + for (name, rect) in [("Home", home), ("tool icon", tool)] { + assert!((rect.center().y - mode.center().y).abs() < 0.5, "{name} centre {} vs Mode {}", rect.center().y, mode.center().y); + } +} diff --git a/crates/ui-egui/src/panels/options_bar.rs b/crates/ui-egui/src/panels/options_bar.rs index a8491771de7..2aa8e29554c 100644 --- a/crates/ui-egui/src/panels/options_bar.rs +++ b/crates/ui-egui/src/panels/options_bar.rs @@ -8,9 +8,10 @@ use craft::behavior::{EditEvents, IconId, NumberCodec}; use craft::ui::bars::{Bar, BarHome, BarKind, BarOutput, BarTool}; use craft::ui::buttons::{IconButton, PopupMark, ToggleButton}; use craft::ui::choice::Checkbox; -use craft::ui::contract::{Bind, Entry, MemoProps, MemoView, Outbox, PopupKind, Props as _, Show as _, ShowContainer as _, Trigger}; +use craft::ui::contract::{Bind, Entry, Gap, MemoProps, MemoView, Outbox, PopupKind, Props as _, Show as _, ShowContainer as _, Trigger}; use craft::ui::display::Divider; use craft::ui::form::Field; +use craft::ui::layout_components::Row; use craft::ui::menu::Menu; use craft::ui::runtime::env::{Env, Label, UnitKind, WheelScope, with_env}; use craft::ui::text::{NumberField, RangeAlert}; @@ -287,18 +288,21 @@ fn lead(app: &mut PhotocraftApp, ui: &mut egui::Ui) { } } -/// The bar lead's view. +/// The bar lead's view. Its members sit in a row of their own: a memoized view's children take no slots on the bar's +/// line, so without the row they would stand at the top of the view, the small arrow above the icon's middle (#17946). fn lead_view(props: &mut LeadProps<'_>, ui: &mut egui::Ui) { - let home = BarHome::new(tl!("Home").to_owned(), Bind::given(props.home_on)).enabled(props.home_enabled).show(ui); - if home.events.value().is_some() { - props.out.send(LeadEvent::Home); - } - let tool = BarTool::new(icons::tool_icon(props.tool), tl!(props.tool.label()).to_owned()).enabled(!props.warping).show(ui); - // Photoshop: right-click the tool icon for Reset Tool / Reset All Tools. - let rows = [Entry::new(Reset::Tool, tl!("Reset Tool").to_owned()), Entry::new(Reset::All, tl!("Reset All Tools").to_owned())]; - if let Some(reset) = Menu::context(tl!("Tool").to_owned(), &tool.response).pick(ui, &rows).picked { - props.out.send(LeadEvent::Reset(reset)); - } + let _ = Row::new().gap(Gap::Item).show(ui, |ui, _| { + let home = BarHome::new(tl!("Home").to_owned(), Bind::given(props.home_on)).enabled(props.home_enabled).show(ui); + if home.events.value().is_some() { + props.out.send(LeadEvent::Home); + } + let tool = BarTool::new(icons::tool_icon(props.tool), tl!(props.tool.label()).to_owned()).enabled(!props.warping).show(ui); + // Photoshop: right-click the tool icon for Reset Tool / Reset All Tools. + let rows = [Entry::new(Reset::Tool, tl!("Reset Tool").to_owned()), Entry::new(Reset::All, tl!("Reset All Tools").to_owned())]; + if let Some(reset) = Menu::context(tl!("Tool").to_owned(), &tool.response).pick(ui, &rows).picked { + props.out.send(LeadEvent::Reset(reset)); + } + }); } /// The Mode, Opacity and Flow of the stamp tools, Healing and Art History: the tool's own brush's, kept per tool like its