Merge pull request #10958 from dotCooCoo/fix/layers-new-layer-button

Layers: the new-item icon adds a layer, and New Sublayer gets its own icon
This commit is contained in:
.CooCoo authored and GitHub committed 2026-12-05 07:14:43 -08:00
commit 4ff814fe99
5 files changed
+57 -2

No files matched your search

+1
View File
@@ -255,6 +255,7 @@ Generated-in-code art is original and has no file to list. This covers the defau
| `assets/icons/dc-new-fill.svg` | VectorCraft contributors | Original work, drawn for VectorCraft | MIT OR Apache-2.0 | |
| `assets/icons/dc-new-item.svg` | VectorCraft contributors | Original work, drawn for VectorCraft | MIT OR Apache-2.0 | |
| `assets/icons/dc-new-stroke.svg` | VectorCraft contributors | Original work, drawn for VectorCraft | MIT OR Apache-2.0 | |
| `assets/icons/dc-new-sublayer.svg` | VectorCraft contributors | Original work, drawn for VectorCraft: a layer row with a new-item square nested under it | MIT OR Apache-2.0 | |
| `assets/icons/dc-objects-on-path.svg` | VectorCraft contributors | Original work, drawn for VectorCraft: three small squares along a curve | MIT OR Apache-2.0 | |
| `assets/icons/dc-options.svg` | VectorCraft contributors | Original work, drawn for VectorCraft | MIT OR Apache-2.0 | |
| `assets/icons/dc-para-bullets.svg` | VectorCraft contributors | Original work, drawn for VectorCraft: three dots, each before a line | MIT OR Apache-2.0 | |
+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="butt" stroke-linejoin="miter"><rect x="3" y="3" width="18" height="4.5" stroke-width="1.25" /><path d="M6 7.5V16H10" stroke-width="1.25" /><rect x="10" y="11" width="11" height="10" stroke-width="1.25" /><path d="M15.5 13.5V18.5M13 16H18" stroke-width="1.5" /></svg>

After

Width:  |  Height:  |  Size: 419 B

+1
View File
@@ -124,6 +124,7 @@ pub static ICONS: &[(&str, &[u8])] = &[
("dc-new-fill", include_bytes!("../../../assets/icons/dc-new-fill.svg")),
("dc-new-item", include_bytes!("../../../assets/icons/dc-new-item.svg")),
("dc-new-stroke", include_bytes!("../../../assets/icons/dc-new-stroke.svg")),
("dc-new-sublayer", include_bytes!("../../../assets/icons/dc-new-sublayer.svg")),
("dc-objects-on-path", include_bytes!("../../../assets/icons/dc-objects-on-path.svg")),
("dc-options", include_bytes!("../../../assets/icons/dc-options.svg")),
("dc-para-bullets", include_bytes!("../../../assets/icons/dc-para-bullets.svg")),
+2 -2
View File
@@ -458,8 +458,8 @@ pub(crate) fn footer(tree: &DocLayers, ui: &mut Ui, out: &mut Vec<(String, Value
.takes_drops_disabled(true)
.accepts_drops(move |d: &LayersDrag<RowId>| own(d) && !d.layers().is_empty())
.also_accepts_drops(move |d: &PanelDrag| d.appearance_for(uid, reverts).is_some()),
FooterAction::new(icon("file-plus"), tl!("Create New Layer").to_string()).enabled(new_layer_ok).accepts_drops(duplicate),
FooterAction::new(icon("plus"), tl!("Create New Sublayer").to_string()).enabled(new_sublayer_ok),
FooterAction::new(icon("dc-new-item"), tl!("Create New Layer").to_string()).enabled(new_layer_ok).accepts_drops(duplicate),
FooterAction::new(icon("dc-new-sublayer"), tl!("Create New Sublayer").to_string()).enabled(new_sublayer_ok),
FooterAction::new(icon("frame"), tl!("Make/Release Clipping Mask").to_string()),
FooterAction::new(icon("search"), if layers_only { tl!("Locate Layer").to_string() } else { tl!("Locate Object").to_string() })
.enabled(locate_ok),
+52
View File
@@ -1571,3 +1571,55 @@ fn the_order_revision_follows_what_the_display_order_reads() {
name_row(&mut app, a, "A");
assert_ne!(order(&app), closed, "an edit moves it");
}
/// The Layers panel beside the Swatches panel, for comparing their footer icons.
fn layers_and_swatches(app: &mut VectorcraftApp, ui: &mut egui::Ui) {
show(app, ui);
crate::panels::swatches::show(app, ui);
}
/// The texture of the icon drawn inside `rect`.
fn icon_texture(shapes: &[egui::Shape], rect: egui::Rect) -> egui::TextureId {
shapes
.iter()
.find_map(|shape| match shape {
egui::Shape::Mesh(mesh) if mesh.texture_id != egui::TextureId::default() && rect.contains_rect(mesh.calc_bounds()) => {
Some(mesh.texture_id)
}
_ => None,
})
.unwrap_or_else(|| panic!("no icon drawn in {rect:?}"))
}
/// Create New Layer shows the icon the other panels' new-item buttons show (here New Swatch), and Create New
/// Sublayer shows a different one, so the generic new-item glyph adds a layer rather than a sublayer. A click on
/// each makes a layer directly above the current one and a sublayer inside it.
#[test]
fn the_new_item_icon_makes_a_layer_and_the_sublayer_button_has_its_own() {
use crate::tests::panel_harness::Panel;
let (app, layer, _) = two_rects();
let mut panel = Panel::new(app, layers_and_swatches);
let (shapes, _) = panel.paint_at(2.0);
let new_item = icon_texture(&shapes, panel.rect("New Swatch"));
let new_layer = icon_texture(&shapes, panel.rect("Create New Layer"));
let new_sublayer = icon_texture(&shapes, panel.rect("Create New Sublayer"));
assert_eq!(new_layer, new_item, "Create New Layer shows the new-item icon");
assert_ne!(new_sublayer, new_item, "Create New Sublayer does not show the new-item icon");
panel.click("Create New Layer");
let added = {
let app = panel.app();
let doc = &app.session.active().unwrap().doc;
let ids: Vec<NodeId> = doc.layers.iter().map(|l| l.id).collect();
assert_eq!(ids.len(), 2, "a top-level layer is added");
assert_eq!(ids[0], layer, "directly above the current layer");
assert!(doc.node(layer).unwrap().children().into_iter().flatten().all(|c| !c.is_layer()), "and not inside it");
ids[1]
};
panel.click("Create New Sublayer");
let app = panel.app();
let doc = &app.session.active().unwrap().doc;
assert_eq!(doc.layers.len(), 2, "no top-level layer is added");
assert!(doc.node(added).unwrap().children().into_iter().flatten().any(|c| c.is_layer()), "a sublayer goes inside the current layer");
}