Add a central application menu for commands and options
This commit is contained in:
parent
975f5a382a
commit
0bef5b93a2
|
|
@ -1,6 +1,8 @@
|
|||
use super::*;
|
||||
#[path = "format_ui.rs"]
|
||||
mod format_ui;
|
||||
#[path = "menu_ui.rs"]
|
||||
mod menu_ui;
|
||||
#[path = "project_ui.rs"]
|
||||
mod project_ui;
|
||||
use format_ui::{FormatDraft, OutputDraft, PropertyTab};
|
||||
|
|
@ -1060,6 +1062,16 @@ impl Editor {
|
|||
self.edit_content = !self.edit_content;
|
||||
ui.close_menu();
|
||||
}
|
||||
if ui.button("Reset crop").clicked() {
|
||||
match self
|
||||
.layout
|
||||
.set_framing(i, midra_layout::formats::Framing::default())
|
||||
{
|
||||
Ok(()) => self.sync(),
|
||||
Err(e) => self.error = e,
|
||||
}
|
||||
ui.close_menu();
|
||||
}
|
||||
} else if !selected.is_empty() {
|
||||
ui.weak(format!("{} layers selected", selected.len()));
|
||||
ui.menu_button("Resize together", |ui| {
|
||||
|
|
@ -1321,19 +1333,8 @@ impl Editor {
|
|||
let rect = Rect::from_min_size(ink.point(x, 22.0), Vec2::splat(32.0));
|
||||
if toolbar_icon(ui, rect, text, icon).clicked() {
|
||||
match text {
|
||||
"Fit screen" => {
|
||||
self.zoom = 1.0;
|
||||
self.pan = Vec2::ZERO;
|
||||
}
|
||||
"Fit selected" => {
|
||||
if let Some(g) = self.layout.selection_bounds() {
|
||||
self.zoom =
|
||||
(sw as f64 / g.width).min(sh as f64 / g.height) as f32 * 0.8;
|
||||
self.zoom = self.zoom.clamp(0.0001, 256.0);
|
||||
let c = g.center();
|
||||
self.pan = Vec2::new(sw / 2.0 - c[0] as f32, sh / 2.0 - c[1] as f32);
|
||||
}
|
||||
}
|
||||
"Fit screen" => self.fit_screen(),
|
||||
"Fit selected" => self.fit_selection(),
|
||||
"Undo" => {
|
||||
self.layout.undo();
|
||||
self.sync();
|
||||
|
|
@ -1393,45 +1394,7 @@ impl Editor {
|
|||
|ui| {
|
||||
ui.spacing_mut().interact_size = Vec2::new(36.0, 34.0);
|
||||
ui.spacing_mut().button_padding.x = 11.0;
|
||||
let menu =
|
||||
ui.menu_button(" ", |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 menu = ui.menu_button(" ", |ui| self.import_menu(ui));
|
||||
let response = menu
|
||||
.response
|
||||
.on_hover_text("Import layer values or reference image");
|
||||
|
|
@ -1483,16 +1446,7 @@ impl Editor {
|
|||
|ui| {
|
||||
ui.spacing_mut().interact_size = Vec2::new(36.0, 34.0);
|
||||
ui.spacing_mut().button_padding.x = 11.0;
|
||||
let menu = ui.menu_button(" ", |ui| {
|
||||
ui.checkbox(
|
||||
&mut self.keep_aspect_ratio,
|
||||
"Keep aspect ratio when resizing",
|
||||
);
|
||||
ui.checkbox(
|
||||
&mut self.show_pattern,
|
||||
"Show source-coordinate test pattern in viewport",
|
||||
);
|
||||
});
|
||||
let menu = ui.menu_button(" ", |ui| self.viewport_options_menu(ui));
|
||||
let response = menu.response.on_hover_text("Viewport options");
|
||||
response.widget_info(|| {
|
||||
egui::WidgetInfo::labeled(egui::WidgetType::Button, true, "Viewport options")
|
||||
|
|
@ -2022,6 +1976,18 @@ impl Editor {
|
|||
ink.text(24.0, 11.0, "MIDRA / LAYOUT", 18.0, TEXT);
|
||||
ink.line([206.0, 13.0], [206.0, 31.0], LINE);
|
||||
ink.text(222.0, 15.0, "Offline position helper", 13.0, MUTED);
|
||||
ui.scope_builder(
|
||||
egui::UiBuilder::new()
|
||||
.max_rect(Rect::from_min_size(
|
||||
ink.point(420.0, 7.0),
|
||||
Vec2::new(80.0, 30.0),
|
||||
))
|
||||
.layout(egui::Layout::left_to_right(egui::Align::Center)),
|
||||
|ui| {
|
||||
ui.spacing_mut().interact_size.y = 30.0;
|
||||
ui.menu_button("Menu", |ui| self.application_menu(ui));
|
||||
},
|
||||
);
|
||||
ink.text(r.width() - 347.0, 15.0, "EIKOS 4K", 12.0, CYAN);
|
||||
ink.button(r.width() - 212.0, 5.0, 188.0, "Copy coordinates", false);
|
||||
if click(
|
||||
|
|
|
|||
|
|
@ -0,0 +1,226 @@
|
|||
use super::*;
|
||||
|
||||
impl Editor {
|
||||
pub(super) fn import_menu(&mut self, ui: &mut egui::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;
|
||||
}
|
||||
}
|
||||
pub(super) fn viewport_options_menu(&mut self, ui: &mut egui::Ui) {
|
||||
ui.checkbox(
|
||||
&mut self.keep_aspect_ratio,
|
||||
"Keep aspect ratio when resizing",
|
||||
);
|
||||
ui.checkbox(
|
||||
&mut self.show_pattern,
|
||||
"Show source-coordinate test pattern in viewport",
|
||||
);
|
||||
}
|
||||
pub(super) fn fit_screen(&mut self) {
|
||||
self.zoom = 1.0;
|
||||
self.pan = Vec2::ZERO;
|
||||
}
|
||||
pub(super) fn fit_selection(&mut self) {
|
||||
if let Some(g) = self.layout.selection_bounds() {
|
||||
let [sw, sh] = self.layout.formats().output.map(|v| v as f32);
|
||||
self.zoom =
|
||||
((sw as f64 / g.width).min(sh as f64 / g.height) as f32 * 0.8).clamp(0.0001, 256.0);
|
||||
let c = g.center();
|
||||
self.pan = Vec2::new(sw / 2.0 - c[0] as f32, sh / 2.0 - c[1] as f32);
|
||||
}
|
||||
}
|
||||
pub(super) fn application_menu(&mut self, ui: &mut egui::Ui) {
|
||||
ui.set_min_width(185.0);
|
||||
ui.menu_button("Project", |ui| self.project_menu(ui));
|
||||
ui.menu_button("Import", |ui| self.import_menu(ui));
|
||||
ui.menu_button("Edit", |ui| {
|
||||
if ui.button("Undo").clicked() {
|
||||
self.layout.undo();
|
||||
self.sync();
|
||||
ui.close_menu();
|
||||
}
|
||||
if ui.button("Redo").clicked() {
|
||||
self.layout.redo();
|
||||
self.sync();
|
||||
ui.close_menu();
|
||||
}
|
||||
ui.separator();
|
||||
if ui
|
||||
.add_enabled(
|
||||
!self.layout.selected_indices().is_empty(),
|
||||
egui::Button::new("Copy layer values"),
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
self.copy(ui.ctx());
|
||||
ui.close_menu();
|
||||
}
|
||||
if ui.button("Select all editable layers").clicked() {
|
||||
self.layout.set_selection(std::array::from_fn(|i| {
|
||||
self.layout.visible(i) && !self.layout.locked(i)
|
||||
}));
|
||||
self.sync();
|
||||
ui.close_menu();
|
||||
}
|
||||
if ui.button("Deselect all").clicked() {
|
||||
self.layout.select(None);
|
||||
self.edit_content = false;
|
||||
self.sync();
|
||||
ui.close_menu();
|
||||
}
|
||||
});
|
||||
ui.menu_button("View", |ui| {
|
||||
if ui.button("Fit screen").clicked() {
|
||||
self.fit_screen();
|
||||
ui.close_menu();
|
||||
}
|
||||
if ui
|
||||
.add_enabled(
|
||||
self.layout.selection_bounds().is_some(),
|
||||
egui::Button::new("Fit selected"),
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
self.fit_selection();
|
||||
ui.close_menu();
|
||||
}
|
||||
if ui.button("1:1 display pixels").clicked() {
|
||||
self.camera_one_to_one = true;
|
||||
ui.close_menu();
|
||||
}
|
||||
ui.separator();
|
||||
if ui.button("Output format…").clicked() {
|
||||
self.output_draft = Some(OutputDraft::new(self.layout.formats().output));
|
||||
ui.close_menu();
|
||||
}
|
||||
if ui.button("Reference image settings…").clicked() {
|
||||
self.reference_open = true;
|
||||
ui.close_menu();
|
||||
}
|
||||
});
|
||||
ui.menu_button("Layers", |ui| {
|
||||
ui.menu_button("Selected layer actions", |ui| {
|
||||
if self.layout.selected_indices().is_empty() {
|
||||
ui.weak("Select a layer to edit its properties.");
|
||||
}
|
||||
self.layer_context_menu(ui);
|
||||
});
|
||||
ui.separator();
|
||||
for i in 0..self.layout.layers().len() {
|
||||
ui.menu_button(label(i), |ui| {
|
||||
if ui
|
||||
.add_enabled(
|
||||
self.layout.visible(i) && !self.layout.locked(i),
|
||||
egui::Button::new("Select layer"),
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
self.layout.select(Some(i));
|
||||
self.edit_content = false;
|
||||
self.sync();
|
||||
ui.close_menu();
|
||||
}
|
||||
let mut visible = self.layout.visible(i);
|
||||
if ui.checkbox(&mut visible, "Visible").changed() {
|
||||
self.layout.set_visible(i, visible);
|
||||
self.sync();
|
||||
}
|
||||
let mut locked = self.layout.locked(i);
|
||||
if ui.checkbox(&mut locked, "Locked").changed() {
|
||||
self.layout.set_locked(i, locked);
|
||||
self.sync();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
ui.menu_button("Options", |ui| self.viewport_options_menu(ui));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::super::tests::{frame, mouse};
|
||||
use super::*;
|
||||
fn click_label(app: &mut Editor, ctx: &egui::Context, label: &str) {
|
||||
frame(app, ctx, vec![]);
|
||||
let output = frame(app, ctx, vec![]);
|
||||
let pos = output
|
||||
.shapes
|
||||
.iter()
|
||||
.find_map(|s| match &s.shape {
|
||||
egui::Shape::Text(t) if t.galley.text() == label => {
|
||||
Some(t.pos + t.galley.size() / 2.0)
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.unwrap_or_else(|| panic!("menu item not found: {label}"));
|
||||
frame(
|
||||
app,
|
||||
ctx,
|
||||
vec![egui::Event::PointerMoved(pos), mouse(pos, true)],
|
||||
);
|
||||
frame(app, ctx, vec![mouse(pos, false)]);
|
||||
}
|
||||
#[test]
|
||||
fn main_menu_routes_view_options_and_selection_commands() {
|
||||
for (section, action) in [
|
||||
("View", "Fit screen"),
|
||||
("Options", "Show source-coordinate test pattern in viewport"),
|
||||
("Edit", "Select all editable layers"),
|
||||
] {
|
||||
let mut app = Editor {
|
||||
zoom: 2.0,
|
||||
pan: Vec2::new(20.0, 30.0),
|
||||
..Default::default()
|
||||
};
|
||||
app.layout.set_locked(1, true);
|
||||
let boxes = *app.layout.layers();
|
||||
let ctx = egui::Context::default();
|
||||
click_label(&mut app, &ctx, "Menu");
|
||||
click_label(&mut app, &ctx, section);
|
||||
click_label(&mut app, &ctx, action);
|
||||
match section {
|
||||
"View" => {
|
||||
assert_eq!(app.zoom, 1.0);
|
||||
assert_eq!(app.pan, Vec2::ZERO);
|
||||
}
|
||||
"Options" => assert!(app.show_pattern),
|
||||
_ => assert_eq!(app.layout.selection_mask(), [true, false]),
|
||||
}
|
||||
assert_eq!(*app.layout.layers(), boxes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -411,3 +411,18 @@ and keeps its proportions, independently of these layer/view preferences.
|
|||
|
||||
The toolbar’s **Import** button uses a downward arrow into a tray. Hover for its
|
||||
label; its dropdown contains SVG, clipboard values, and reference-image actions.
|
||||
|
||||
## Application menu
|
||||
|
||||
The header’s **Menu** brings the application’s commands together:
|
||||
|
||||
- **Project**: open/save JSON and export SVG.
|
||||
- **Import**: SVG, clipboard layer values, and reference images.
|
||||
- **Edit**: undo/redo, copy values, select all editable layers, or deselect.
|
||||
- **View**: fit screen/selection, 1:1 pixels, output format, and reference settings.
|
||||
- **Layers**: selected-layer properties, crop/reset, alignment, shared resizing,
|
||||
lock/hide, and per-layer selection/visibility/lock controls.
|
||||
- **Options**: resize aspect ratio and the source-coordinate preview.
|
||||
|
||||
The toolbar, cog and right-click shortcuts use the same commands and preferences.
|
||||
Detailed numeric controls remain in their existing properties dialogs.
|
||||
|
|
|
|||
Loading…
Reference in New Issue