Group SVG clipboard and reference imports in a dropdown
This commit is contained in:
parent
1076ef05fd
commit
a54a5bbd25
|
|
@ -175,24 +175,28 @@ impl Editor {
|
|||
Err(error) => self.reference_error = error,
|
||||
}
|
||||
}
|
||||
fn import_reference_file(&mut self, ctx: &egui::Context) {
|
||||
if let Some(path) = rfd::FileDialog::new()
|
||||
.add_filter("Pictures", &["png", "jpg", "jpeg", "bmp"])
|
||||
.pick_file()
|
||||
{
|
||||
self.load_reference(
|
||||
ctx,
|
||||
&egui::DroppedFile {
|
||||
path: Some(path),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
fn reference_window(&mut self, ctx: &egui::Context) {
|
||||
let mut open = self.reference_open;
|
||||
egui::Window::new("Reference image")
|
||||
.open(&mut open)
|
||||
.default_width(420.0)
|
||||
.show(ctx, |ui| {
|
||||
if ui.button("Import picture…").clicked()
|
||||
&& let Some(path) = rfd::FileDialog::new()
|
||||
.add_filter("Pictures", &["png", "jpg", "jpeg", "bmp"])
|
||||
.pick_file()
|
||||
{
|
||||
self.load_reference(
|
||||
ctx,
|
||||
&egui::DroppedFile {
|
||||
path: Some(path),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
if ui.button("Import picture…").clicked() {
|
||||
self.import_reference_file(ctx);
|
||||
}
|
||||
ui.label("Or drag one PNG, JPEG or BMP into the window.");
|
||||
let mut remove = false;
|
||||
|
|
@ -1007,14 +1011,67 @@ impl Editor {
|
|||
}
|
||||
}
|
||||
}
|
||||
ink.button(190.0, 66.0, 154.0, "Paste layer(s) values", true);
|
||||
if click(ui, &ink, [190.0, 66.0, 154.0, 34.0], "toolbar-paste") {
|
||||
self.open_paste(String::new());
|
||||
}
|
||||
ink.button(438.0, 20.0, 154.0, "Reference image…", false);
|
||||
if click(ui, &ink, [438.0, 20.0, 154.0, 34.0], "reference-settings") {
|
||||
self.reference_open = true;
|
||||
}
|
||||
ui.scope_builder(
|
||||
egui::UiBuilder::new()
|
||||
.max_rect(Rect::from_min_size(
|
||||
ink.point(190.0, 66.0),
|
||||
Vec2::new(154.0, 34.0),
|
||||
))
|
||||
.layout(egui::Layout::left_to_right(egui::Align::Center)),
|
||||
|ui| {
|
||||
ui.spacing_mut().interact_size.y = 34.0;
|
||||
ui.spacing_mut().button_padding.x = 16.0;
|
||||
let menu =
|
||||
ui.menu_button("Import", |ui| {
|
||||
ui.set_min_width(225.0);
|
||||
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()
|
||||
{
|
||||
ui.close_menu();
|
||||
self.import_svg_file();
|
||||
}
|
||||
if ui
|
||||
.add_enabled(selected, egui::Button::new("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();
|
||||
ui.ctx().memory_mut(|m| {
|
||||
if let Some(id) = m.focused() { m.surrender_focus(id); }
|
||||
});
|
||||
ui.ctx().send_viewport_cmd(egui::ViewportCommand::RequestPaste);
|
||||
}
|
||||
ui.separator();
|
||||
ui.weak("Screen reference");
|
||||
if ui.button("Reference image…").clicked() {
|
||||
ui.close_menu();
|
||||
self.import_reference_file(ui.ctx());
|
||||
}
|
||||
if self.reference.is_some() && ui.button("Reference settings…").clicked()
|
||||
{
|
||||
ui.close_menu();
|
||||
self.reference_open = true;
|
||||
}
|
||||
});
|
||||
let c = menu.response.rect.right_center() - Vec2::new(8.0, 0.0);
|
||||
ui.painter().add(egui::Shape::convex_polygon(
|
||||
vec![
|
||||
c + Vec2::new(-3.0, -2.0),
|
||||
c + Vec2::new(3.0, -2.0),
|
||||
c + Vec2::new(0.0, 2.0),
|
||||
],
|
||||
MUTED,
|
||||
Stroke::NONE,
|
||||
));
|
||||
},
|
||||
);
|
||||
ui.put(
|
||||
Rect::from_min_size(ink.point(24.0, 108.0), Vec2::new(310.0, 20.0)),
|
||||
egui::Checkbox::new(
|
||||
|
|
@ -1039,17 +1096,13 @@ impl Editor {
|
|||
.as_ref()
|
||||
.map(|r| format!("Reference: {} · {} × {} px", r.name, r.size[0], r.size[1]))
|
||||
.unwrap_or_else(|| {
|
||||
"Drop a reference picture here, or choose Reference image…".into()
|
||||
"Drop a reference picture here, or use Import / Reference image…".into()
|
||||
}),
|
||||
MUTED,
|
||||
)
|
||||
};
|
||||
ink.button(24.0, 142.0, 154.0, "Import SVG…", false);
|
||||
if click(ui, &ink, [24.0, 142.0, 154.0, 34.0], "import-svg") {
|
||||
self.import_svg_file();
|
||||
}
|
||||
ui.put(
|
||||
Rect::from_min_size(ink.point(190.0, 129.0), Vec2::new(r.width() - 215.0, 58.0)),
|
||||
Rect::from_min_size(ink.point(24.0, 135.0), Vec2::new(r.width() - 48.0, 52.0)),
|
||||
egui::Label::new(egui::RichText::new(text).color(color)).wrap(),
|
||||
);
|
||||
let area = Rect::from_min_max(
|
||||
|
|
@ -1819,6 +1872,48 @@ mod tests {
|
|||
assert_eq!(app.content_hit(covered, origin, 1.0), None);
|
||||
}
|
||||
#[test]
|
||||
fn import_menu_requests_clipboard_and_opens_layer_review() {
|
||||
let mut app = Editor::default();
|
||||
let ctx = egui::Context::default();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
let mut requested = false;
|
||||
for label in ["Import", "Clipboard values"] {
|
||||
let output = frame(&mut app, &ctx, vec![]);
|
||||
let pos = output
|
||||
.shapes
|
||||
.iter()
|
||||
.find_map(|s| match &s.shape {
|
||||
egui::epaint::Shape::Text(t) if t.galley.job.text == label => {
|
||||
Some(t.pos + Vec2::new(10.0, 6.0))
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.unwrap();
|
||||
frame(
|
||||
&mut app,
|
||||
&ctx,
|
||||
vec![egui::Event::PointerMoved(pos), mouse(pos, true)],
|
||||
);
|
||||
let output = frame(&mut app, &ctx, vec![mouse(pos, false)]);
|
||||
requested |= output.viewport_output.values().any(|v| {
|
||||
v.commands
|
||||
.iter()
|
||||
.any(|c| matches!(c, egui::ViewportCommand::RequestPaste))
|
||||
});
|
||||
}
|
||||
assert!(requested);
|
||||
frame(
|
||||
&mut app,
|
||||
&ctx,
|
||||
vec![egui::Event::Paste(
|
||||
include_str!("../tests/fixtures/drawio-rectangle.txt").into(),
|
||||
)],
|
||||
);
|
||||
let p = app.paste.as_ref().unwrap();
|
||||
assert!(p.error.is_empty());
|
||||
assert_eq!(p.shapes.len(), 1);
|
||||
}
|
||||
#[test]
|
||||
fn native_copy_paste_round_trip_supports_single_and_multiple_layers() {
|
||||
for selection in [[false, true], [true, true]] {
|
||||
let mut app = Editor::default();
|
||||
|
|
|
|||
|
|
@ -16,8 +16,9 @@ cargo run --locked -p midra-layout
|
|||
(Shift-click to select both).
|
||||
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…** opens an SVG file in the
|
||||
same review window; raw SVG XML can also be pasted.
|
||||
area and click **Read geometry**. **Import → SVG file…** opens an SVG file in the
|
||||
same review window; raw SVG XML can also be pasted. **Import → Clipboard values**
|
||||
reads the clipboard directly and opens the mapping review.
|
||||
3. Review each detected rectangle and choose its destination layer. Initial
|
||||
mapping follows document order and the selected layer list. Every selected
|
||||
destination must receive exactly one rectangle: count mismatches and duplicate
|
||||
|
|
@ -208,8 +209,11 @@ selection state, including when several layers are selected.
|
|||
|
||||
### Reference pictures
|
||||
|
||||
Drop one PNG, JPEG or BMP into the window, or open **Reference image… → Import
|
||||
picture…**. The image is fixed behind the layers in screen coordinates; zooming
|
||||
The **Import** dropdown groups layer-value imports and screen references.
|
||||
Layer imports require selected destinations. After importing a reference picture,
|
||||
**Import → Reference settings…** opens its visibility, opacity and scaling controls.
|
||||
|
||||
Drop one PNG, JPEG or BMP into the window, or choose **Import → Reference image…**. The image is fixed behind the layers in screen coordinates; zooming
|
||||
and panning keep it aligned. Layer fills become translucent to reveal the image.
|
||||
Use the reference window to hide it, adjust opacity, replace it or remove it.
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue