Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Merge pull request #1898 from storytold/community/1734-fxdrag

BFlat9823f4ea08f4
diff --cc crates/ui-egui/src/panels.rs
index 29499f922,18bb47216..1e89eab80
--- a/crates/ui-egui/src/panels.rs
+++ b/crates/ui-egui/src/panels.rs
@@@ -1648,74 -1590,81 +1654,75 @@@ fn layers(app: &mut PhotocraftApp, ui:
// End any layer drag after every row has had a chance to accept the drop.
if ctx.input(|i| i.pointer.any_released()) {
ctx.data_mut(|d| d.remove::<u64>(egui::Id::new("layer-drag")));
+ ctx.data_mut(|d| d.remove::<FxDrag>(fx_drag_key()));
}
- ui.add_space(4.0);
- widgets::hairline(ui);
- ui.add_space(2.0);
- ui.horizontal(|ui| {
- ui.spacing_mut().item_spacing.x = 2.0;
- ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
- let trash = icons::button(ui, "trash", 26.0, false, tl!("Delete layer"));
- if trash.clicked() {
- actions.push(("layer.delete".into(), json!({})));
+ widgets::panel_footer(ui, |ui| {
+ let trash = icons::button(ui, "trash", 26.0, false, tl!("Delete layer"));
+ if trash.clicked() {
+ actions.push(("layer.delete".into(), json!({})));
+ }
+ actions.extend(footer_drop(ui, &trash, footer_drag, "layer.delete"));
+ let new_layer = icons::button(ui, "square-plus", 26.0, false, &crate::shortcuts::tip_label(app, "Create a new layer", "layer.new.layer"));
+ if new_layer.clicked() {
+ actions.push(("layer.new.layer".into(), json!({})));
+ }
+ actions.extend(footer_drop(ui, &new_layer, footer_drag, "layer.duplicate"));
+ let group = icons::button(ui, "folder", 26.0, false, tl!("Create a new group"));
+ if group.clicked() {
+ actions.push(("layer.new.group".into(), json!({})));
+ }
+ actions.extend(footer_drop(ui, &group, footer_drag, "layer.groupLayers"));
+ let adj = footer_menu_button(ui, "adjustment-layer", 26.0, tl!("Create new fill or adjustment layer"));
+ egui::Popup::menu(&adj).open_memory(footer_menu_right_click(&adj)).show(|ui| {
+ ui.set_min_width(190.0);
+ for c in photocraft_engine::command_specs().iter().filter(|c| c.id.starts_with("layer.newAdjustmentLayer.")) {
+ if ui.button(tl!(c.label).trim_end_matches('…')).clicked() {
+ actions.push((c.id.into(), json!({})));
+ ui.close();
+ }
}
- actions.extend(footer_drop(ui, &trash, footer_drag, "layer.delete"));
- let new_layer = icons::button(ui, "square-plus", 26.0, false, &crate::shortcuts::tip_label(app, "Create a new layer", "layer.new.layer"));
- if new_layer.clicked() {
- actions.push(("layer.new.layer".into(), json!({})));
+ ui.separator();
+ if ui.button(tl!("Solid Color…")).clicked() {
+ actions.push(("layer.newFillLayer.solidColor".into(), json!({})));
+ ui.close();
}
- actions.extend(footer_drop(ui, &new_layer, footer_drag, "layer.duplicate"));
- let group = icons::button(ui, "folder", 26.0, false, tl!("Create a new group"));
- if group.clicked() {
- actions.push(("layer.new.group".into(), json!({})));
+ if ui.button(tl!("Gradient…")).clicked() {
+ actions.push(("layer.newFillLayer.gradient".into(), json!({})));
+ ui.close();
}
- actions.extend(footer_drop(ui, &group, footer_drag, "layer.groupLayers"));
- let adj = footer_menu_button(ui, "contrast", 26.0, tl!("Create new fill or adjustment layer"));
- egui::Popup::menu(&adj).open_memory(footer_menu_right_click(&adj)).show(|ui| {
- ui.set_min_width(190.0);
- for c in photocraft_engine::command_specs().iter().filter(|c| c.id.starts_with("layer.newAdjustmentLayer.")) {
- if ui.button(tl!(c.label).trim_end_matches('…')).clicked() {
- actions.push((c.id.into(), json!({})));
- ui.close();
- }
- }
- ui.separator();
- if ui.button(tl!("Solid Color…")).clicked() {
- actions.push(("layer.newFillLayer.solidColor".into(), json!({})));
- ui.close();
- }
- if ui.button(tl!("Gradient…")).clicked() {
- actions.push(("layer.newFillLayer.gradient".into(), json!({})));
- ui.close();
- }
- });
- if icons::button(
- ui,
- "square-dot",
- 26.0,
- false,
- &crate::i18n::fmt(tl!("Add a mask (from the selection; {key} inverts)"), &[("key", &crate::shortcuts::pretty("Alt"))]),
- )
- .clicked()
- {
- let alt = ui.input(|i| i.modifiers.alt);
- actions.push((crate::layer_menu_ui::add_mask_command(doc.selection.is_some(), alt).into(), json!({})));
+ });
+ if icons::button(
+ ui,
+ "layer-mask",
+ 26.0,
+ false,
+ &crate::i18n::fmt(tl!("Add a mask (from the selection; {key} inverts)"), &[("key", &crate::shortcuts::pretty("Alt"))]),
+ )
+ .clicked()
+ {
+ let alt = ui.input(|i| i.modifiers.alt);
+ actions.push((crate::layer_menu_ui::add_mask_command(doc.selection.is_some(), alt).into(), json!({})));
+ }
+ let fx = fx_button(ui, 26.0, tl!("Add a layer style"));
+ egui::Popup::menu(&fx).open_memory(footer_menu_right_click(&fx)).show(|ui| {
+ ui.set_min_width(180.0);
+ if ui.button(tl!("Blending Options…")).clicked() {
+ crate::layer_style::open(app, None);
+ ui.close();
}
- let fx = fx_button(ui, 26.0, tl!("Add a layer style"));
- egui::Popup::menu(&fx).open_memory(footer_menu_right_click(&fx)).show(|ui| {
- ui.set_min_width(180.0);
- if ui.button(tl!("Blending Options…")).clicked() {
- crate::layer_style::open(app, None);
+ ui.separator();
+ for &(kind, label) in crate::layer_style::KINDS {
+ if ui.button(format!("{}…", tl!(label))).clicked() {
+ crate::layer_style::open(app, Some(kind));
ui.close();
}
- ui.separator();
- for &(kind, label) in crate::layer_style::KINDS {
- if ui.button(format!("{}…", tl!(label))).clicked() {
- crate::layer_style::open(app, Some(kind));
- ui.close();
- }
- }
- });
- // Photoshop's footer starts with Link Layers (enabled with two or more layers selected).
- let can_link = app.session.is_enabled("layer.linkLayers");
- if ui.add_enabled_ui(can_link, |ui| icons::button(ui, "link", 26.0, false, tl!("Link layers"))).inner.clicked() {
- actions.push(("layer.linkLayers".into(), json!({})));
}
});
+ // Photoshop's footer starts with Link Layers (enabled with two or more layers selected).
+ let can_link = app.session.is_enabled("layer.linkLayers");
+ if ui.add_enabled_ui(can_link, |ui| icons::button(ui, "link-2", 26.0, false, tl!("Link layers"))).inner.clicked() {
+ actions.push(("layer.linkLayers".into(), json!({})));
+ }
});
for (id, p) in actions {
if id == "ui.maskTarget" {