Add layer context menu for properties and selection actions
This commit is contained in:
parent
952c407346
commit
3908647328
|
|
@ -970,6 +970,86 @@ impl Editor {
|
|||
ui.colored_label(AMBER, &self.error);
|
||||
}
|
||||
}
|
||||
fn layer_context_menu(&mut self, ui: &mut egui::Ui) {
|
||||
ui.set_min_width(210.0);
|
||||
let selected = self.layout.selected_indices();
|
||||
if let Some(i) = self.layout.selected() {
|
||||
ui.weak(label(i));
|
||||
if ui.button("Layer properties…").clicked() {
|
||||
self.format_draft = Some(FormatDraft::new(&self.layout, i));
|
||||
ui.close_menu();
|
||||
}
|
||||
let crop_label = if self.edit_content {
|
||||
"Done adjusting crop"
|
||||
} else {
|
||||
"Adjust layer crop"
|
||||
};
|
||||
if ui
|
||||
.button(crop_label)
|
||||
.on_hover_text(
|
||||
"Change crop zoom and offset inside the layer; keep its visible box fixed.",
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
self.edit_content = !self.edit_content;
|
||||
ui.close_menu();
|
||||
}
|
||||
} else if !selected.is_empty() {
|
||||
ui.weak(format!("{} layers selected", selected.len()));
|
||||
ui.menu_button("Resize together", |ui| {
|
||||
for (mode, name) in [
|
||||
(ResizeMode::Individual, "Individual layers"),
|
||||
(ResizeMode::Same, "Same handles"),
|
||||
(ResizeMode::Mirror, "Mirror horizontally"),
|
||||
(ResizeMode::Opposite, "Opposite handles"),
|
||||
] {
|
||||
let enabled = matches!(mode, ResizeMode::Individual | ResizeMode::Same)
|
||||
|| selected.len() == 2;
|
||||
if ui
|
||||
.add_enabled(
|
||||
enabled,
|
||||
egui::Button::new(name).selected(self.resize_mode == mode),
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
self.resize_mode = mode;
|
||||
ui.close_menu();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
if !selected.is_empty() {
|
||||
ui.checkbox(&mut self.keep_aspect_ratio, "Keep aspect ratio");
|
||||
ui.menu_button("Align…", |ui| self.alignment_menu(ui));
|
||||
ui.separator();
|
||||
if ui.button("Copy layer values").clicked() {
|
||||
self.copy(ui.ctx());
|
||||
ui.close_menu();
|
||||
}
|
||||
if ui.button("Lock selected layers").clicked() {
|
||||
for &i in &selected {
|
||||
self.layout.set_locked(i, true);
|
||||
}
|
||||
self.edit_content = false;
|
||||
self.sync();
|
||||
ui.close_menu();
|
||||
}
|
||||
if ui.button("Hide selected layers").clicked() {
|
||||
for &i in &selected {
|
||||
self.layout.set_visible(i, false);
|
||||
}
|
||||
self.edit_content = false;
|
||||
self.sync();
|
||||
ui.close_menu();
|
||||
}
|
||||
ui.separator();
|
||||
}
|
||||
if ui.button("Output format…").clicked() {
|
||||
self.output_draft = Some(OutputDraft::new(self.layout.formats().output));
|
||||
ui.close_menu();
|
||||
}
|
||||
}
|
||||
|
||||
fn alignment_inspector(&mut self, ui: &mut egui::Ui, ink: &Ink, w: f32) {
|
||||
ink.text(0.0, 150.0, "2 layers selected", 25.0, TEXT);
|
||||
ink.text(
|
||||
|
|
@ -1470,6 +1550,20 @@ impl Editor {
|
|||
}
|
||||
});
|
||||
}
|
||||
if response.secondary_clicked()
|
||||
&& let Some(p) = pointer
|
||||
{
|
||||
let point = (p - origin) / scale;
|
||||
let hit = self
|
||||
.content_hit(p, origin, scale)
|
||||
.or_else(|| self.layout.hit([point.x as f64, point.y as f64]));
|
||||
if hit.is_none_or(|i| !self.layout.selection_mask()[i]) {
|
||||
self.layout.select(hit);
|
||||
self.edit_content = false;
|
||||
}
|
||||
self.sync();
|
||||
}
|
||||
response.context_menu(|ui| self.layer_context_menu(ui));
|
||||
let screen = Ink {
|
||||
painter: ui.painter_at(area),
|
||||
origin,
|
||||
|
|
@ -2879,6 +2973,63 @@ mod tests {
|
|||
click_shift(&mut app, &ctx, row.center());
|
||||
assert_eq!(app.layout.selected(), Some(1));
|
||||
}
|
||||
#[test]
|
||||
fn canvas_context_menu_selects_target_preserves_groups_and_opens_properties() {
|
||||
for grouped in [false, true] {
|
||||
let mut app = Editor::default();
|
||||
if grouped {
|
||||
app.layout.set_selection([true; 2]);
|
||||
}
|
||||
let before = *app.layout.layers();
|
||||
let ctx = egui::Context::default();
|
||||
let output = frame(&mut app, &ctx, vec![]);
|
||||
let pos = layer_rects(&output)[0].center();
|
||||
let secondary = |pressed| egui::Event::PointerButton {
|
||||
pos,
|
||||
button: egui::PointerButton::Secondary,
|
||||
pressed,
|
||||
modifiers: egui::Modifiers::NONE,
|
||||
};
|
||||
frame(
|
||||
&mut app,
|
||||
&ctx,
|
||||
vec![egui::Event::PointerMoved(pos), secondary(true)],
|
||||
);
|
||||
frame(&mut app, &ctx, vec![secondary(false)]);
|
||||
let output = frame(&mut app, &ctx, vec![]);
|
||||
assert_eq!(app.layout.selection_mask(), [true, grouped]);
|
||||
assert_eq!(*app.layout.layers(), before);
|
||||
let title = if grouped {
|
||||
"Lock selected layers"
|
||||
} else {
|
||||
"Layer properties…"
|
||||
};
|
||||
let pos = output
|
||||
.shapes
|
||||
.iter()
|
||||
.find_map(|s| match &s.shape {
|
||||
egui::Shape::Text(t) if t.galley.text() == title => {
|
||||
Some(t.pos + t.galley.size() / 2.0)
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.expect("context menu action");
|
||||
frame(
|
||||
&mut app,
|
||||
&ctx,
|
||||
vec![egui::Event::PointerMoved(pos), mouse(pos, true)],
|
||||
);
|
||||
frame(&mut app, &ctx, vec![mouse(pos, false)]);
|
||||
if grouped {
|
||||
assert!(app.layout.locked(0) && app.layout.locked(1));
|
||||
assert!(app.layout.selected_indices().is_empty());
|
||||
} else {
|
||||
assert!(app.format_draft.is_some());
|
||||
}
|
||||
assert_eq!(*app.layout.layers(), before);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn selected_layer_is_painted_last_and_keeps_overlap_clicks() {
|
||||
let mut app = Editor::default();
|
||||
|
|
|
|||
|
|
@ -142,6 +142,13 @@ clipboard testing against a running draw.io instance remains to be done.
|
|||
offsets are not copied. Crop zoom is included separately as a percentage and
|
||||
can be toggled on paste. This is not a native WebRCS clipboard payload.
|
||||
|
||||
Right-click a layer for **Layer properties**, **Adjust layer crop**, aspect-ratio
|
||||
locking, alignment, copying values, and lock/hide actions. Right-clicking a layer
|
||||
already in a selection keeps the whole selection and offers **Resize together**.
|
||||
Right-clicking an unselected layer selects it first. Locked/hidden layers remain
|
||||
protected; use the layer list to unlock/show them. Right-click empty canvas for
|
||||
**Output format**.
|
||||
|
||||
## Resize selected layers together
|
||||
|
||||
Select multiple layers, then choose **Same handles**, **Mirror horizontally**, or **Opposite handles** in the
|
||||
|
|
|
|||
Loading…
Reference in New Issue