Merge pull request #10050 from dotCooCoo/fix/pathfinder-disabled-shape-modes-dim

Pathfinder: Shape Modes buttons dim while they are off
This commit is contained in:
.CooCoo authored and GitHub committed 2026-11-29 09:06:31 -08:00
commit 0fe52b0a19
2 files changed
+32 -1

No files matched your search

+4 -1
View File
@@ -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))
@@ -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();