Add layer pickers to import and export menus
This commit is contained in:
parent
c6c943e5b5
commit
655cc03357
|
|
@ -80,6 +80,9 @@ impl Editor {
|
|||
ui.selectable_value(&mut self.device.prepare_send, false, "Import from Midra");
|
||||
ui.selectable_value(&mut self.device.prepare_send, true, "Prepare selected layers for Preview");
|
||||
});
|
||||
if self.device.prepare_send {
|
||||
self.transfer_layer_picker(ui, "Choose editor layers to send…");
|
||||
}
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Device IP");
|
||||
if ui.add_enabled(self.device.pending.is_none(), egui::TextEdit::singleline(&mut self.device.host).hint_text("192.168.…")).changed() {
|
||||
|
|
|
|||
|
|
@ -437,10 +437,6 @@ impl Editor {
|
|||
}
|
||||
fn open_paste(&mut self, text: String) {
|
||||
let targets = self.layout.selected_indices();
|
||||
if targets.is_empty() {
|
||||
self.error = "Select one or more destination layers before importing values.".into();
|
||||
return;
|
||||
}
|
||||
let mut p = Paste {
|
||||
target_ids: targets
|
||||
.iter()
|
||||
|
|
@ -465,10 +461,6 @@ impl Editor {
|
|||
self.paste = Some(p);
|
||||
}
|
||||
fn import_svg_file(&mut self) {
|
||||
if self.layout.selected_indices().is_empty() {
|
||||
self.error = "Select one or more destination layers before importing SVG.".into();
|
||||
return;
|
||||
}
|
||||
if let Some(path) = rfd::FileDialog::new()
|
||||
.add_filter("SVG", &["svg"])
|
||||
.pick_file()
|
||||
|
|
@ -712,6 +704,11 @@ impl Editor {
|
|||
let response=egui::Modal::new(egui::Id::new("layer-values-import")).show(ctx,|ui| {
|
||||
ui.set_width(600.0);
|
||||
ui.heading("Paste layer(s) values");
|
||||
if self.transfer_layer_picker(ui, "Choose destination layers…") {
|
||||
p.targets = self.layout.selected_indices();
|
||||
p.target_ids = p.targets.iter().map(|&i| self.layout.layer_info(i).id).collect();
|
||||
p.reset_mapping();
|
||||
}
|
||||
ui.label(format!("Selected destinations: {}",p.targets.iter().map(|i|self.layout.layer_label(*i)).collect::<Vec<_>>().join(", ")));
|
||||
ui.label("Paste Midra Layout values, draw.io clipboard data or SVG XML, or import SVG.");
|
||||
egui::ScrollArea::vertical().max_height((ctx.screen_rect().height()-360.0).max(150.0)).show(ui,|ui| {
|
||||
|
|
@ -3467,6 +3464,54 @@ mod tests {
|
|||
assert_eq!(app.reference.as_ref().unwrap().texture.id(), texture);
|
||||
}
|
||||
#[test]
|
||||
fn import_can_choose_destination_inside_review_without_initial_selection() {
|
||||
let mut app = Editor::default();
|
||||
let ctx = egui::Context::default();
|
||||
app.layout.select(None);
|
||||
let before = app.layout.layers().clone();
|
||||
app.open_paste(include_str!("../tests/fixtures/drawio-rectangle.txt").into());
|
||||
assert!(app.paste.as_ref().unwrap().targets.is_empty());
|
||||
fn text_position(output: &egui::FullOutput, label: &str) -> Pos2 {
|
||||
output
|
||||
.shapes
|
||||
.iter()
|
||||
.rev()
|
||||
.find_map(|s| match &s.shape {
|
||||
egui::epaint::Shape::Text(t) if t.galley.job.text == label => {
|
||||
Some(t.pos + Vec2::new(12.0, 6.0))
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.unwrap_or_else(|| panic!("Missing label {label}"))
|
||||
}
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
let output = frame(&mut app, &ctx, vec![]);
|
||||
let pos = text_position(&output, "Choose destination layers…");
|
||||
frame(
|
||||
&mut app,
|
||||
&ctx,
|
||||
vec![egui::Event::PointerMoved(pos), mouse(pos, true)],
|
||||
);
|
||||
frame(&mut app, &ctx, vec![mouse(pos, false)]);
|
||||
let output = frame(&mut app, &ctx, vec![]);
|
||||
let pos = text_position(&output, &app.layout.layer_label(0));
|
||||
frame(
|
||||
&mut app,
|
||||
&ctx,
|
||||
vec![egui::Event::PointerMoved(pos), mouse(pos, true)],
|
||||
);
|
||||
frame(&mut app, &ctx, vec![mouse(pos, false)]);
|
||||
let paste = app.paste.as_ref().unwrap();
|
||||
assert_eq!(paste.targets, vec![0]);
|
||||
assert_eq!(paste.mapping, vec![Some(0)]);
|
||||
assert_eq!(*app.layout.layers(), before);
|
||||
paste.apply(&mut app.layout).unwrap();
|
||||
assert_eq!(app.layout.layers()[0].width, 945.0);
|
||||
assert_eq!(app.layout.layers()[1], before[1]);
|
||||
app.layout.undo();
|
||||
assert_eq!(*app.layout.layers(), before);
|
||||
}
|
||||
#[test]
|
||||
fn paste_opens_review_without_editing_and_escape_cancels() {
|
||||
let mut app = Editor::default();
|
||||
let ctx = egui::Context::default();
|
||||
|
|
@ -3569,8 +3614,8 @@ mod tests {
|
|||
let before = app.layout.layers().clone();
|
||||
app.layout.select(None);
|
||||
app.open_paste("invalid".into());
|
||||
assert!(app.paste.is_none());
|
||||
assert!(!app.error.is_empty());
|
||||
assert!(app.paste.as_ref().unwrap().targets.is_empty());
|
||||
assert!(!app.paste.as_ref().unwrap().error.is_empty());
|
||||
app.layout.select(Some(0));
|
||||
app.open_paste("invalid".into());
|
||||
assert!(app.paste.as_ref().unwrap().shapes.is_empty());
|
||||
|
|
|
|||
|
|
@ -1,6 +1,45 @@
|
|||
use super::*;
|
||||
|
||||
impl Editor {
|
||||
/// Layer selection is available beside import/export actions as well as on canvas.
|
||||
pub(super) fn transfer_layer_picker(&mut self, ui: &mut egui::Ui, label: &str) -> bool {
|
||||
let mut changed = false;
|
||||
ui.menu_button(label, |ui| {
|
||||
egui::ScrollArea::vertical()
|
||||
.max_height(240.0)
|
||||
.show(ui, |ui| {
|
||||
for i in 0..self.layout.layers().len() {
|
||||
let mut selected = self.layout.selected_indices().contains(&i);
|
||||
let available = self.layout.visible(i) && !self.layout.locked(i);
|
||||
let suffix = if self.layout.locked(i) {
|
||||
" (locked)"
|
||||
} else if !self.layout.visible(i) {
|
||||
" (hidden)"
|
||||
} else {
|
||||
""
|
||||
};
|
||||
if ui
|
||||
.add_enabled(
|
||||
available,
|
||||
egui::Checkbox::new(
|
||||
&mut selected,
|
||||
format!("{}{suffix}", self.layout.layer_label(i)),
|
||||
),
|
||||
)
|
||||
.changed()
|
||||
{
|
||||
self.layout.toggle(i);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
if changed {
|
||||
self.sync();
|
||||
}
|
||||
changed
|
||||
}
|
||||
|
||||
pub(super) fn import_menu(&mut self, ui: &mut egui::Ui) {
|
||||
ui.set_min_width(225.0);
|
||||
if ui.button("Midra Preview…").clicked() {
|
||||
|
|
@ -10,19 +49,14 @@ impl Editor {
|
|||
}
|
||||
ui.separator();
|
||||
ui.weak("Layer values");
|
||||
let selected = !self.layout.selected_indices().is_empty();
|
||||
if ui
|
||||
.add_enabled(selected, egui::Button::new("SVG file…"))
|
||||
.on_disabled_hover_text("Select destination layers first.")
|
||||
.clicked()
|
||||
{
|
||||
self.transfer_layer_picker(ui, "Choose destination layers…");
|
||||
if ui.button("SVG file…").clicked() {
|
||||
ui.close_menu();
|
||||
self.import_svg_file();
|
||||
}
|
||||
if ui
|
||||
.add_enabled(selected, egui::Button::new("Clipboard values"))
|
||||
.button("Clipboard values")
|
||||
.on_hover_text("Read the clipboard and review layer mapping. Ctrl/Cmd-V also works.")
|
||||
.on_disabled_hover_text("Select destination layers first.")
|
||||
.clicked()
|
||||
{
|
||||
ui.close_menu();
|
||||
|
|
|
|||
|
|
@ -116,16 +116,17 @@ impl Editor {
|
|||
}
|
||||
ui.small("Saves applied values and the reference image.");
|
||||
ui.separator();
|
||||
if ui.add_enabled(self.device.online() && !self.layout.selected_indices().is_empty(),
|
||||
if ui.add_enabled(self.device.online(),
|
||||
egui::Button::new("Prepare selected layers for Midra…"))
|
||||
.on_hover_text("Review Preview destinations and requested values. Device sending is not yet available.")
|
||||
.on_disabled_hover_text("Read the Midra connection and select editor layers first.")
|
||||
.on_disabled_hover_text("Read the Midra connection first; layers can be chosen in the review.")
|
||||
.clicked() {
|
||||
self.device.prepare_send = true;
|
||||
self.device.open = true;
|
||||
ui.close_menu();
|
||||
}
|
||||
ui.menu_button("Export SVG", |ui| {
|
||||
self.transfer_layer_picker(ui, "Choose layers to export…");
|
||||
ui.menu_button("Specific layer…", |ui| {
|
||||
egui::ScrollArea::vertical()
|
||||
.max_height(320.0)
|
||||
|
|
|
|||
|
|
@ -12,8 +12,9 @@ cargo run --locked -p midra-layout
|
|||
|
||||
## Paste layer values and import SVG
|
||||
|
||||
1. Select the destination layers on the canvas or in the right-hand list
|
||||
(Shift-click to select both).
|
||||
1. Choose destinations using **Choose destination layers…** in the Import menu
|
||||
or review window. Selecting them on the canvas or right-hand list also works
|
||||
(Shift-click for multiple layers).
|
||||
2. Copy layer values in Midra Layout or rectangles in draw.io, then press **Ctrl/Cmd-V** with the viewport
|
||||
focused. Alternatively, click **Paste layer(s) values**, paste into the text
|
||||
area and click **Read geometry**. **Import → SVG file…** opens an SVG file in the
|
||||
|
|
@ -576,3 +577,26 @@ On the development Linux host (2026-11-13), 256 visible layers at 1440×940
|
|||
measured p50 **0.73 ms**, p95 **0.78 ms** across 100 frames after 20 warm-up frames.
|
||||
This measures egui CPU frame construction, not GPU presentation, image decoding,
|
||||
OS/DPI behavior or performance on an operator laptop. It is not a release gate.
|
||||
|
||||
## Choose layers inside import and export menus
|
||||
|
||||
You can choose layers without returning to the viewport:
|
||||
|
||||
- **Import → Choose destination layers…**, and the same picker inside the
|
||||
clipboard/SVG review, select the destinations. Paste and SVG import can open
|
||||
with nothing selected. Then map each detected rectangle using its destination
|
||||
dropdown. The number of chosen destinations must match the imported rectangles
|
||||
after ignoring an SVG background; duplicate mappings remain invalid.
|
||||
- **Project → Export SVG → Choose layers to export…** selects the group for
|
||||
**Selected layers…**. **Specific layer…** remains available for individual layers,
|
||||
including hidden layers.
|
||||
- Midra send preparation has **Choose editor layers to send…**, followed by a
|
||||
device-destination dropdown for each chosen layer. It can open online with
|
||||
nothing selected. Actual device sending remains unavailable.
|
||||
- Midra import retains its independent per-device-layer destinations, including
|
||||
**New layer** and **Do not import**.
|
||||
|
||||
The shared pickers update the viewport selection. Hidden/locked layers are labeled
|
||||
and disabled in these pickers; choosing layers changes no geometry. Full project
|
||||
save/load and screen reference images are document-wide operations, so they have
|
||||
no layer mapping.
|
||||
|
|
|
|||
Loading…
Reference in New Issue