From c0704b7bb02d93766e1281dffd77a9e7de37de97 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 28 Nov 2026 22:31:01 -0800 Subject: [PATCH] Pathfinder: Shape Modes buttons dim while they are off With nothing selected the four Shape Modes buttons are off, but their icon was drawn through a glyph that paints the icon's own colors and ignores the off color, so they stayed at full strength while the Pathfinders row dimmed. The buttons now show the set icon, and the glyph is used only while members with different modes are selected, where it adds the question mark and the buttons are on. --- crates/ui-egui/src/panels/pathfinder.rs | 5 +++- .../ui-egui/src/panels/tests_icon_buttons.rs | 28 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/panels/pathfinder.rs b/crates/ui-egui/src/panels/pathfinder.rs index d1ee58262d..1855261d6e 100644 --- a/crates/ui-egui/src/panels/pathfinder.rs +++ b/crates/ui-egui/src/panels/pathfinder.rs @@ -136,9 +136,12 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { Row::new().gap(Gap::Item).show(ui, |ui, _| { for ((icon, label, op), mode) in SHAPE_MODES.into_iter().zip(ShapeMode::ALL) { let glyph = ShapeModeGlyph { icon: IconId::new(icon), mixed }; + // The glyph paints the icon in its own inks, so it is used only for the question mark (mixed modes + // keep the buttons on). Otherwise the button paints the set icon, dimmed while it is off. + let spec = if mixed { IconSpec::glyph(&glyph) } else { IconSpec::svg(IconId::new(icon)) }; let value = if mixed { Mixed::Mixed } else { Mixed::Same(shared == Some(mode)) }; let out = ToggleButton::new(tl!(label).to_string(), Bind::given(value)) - .icon(IconSpec::glyph(&glyph)) + .icon(spec) .icon_only() .enabled(count >= 2) .tooltip(tip(label)) diff --git a/crates/ui-egui/src/panels/tests_icon_buttons.rs b/crates/ui-egui/src/panels/tests_icon_buttons.rs index b7a1ee607e..ff498339a4 100644 --- a/crates/ui-egui/src/panels/tests_icon_buttons.rs +++ b/crates/ui-egui/src/panels/tests_icon_buttons.rs @@ -54,6 +54,34 @@ fn the_align_panel_icons_fill_their_square() { assert_full_size(align::show, &names); } +/// The colors the icon meshes inside `rect` are tinted with, sorted and without repeats. +fn icon_tints(shapes: &[Shape], rect: Rect) -> Vec<[u8; 4]> { + let mut tints: Vec<[u8; 4]> = shapes + .iter() + .filter_map(|shape| match shape { + Shape::Mesh(mesh) if mesh.texture_id != TextureId::default() && rect.contains_rect(mesh.calc_bounds()) => Some(mesh), + _ => None, + }) + .flat_map(|mesh| mesh.vertices.iter().map(|v| v.color.to_array())) + .collect(); + tints.sort_unstable(); + tints.dedup(); + tints +} + +#[test] +fn the_shape_modes_dim_with_the_pathfinders_while_they_are_off() { + let mut app = app_with_rect(); + run(&mut app, "select.none", json!({})); + let mut panel = Panel::new(app, pathfinder::show); + let (shapes, _) = panel.paint_at(2.0); + let off = icon_tints(&shapes, panel.rect("Divide")); + assert!(!off.is_empty(), "no icon drawn for Divide"); + for (_, name, _) in pathfinder::SHAPE_MODES { + assert_eq!(icon_tints(&shapes, panel.rect(name)), off, "{name} is off and should be painted as the off Divide button is"); + } +} + #[test] fn the_pathfinder_panel_icons_fill_their_square() { let names: Vec<&str> = pathfinder::SHAPE_MODES.iter().chain(&pathfinder::PATHFINDERS).map(|r| r.1).collect();