Add full preferences window and configurable movement snapping
This commit is contained in:
parent
56d49c06ca
commit
1d4616abe9
|
|
@ -3,6 +3,8 @@ use super::*;
|
|||
mod format_ui;
|
||||
#[path = "menu_ui.rs"]
|
||||
mod menu_ui;
|
||||
#[path = "preferences_ui.rs"]
|
||||
mod preferences_ui;
|
||||
#[path = "project_ui.rs"]
|
||||
mod project_ui;
|
||||
use format_ui::{FormatDraft, OutputDraft, PropertyTab};
|
||||
|
|
@ -12,6 +14,10 @@ use midra_layout::{AlignTarget, Alignment, Corner, Geometry, Layout, ResizeHandl
|
|||
pub struct Editor {
|
||||
settings: settings::Store,
|
||||
themes_open: bool,
|
||||
preferences_open: bool,
|
||||
snapping: midra_layout::snapping::Snapping,
|
||||
snap_guides: [Option<f64>; 2],
|
||||
preferences_section: preferences_ui::Section,
|
||||
layout: Layout,
|
||||
files: project_ui::FileUi,
|
||||
corner: Corner,
|
||||
|
|
@ -170,6 +176,10 @@ impl Default for Editor {
|
|||
let mut this = Self {
|
||||
settings: settings::Store::default(),
|
||||
themes_open: false,
|
||||
preferences_open: false,
|
||||
snapping: Default::default(),
|
||||
snap_guides: [None; 2],
|
||||
preferences_section: preferences_ui::Section::default(),
|
||||
layout: Layout::default(),
|
||||
files: project_ui::FileUi::default(),
|
||||
corner: Corner::TopRight,
|
||||
|
|
@ -231,6 +241,7 @@ impl Editor {
|
|||
saved.theme.apply(ctx);
|
||||
Self {
|
||||
settings: store,
|
||||
snapping: saved.snapping,
|
||||
keep_aspect_ratio: saved.keep_aspect_ratio,
|
||||
show_pattern: saved.show_source_pattern,
|
||||
show_toolbar_icon_names: saved.show_toolbar_icon_names,
|
||||
|
|
@ -241,6 +252,7 @@ impl Editor {
|
|||
settings::Settings {
|
||||
theme: theme::Theme::current(ctx),
|
||||
recent_themes: theme::Theme::recent(ctx),
|
||||
snapping: self.snapping,
|
||||
keep_aspect_ratio: self.keep_aspect_ratio,
|
||||
show_source_pattern: self.show_pattern,
|
||||
show_toolbar_icon_names: self.show_toolbar_icon_names,
|
||||
|
|
@ -498,6 +510,10 @@ impl Editor {
|
|||
}
|
||||
}
|
||||
fn shortcuts(&mut self, ctx: &egui::Context) {
|
||||
if ctx.input_mut(|i| i.consume_key(egui::Modifiers::COMMAND, egui::Key::Comma)) {
|
||||
self.preferences_open = true;
|
||||
return;
|
||||
}
|
||||
if self.paste.is_some() {
|
||||
return;
|
||||
}
|
||||
|
|
@ -1781,6 +1797,7 @@ impl Editor {
|
|||
self.sync();
|
||||
}
|
||||
}
|
||||
self.snap_guides = [None; 2];
|
||||
if response.dragged() {
|
||||
if self.panning {
|
||||
self.pan += response.drag_delta() / scale;
|
||||
|
|
@ -1792,7 +1809,13 @@ impl Editor {
|
|||
m.end = point;
|
||||
self.layout.select_region(m.start, point, m.base);
|
||||
} else {
|
||||
self.layout.drag_to(point);
|
||||
let mut snapping = self.snapping;
|
||||
if ui.input(|i| i.modifiers.alt) {
|
||||
snapping.enabled = false;
|
||||
}
|
||||
self.snap_guides =
|
||||
self.layout
|
||||
.drag_to_snapped(point, snapping, 6.0 / scale as f64);
|
||||
}
|
||||
self.sync();
|
||||
}
|
||||
|
|
@ -2029,6 +2052,25 @@ impl Editor {
|
|||
);
|
||||
}
|
||||
}
|
||||
for (axis, guide) in self.snap_guides.iter().enumerate() {
|
||||
if let Some(value) = guide {
|
||||
let position = if axis == 0 { origin.x } else { origin.y } + *value as f32 * scale;
|
||||
let points = if axis == 0 {
|
||||
[
|
||||
Pos2::new(position, area.top()),
|
||||
Pos2::new(position, area.bottom()),
|
||||
]
|
||||
} else {
|
||||
[
|
||||
Pos2::new(area.left(), position),
|
||||
Pos2::new(area.right(), position),
|
||||
]
|
||||
};
|
||||
screen
|
||||
.painter
|
||||
.line_segment(points, Stroke::new(1.5_f32, palette.cyan));
|
||||
}
|
||||
}
|
||||
if let Some(m) = self.marquee {
|
||||
let from = origin + Vec2::new(m.start[0] as f32, m.start[1] as f32) * scale;
|
||||
let to = origin + Vec2::new(m.end[0] as f32, m.end[1] as f32) * scale;
|
||||
|
|
@ -2250,6 +2292,7 @@ impl Editor {
|
|||
self.output_window(ctx);
|
||||
self.formats_window(ctx);
|
||||
self.project_windows(ctx);
|
||||
self.preferences_window(ctx);
|
||||
self.theme_window(ctx);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ use std::collections::HashMap;
|
|||
pub mod formats;
|
||||
pub mod import;
|
||||
pub mod project;
|
||||
pub mod snapping;
|
||||
use formats::{Formats, Framing, Source};
|
||||
|
||||
/// Presentation only: retain full precision in the document.
|
||||
|
|
|
|||
|
|
@ -40,6 +40,11 @@ impl Editor {
|
|||
}
|
||||
}
|
||||
pub(super) fn viewport_options_menu(&mut self, ui: &mut egui::Ui) {
|
||||
if ui.button("Preferences…").clicked() {
|
||||
self.preferences_open = true;
|
||||
ui.close_menu();
|
||||
}
|
||||
ui.separator();
|
||||
let before = self.application_settings(ui.ctx());
|
||||
let current = theme::Theme::current(ui.ctx());
|
||||
ui.menu_button(format!("Theme: {}", current.name()), |ui| {
|
||||
|
|
@ -143,6 +148,11 @@ impl Editor {
|
|||
}
|
||||
pub(super) fn application_menu(&mut self, ui: &mut egui::Ui) {
|
||||
ui.set_min_width(185.0);
|
||||
if ui.button("Preferences…").clicked() {
|
||||
self.preferences_open = true;
|
||||
ui.close_menu();
|
||||
}
|
||||
ui.separator();
|
||||
ui.menu_button("Project", |ui| self.project_menu(ui));
|
||||
ui.menu_button("Import", |ui| self.import_menu(ui));
|
||||
ui.menu_button("Edit", |ui| {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,200 @@
|
|||
use super::*;
|
||||
|
||||
#[derive(Clone, Copy, Default, PartialEq)]
|
||||
pub(super) enum Section {
|
||||
#[default]
|
||||
Appearance,
|
||||
Editing,
|
||||
Reference,
|
||||
Storage,
|
||||
Device,
|
||||
}
|
||||
impl Section {
|
||||
const ALL: [(Self, &'static str); 5] = [
|
||||
(Self::Appearance, "Appearance"),
|
||||
(Self::Editing, "Editing"),
|
||||
(Self::Reference, "Reference images"),
|
||||
(Self::Storage, "Files & settings"),
|
||||
(Self::Device, "Midra integration"),
|
||||
];
|
||||
}
|
||||
impl Editor {
|
||||
pub(super) fn preferences_window(&mut self, ctx: &egui::Context) {
|
||||
if !self.preferences_open {
|
||||
return;
|
||||
}
|
||||
let before = self.application_settings(ctx);
|
||||
let mut open = self.preferences_open;
|
||||
egui::Window::new("Preferences")
|
||||
.open(&mut open)
|
||||
.default_width(660.0)
|
||||
.min_width(540.0)
|
||||
.collapsible(false)
|
||||
.show(ctx, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.vertical(|ui| {
|
||||
ui.set_width(145.0);
|
||||
for (section, name) in Section::ALL {
|
||||
ui.selectable_value(&mut self.preferences_section, section, name);
|
||||
}
|
||||
});
|
||||
ui.separator();
|
||||
ui.vertical(|ui| {
|
||||
ui.set_min_height(265.0);
|
||||
match self.preferences_section {
|
||||
Section::Appearance => {
|
||||
ui.heading("Appearance");
|
||||
ui.label(format!("Current theme: {}", theme::Theme::current(ctx).name()));
|
||||
if ui.button("Browse all themes…").clicked() { self.themes_open = true; }
|
||||
ui.label("Recently used");
|
||||
for choice in theme::Theme::recent(ctx) {
|
||||
if ui.selectable_label(choice == theme::Theme::current(ctx), choice.name()).clicked() {
|
||||
choice.apply(ctx);
|
||||
}
|
||||
}
|
||||
ui.separator();
|
||||
ui.checkbox(&mut self.show_toolbar_icon_names, "Show toolbar icon names");
|
||||
ui.checkbox(&mut self.show_pattern, "Show source-coordinate test pattern in viewport");
|
||||
ui.weak("Themes also apply to the viewport. Imported pictures retain their colors.");
|
||||
}
|
||||
Section::Editing => {
|
||||
ui.heading("Editing");
|
||||
ui.checkbox(&mut self.keep_aspect_ratio, "Keep aspect ratio when resizing");
|
||||
ui.label("Applies to layer handles and numeric width/height edits. Crop zoom always keeps the source proportions.");
|
||||
ui.separator();
|
||||
ui.checkbox(&mut self.snapping.enabled, "Snap while moving layers");
|
||||
ui.add_enabled_ui(self.snapping.enabled, |ui| {
|
||||
ui.checkbox(&mut self.snapping.pixels, "Pixel edges");
|
||||
ui.checkbox(&mut self.snapping.screen_edges, "Screen edges");
|
||||
ui.checkbox(&mut self.snapping.layer_edges, "Other visible layer edges");
|
||||
});
|
||||
ui.weak("Hold Alt to bypass snapping. Numeric entry remains exact. Resize and crop handles do not proximity-snap.");
|
||||
ui.separator();
|
||||
ui.label("Arrow keys: move 1 pixel · Shift-arrow: move 10 pixels");
|
||||
ui.label("Shift-click: add/remove a layer from selection");
|
||||
ui.label("Space-drag or middle button: pan · Scroll: zoom");
|
||||
ui.label("Double-click a layer: adjust crop · Escape: cancel gesture");
|
||||
}
|
||||
Section::Reference => {
|
||||
ui.heading("Reference images");
|
||||
ui.label("Image placement, visibility and opacity belong to the current project.");
|
||||
if ui.button("Reference image settings…").clicked() { self.reference_open = true; }
|
||||
if ui.button("Import reference picture…").clicked() { self.import_reference_file(ctx); }
|
||||
ui.weak("PNG, JPEG and BMP. Drop a picture into the viewport to import it.");
|
||||
}
|
||||
Section::Storage => {
|
||||
ui.heading("Files & settings");
|
||||
ui.label("Application preferences save automatically when changed.");
|
||||
if let Some(path) = &self.settings.path {
|
||||
ui.label(path.display().to_string());
|
||||
if ui.button("Copy settings path").clicked() { ctx.copy_text(path.display().to_string()); }
|
||||
} else { ui.label("No configuration location is available."); }
|
||||
ui.separator();
|
||||
ui.label("Project JSON stores layout, sources, crops and the reference picture. SVG exports layer geometry.");
|
||||
ui.weak("Opening a project may restore its viewport options without rewriting your startup defaults.");
|
||||
if ui.button("Restore default preferences").clicked() {
|
||||
let defaults = settings::Settings::default();
|
||||
theme::Theme::restore_recent(ctx, defaults.recent_themes);
|
||||
defaults.theme.apply(ctx);
|
||||
self.snapping = defaults.snapping;
|
||||
self.keep_aspect_ratio = defaults.keep_aspect_ratio;
|
||||
self.show_pattern = defaults.show_source_pattern;
|
||||
self.show_toolbar_icon_names = defaults.show_toolbar_icon_names;
|
||||
}
|
||||
}
|
||||
Section::Device => {
|
||||
ui.heading("Midra integration");
|
||||
ui.label("Offline layout planning for Eikos 4K.");
|
||||
ui.label("Device mapping and export strategies are not implemented yet. No network connection or device commands are made.");
|
||||
ui.weak("Hardware compatibility needs validation against the exact firmware in an isolated test setup.");
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
ui.separator();
|
||||
ui.label("Changes take effect immediately and save automatically.");
|
||||
if let Some(error) = &self.settings.error { ui.colored_label(ui.visuals().error_fg_color, error); }
|
||||
if self.settings.can_retry() && ui.button("Retry saving preferences").clicked() {
|
||||
self.settings.save(&self.application_settings(ctx));
|
||||
}
|
||||
if ui.button("Close").clicked() { self.preferences_open = false; }
|
||||
});
|
||||
self.preferences_open &= open;
|
||||
let after = self.application_settings(ctx);
|
||||
if before != after {
|
||||
self.settings.save(&after);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::gui::tests::{frame, mouse};
|
||||
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()
|
||||
.rev()
|
||||
.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!("missing preference: {label}"));
|
||||
frame(
|
||||
app,
|
||||
ctx,
|
||||
vec![egui::Event::PointerMoved(pos), mouse(pos, true)],
|
||||
);
|
||||
frame(app, ctx, vec![mouse(pos, false)]);
|
||||
}
|
||||
#[test]
|
||||
fn preferences_edit_and_persist_without_touching_document_or_drafts() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let path = dir.path().join("settings.json");
|
||||
let (store, saved) = settings::Store::at(path.clone());
|
||||
let ctx = egui::Context::default();
|
||||
let mut app = Editor::with_settings(&ctx, store, saved);
|
||||
let before = *app.layout.layers();
|
||||
app.fields[0] = "123.5".into();
|
||||
let draft = app.fields.clone();
|
||||
app.preferences_open = true;
|
||||
click_label(&mut app, &ctx, "Show toolbar icon names");
|
||||
click_label(&mut app, &ctx, "Editing");
|
||||
click_label(&mut app, &ctx, "Keep aspect ratio when resizing");
|
||||
click_label(&mut app, &ctx, "Snap while moving layers");
|
||||
let (_, saved) = settings::Store::at(path);
|
||||
assert!(saved.snapping.enabled);
|
||||
assert!(saved.show_toolbar_icon_names);
|
||||
assert!(!saved.keep_aspect_ratio);
|
||||
assert_eq!(*app.layout.layers(), before);
|
||||
assert_eq!(app.fields, draft);
|
||||
click_label(&mut app, &ctx, "Close");
|
||||
assert!(!app.preferences_open);
|
||||
}
|
||||
#[test]
|
||||
fn command_comma_opens_preferences() {
|
||||
let ctx = egui::Context::default();
|
||||
let mut app = Editor::default();
|
||||
frame(
|
||||
&mut app,
|
||||
&ctx,
|
||||
vec![egui::Event::Key {
|
||||
key: egui::Key::Comma,
|
||||
physical_key: None,
|
||||
pressed: true,
|
||||
repeat: false,
|
||||
modifiers: egui::Modifiers {
|
||||
ctrl: true,
|
||||
command: true,
|
||||
..Default::default()
|
||||
},
|
||||
}],
|
||||
);
|
||||
assert!(app.preferences_open);
|
||||
}
|
||||
}
|
||||
|
|
@ -49,6 +49,7 @@ impl Editor {
|
|||
// Replace only after both the document and embedded image are ready.
|
||||
*self = Self {
|
||||
settings: std::mem::take(&mut self.settings),
|
||||
snapping: self.snapping,
|
||||
layout,
|
||||
reference,
|
||||
corner: e.position_corner,
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ pub struct Settings {
|
|||
pub version: u32,
|
||||
pub theme: Theme,
|
||||
pub recent_themes: Vec<Theme>,
|
||||
pub snapping: midra_layout::snapping::Snapping,
|
||||
pub show_toolbar_icon_names: bool,
|
||||
pub keep_aspect_ratio: bool,
|
||||
pub show_source_pattern: bool,
|
||||
|
|
@ -16,9 +17,10 @@ pub struct Settings {
|
|||
impl Default for Settings {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
version: 2,
|
||||
version: 3,
|
||||
theme: Theme::Midra,
|
||||
recent_themes: vec![Theme::Midra],
|
||||
snapping: Default::default(),
|
||||
show_toolbar_icon_names: false,
|
||||
keep_aspect_ratio: true,
|
||||
show_source_pattern: false,
|
||||
|
|
@ -44,12 +46,20 @@ impl Settings {
|
|||
value["recent_themes"] = serde_json::json!([theme]);
|
||||
value["version"] = 2.into();
|
||||
}
|
||||
if value["version"] == 2 {
|
||||
if value.get("snapping").is_some() {
|
||||
return Err("Unexpected snapping in version 2 settings".into());
|
||||
}
|
||||
value["snapping"] = serde_json::to_value(midra_layout::snapping::Snapping::default())
|
||||
.map_err(|e| e.to_string())?;
|
||||
value["version"] = 3.into();
|
||||
}
|
||||
let settings: Self = serde_json::from_value(value).map_err(|e| e.to_string())?;
|
||||
settings.validate()?;
|
||||
Ok(settings)
|
||||
}
|
||||
fn validate(&self) -> Result<(), String> {
|
||||
if self.version != 2 {
|
||||
if self.version != 3 {
|
||||
return Err(format!("unsupported settings version {}", self.version));
|
||||
}
|
||||
if self.recent_themes.is_empty()
|
||||
|
|
@ -186,7 +196,7 @@ mod tests {
|
|||
for text in [
|
||||
"broken".to_string(),
|
||||
serde_json::to_string(&Settings {
|
||||
version: 3,
|
||||
version: 4,
|
||||
..Default::default()
|
||||
})
|
||||
.unwrap(),
|
||||
|
|
@ -237,4 +247,16 @@ mod tests {
|
|||
assert!(Settings::parse(&value.to_string()).is_err());
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn version_three_adds_disabled_snapping_to_older_settings() {
|
||||
let example =
|
||||
include_str!("../../../docs/interfaces/midra-layout-settings-v3.example.json");
|
||||
assert_eq!(Settings::parse(example).unwrap(), Settings::default());
|
||||
let mut settings = Settings::default();
|
||||
settings.snapping.enabled = true;
|
||||
assert_eq!(
|
||||
Settings::parse(&serde_json::to_string(&settings).unwrap()).unwrap(),
|
||||
settings
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,104 @@
|
|||
//! Proximity snapping for moving one layer or a selection as a rigid group.
|
||||
use crate::{Geometry, Layout};
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct Snapping {
|
||||
pub enabled: bool,
|
||||
pub pixels: bool,
|
||||
pub screen_edges: bool,
|
||||
pub layer_edges: bool,
|
||||
}
|
||||
impl Default for Snapping {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
enabled: false,
|
||||
pixels: true,
|
||||
screen_edges: true,
|
||||
layer_edges: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl Layout {
|
||||
/// Recompute from the gesture's original snapshot, never from a previous snapped frame.
|
||||
/// `tolerance` is in screen pixels; the UI converts its fixed logical hit distance.
|
||||
/// Resizing and content gestures retain their existing anchor/crop semantics.
|
||||
pub fn drag_to_snapped(
|
||||
&mut self,
|
||||
point: [f64; 2],
|
||||
options: Snapping,
|
||||
tolerance: f64,
|
||||
) -> [Option<f64>; 2] {
|
||||
let mut guides = [None; 2];
|
||||
let Some((selected, before, start)) = self.drag else {
|
||||
self.drag_to(point);
|
||||
return guides;
|
||||
};
|
||||
if !options.enabled || !tolerance.is_finite() || tolerance < 0.0 {
|
||||
self.drag_to(point);
|
||||
return guides;
|
||||
}
|
||||
if point.iter().any(|v| !v.is_finite()) {
|
||||
return guides;
|
||||
}
|
||||
let mut delta = [point[0] - start[0], point[1] - start[1]];
|
||||
let edge = |g: Geometry, axis: usize| {
|
||||
if axis == 0 {
|
||||
[g.x, g.x + g.width]
|
||||
} else {
|
||||
[g.y, g.y + g.height]
|
||||
}
|
||||
};
|
||||
for axis in 0..2 {
|
||||
let mut targets = Vec::new();
|
||||
if options.screen_edges {
|
||||
targets.extend([0.0, self.formats.output[axis] as f64]);
|
||||
}
|
||||
if options.layer_edges {
|
||||
for (i, g) in before.layers.iter().enumerate() {
|
||||
if !selected[i] && self.visible[i] {
|
||||
targets.extend(edge(*g, axis));
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut best: Option<(f64, f64)> = None;
|
||||
for (i, g) in before.layers.iter().enumerate() {
|
||||
if !selected[i] {
|
||||
continue;
|
||||
}
|
||||
for moving in edge(*g, axis) {
|
||||
for target in &targets {
|
||||
let correction = *target - (moving + delta[axis]);
|
||||
if correction.abs() <= tolerance
|
||||
&& best.is_none_or(|(d, _)| correction.abs() < d.abs())
|
||||
{
|
||||
best = Some((correction, *target));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some((correction, target)) = best {
|
||||
delta[axis] += correction;
|
||||
guides[axis] = Some(target);
|
||||
} else if options.pixels
|
||||
&& let Some(i) = selected.iter().position(|v| *v)
|
||||
{
|
||||
let coordinate = edge(before.layers[i], axis)[0] + delta[axis];
|
||||
delta[axis] += coordinate.round() - coordinate;
|
||||
}
|
||||
}
|
||||
let mut next = before.layers;
|
||||
for (i, g) in next.iter_mut().enumerate() {
|
||||
if selected[i] {
|
||||
g.x += delta[0];
|
||||
g.y += delta[1];
|
||||
}
|
||||
}
|
||||
if next.iter().all(|g| g.validate().is_ok()) {
|
||||
self.layers = next;
|
||||
} else {
|
||||
guides = [None; 2];
|
||||
}
|
||||
guides
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,99 @@
|
|||
use midra_layout::{Layout, snapping::Snapping};
|
||||
|
||||
#[test]
|
||||
fn screen_snapping_recomputes_from_original_and_is_one_undo_step() {
|
||||
let mut layout = Layout::default();
|
||||
let before = *layout.layers();
|
||||
let formats = *layout.formats();
|
||||
let options = Snapping {
|
||||
enabled: true,
|
||||
layer_edges: false,
|
||||
..Default::default()
|
||||
};
|
||||
layout.start_drag([1200.0, 200.0]);
|
||||
assert_eq!(
|
||||
layout.drag_to_snapped([1317.0, 201.0], options, 6.0),
|
||||
[Some(1920.0), None]
|
||||
);
|
||||
assert_eq!(layout.layers()[1].x, 1280.0);
|
||||
layout.drag_to_snapped([1250.0, 200.0], options, 6.0);
|
||||
assert_eq!(layout.layers()[1].x, before[1].x + 50.0);
|
||||
layout.drag_to_snapped([1317.0, 201.0], options, 6.0);
|
||||
layout.finish_drag();
|
||||
assert_eq!(*layout.formats(), formats);
|
||||
layout.undo();
|
||||
assert_eq!(*layout.layers(), before);
|
||||
layout.redo();
|
||||
assert_eq!(layout.layers()[1].x, 1280.0);
|
||||
}
|
||||
#[test]
|
||||
fn visible_layer_edges_include_locked_targets_but_not_hidden_targets() {
|
||||
let options = Snapping {
|
||||
enabled: true,
|
||||
screen_edges: false,
|
||||
pixels: false,
|
||||
..Default::default()
|
||||
};
|
||||
for hidden in [false, true] {
|
||||
let mut layout = Layout::default();
|
||||
layout.set_locked(0, true);
|
||||
if hidden {
|
||||
layout.set_visible(0, false);
|
||||
}
|
||||
layout.start_drag([1160.0, 180.0]);
|
||||
let guides = layout.drag_to_snapped([763.0, 190.0], options, 6.0);
|
||||
assert_eq!(guides[0], if hidden { None } else { Some(760.0) });
|
||||
assert_eq!(layout.layers()[1].x, if hidden { 763.0 } else { 760.0 });
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn group_snapping_preserves_spacing_and_cancel_restores_geometry() {
|
||||
let mut layout = Layout::default();
|
||||
layout.set_selection([true; 2]);
|
||||
let before = *layout.layers();
|
||||
layout.start_drag([200.0, 200.0]);
|
||||
layout.drag_to_snapped(
|
||||
[83.0, 200.0],
|
||||
Snapping {
|
||||
enabled: true,
|
||||
..Default::default()
|
||||
},
|
||||
6.0,
|
||||
);
|
||||
assert_eq!(layout.layers()[0].x, 0.0);
|
||||
assert_eq!(
|
||||
layout.layers()[1].x - layout.layers()[0].x,
|
||||
before[1].x - before[0].x
|
||||
);
|
||||
layout.cancel_drag();
|
||||
assert_eq!(*layout.layers(), before);
|
||||
layout.start_drag([200.0, 200.0]);
|
||||
assert_eq!(
|
||||
layout.drag_to_snapped([83.0, 200.0], Snapping::default(), 6.0),
|
||||
[None; 2]
|
||||
);
|
||||
assert_eq!(layout.layers()[0].x, 3.0);
|
||||
}
|
||||
#[test]
|
||||
fn pixel_snap_can_be_disabled_and_numeric_entry_bypasses_it() {
|
||||
let mut layout = Layout::default();
|
||||
let mut g = layout.layers()[1];
|
||||
g.x = 1160.25;
|
||||
layout.apply(1, g).unwrap();
|
||||
for pixels in [false, true] {
|
||||
layout.start_drag([1200.0, 200.0]);
|
||||
layout.drag_to_snapped(
|
||||
[1200.2, 200.0],
|
||||
Snapping {
|
||||
enabled: true,
|
||||
pixels,
|
||||
screen_edges: false,
|
||||
layer_edges: false,
|
||||
},
|
||||
6.0,
|
||||
);
|
||||
assert!((layout.layers()[1].x - if pixels { 1160.0 } else { 1160.45 }).abs() < 1e-8);
|
||||
layout.cancel_drag();
|
||||
assert_eq!(layout.layers()[1], g);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"version": 3,
|
||||
"theme": "midra",
|
||||
"recent_themes": [
|
||||
"midra"
|
||||
],
|
||||
"show_toolbar_icon_names": false,
|
||||
"keep_aspect_ratio": true,
|
||||
"show_source_pattern": false,
|
||||
"snapping": {
|
||||
"enabled": false,
|
||||
"pixels": true,
|
||||
"screen_edges": true,
|
||||
"layer_edges": true
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,13 @@
|
|||
# Midra Layout application settings, version 2
|
||||
# Midra Layout application settings, version 3
|
||||
|
||||
Implementation: `crates/midra-layout/src/settings.rs`. This per-user JSON file is
|
||||
independent of the [project JSON and SVG contracts](midra-layout.md).
|
||||
[Complete default example](midra-layout-settings-v2.example.json).
|
||||
[Complete default example](midra-layout-settings-v3.example.json).
|
||||
Version 1 files migrate automatically: the saved theme becomes the only entry in
|
||||
`recent_themes`, with all other preferences preserved. The [version 1 example](midra-layout-settings-v1.example.json)
|
||||
remains a migration fixture. Saving writes version 2; old applications reject it.
|
||||
remains a migration fixture. Version 2 files then migrate by adding disabled
|
||||
snapping with all target types enabled. The [version 2 example](midra-layout-settings-v2.example.json)
|
||||
remains a migration fixture too. Saving writes version 3; old applications reject it.
|
||||
|
||||
The `directories` 6 crate resolves `ProjectDirs::from("org", "beffroi", "midra-layout")`.
|
||||
The filename is `settings.json` beneath `config_dir()`:
|
||||
|
|
@ -22,12 +24,13 @@ unknown theme names are rejected. There are no numeric coordinates or units.
|
|||
|
||||
| Field | Values / default |
|
||||
| --- | --- |
|
||||
| `version` | Integer `2` |
|
||||
| `version` | Integer `3` |
|
||||
| `theme` | Theme ID from the catalog below; default `"midra"` |
|
||||
| `recent_themes` | 1–3 unique theme IDs, newest first; first must equal `theme`; default `["midra"]` |
|
||||
| `show_toolbar_icon_names` | Boolean; default false |
|
||||
| `keep_aspect_ratio` | Boolean; default true |
|
||||
| `show_source_pattern` | Boolean; default false |
|
||||
| `snapping` | Object with required boolean fields `enabled` (false), `pixels` (true), `screen_edges` (true), `layer_edges` (true); unknown fields rejected |
|
||||
|
||||
Loaded once at startup before the editor appears. Explicit Options changes save
|
||||
the current preferences and theme history immediately. The directory is created lazily;
|
||||
|
|
@ -41,7 +44,8 @@ the restored history. Opening or dismissing the full picker changes nothing.
|
|||
Project JSON v1/v2 remains unchanged. Opening a project can restore its embedded
|
||||
caption, aspect-ratio and source-preview preferences for that document; it never
|
||||
writes application settings. Theme remains global. Editing an option afterward
|
||||
saves all currently active preferences as the next startup defaults.
|
||||
saves all currently active preferences as the next startup defaults. Snapping remains
|
||||
an application preference and is not read from or written into project JSON.
|
||||
|
||||
Invalid/unreadable settings fall back to defaults, report the failure in Options,
|
||||
and disable writes for that run to preserve the original file. Repair/move the
|
||||
|
|
@ -88,3 +92,11 @@ The picker includes both light and dark themes with color swatches.
|
|||
| USTF | `ustf` | `theme-ustf.css` |
|
||||
| Verdant Rebel | `verdant_rebel` | `theme-verdant-rebel.css` |
|
||||
| Weicat Industrial | `weicat_industrial` | `theme-weicat-industrial.css` |
|
||||
|
||||
The Preferences window and quick menus share the same settings. Changes apply
|
||||
and save immediately; closing the window requires no Apply step. Restore default
|
||||
preferences resets all values, including theme history and snapping, without
|
||||
changing layer geometry or pending position/size text fields. Snapping uses a
|
||||
fixed six-logical-pixel proximity radius converted by viewport scale. It affects
|
||||
layer movement only; numeric entry, nudges, resize and crop gestures bypass it.
|
||||
Alt temporarily disables it without changing the saved option.
|
||||
|
|
|
|||
|
|
@ -12,6 +12,33 @@ Target: Analog Way Eikos 4K, running the latest firmware according to the user.
|
|||
Record the actual installed version during compatibility checks; do not infer it
|
||||
from a different Midra generation's documentation. Working name: **Midra Layout**.
|
||||
|
||||
## Reconciled implementation status
|
||||
|
||||
The offline editor now includes source/input/layer formats and cropping, all eight
|
||||
layer and crop handles, multi-selection/group resizing/alignment, reference import,
|
||||
draw.io/native/SVG paste with review, JSON project save/load, SVG all/visible export,
|
||||
19 bundled themes, recent-theme history and persistent application preferences.
|
||||
A full Preferences window and optional movement snapping with guides/Alt bypass
|
||||
are implemented. Project save/load and theme preferences are no longer future work.
|
||||
|
||||
Remaining work, in priority order:
|
||||
|
||||
1. Replace fixed two-layer arrays with stable-ID collections; add/remove/rename,
|
||||
preserve history and migrate save files. Optional folders follow this foundation.
|
||||
2. Reference native-size/offset mapping, outline-only layer display, adaptive image
|
||||
filtering and decoding away from the UI thread. Current decoding is bounded
|
||||
but synchronous. Pixel-grid/ruler refinement and resize snapping are follow-ups.
|
||||
3. Additional clipboard adapters after obtaining real application/version samples.
|
||||
4. Local device mappings, specific-layer export, destination review, and two
|
||||
independently tested sizing/crop strategies. Hardware values remain provisional.
|
||||
5. Mocked REST integration and exact-firmware verification in an isolated setup.
|
||||
No authorization to probe/write the currently live Eikos is implied.
|
||||
6. Operator-laptop/DPI/OS acceptance, performance measurements and release packaging.
|
||||
|
||||
Checked entries below refer to implemented offline behavior. Items combining an
|
||||
implemented feature with an unverified hardware or platform acceptance gate stay
|
||||
open; those gates are not claimed complete merely because automated tests pass.
|
||||
|
||||
## Intended workflow
|
||||
|
||||
Set the output format and preset or custom screen resolution, optionally load a reference picture, then place one or
|
||||
|
|
@ -30,7 +57,7 @@ Source routing, transitions, playback, masking, rotation, keying, live preview
|
|||
and device control remain outside the offline implementation scope. Device writes
|
||||
are a later stretch goal (step 10), not authorized work on the connected unit.
|
||||
Input cropping and virtual layer
|
||||
resolutions are now planned, with support deferred until after the first draft.
|
||||
resolutions are implemented offline; device mapping still requires verification.
|
||||
Their coordinate spaces must be designed from the start. See the
|
||||
[resolution and advanced-cropping specification](midra-layout-resolutions.md).
|
||||
|
||||
|
|
@ -64,7 +91,7 @@ label as WebRCS-compatible. The example math below is provisional until then.
|
|||
|
||||
- [x] Choose a direction from the three proposals below. Approved: A, with
|
||||
B's optional rulers and C's contextual alignment panel later.
|
||||
- [ ] Build a disposable viewport interaction spike with two rectangles before
|
||||
- [x] Build a disposable viewport interaction spike with two rectangles before
|
||||
committing to the full UI. Rust/egui is the preferred starting point because
|
||||
the repository already uses it; validate interaction quality before settling.
|
||||
- [ ] Prove pointer-centered zoom, pan, selection, hit testing, keyboard nudge,
|
||||
|
|
@ -89,7 +116,7 @@ toolkit cannot meet these needs, resolve that before building the rest.
|
|||
controls. Do not implement crop interactions until after the first draft.
|
||||
- [ ] Implement four-corner offset conversion and inverse WebRCS conversion
|
||||
under the verified device contract.
|
||||
- [ ] Switching corner changes the displayed offsets without moving the layer.
|
||||
- [x] Switching corner changes the displayed offsets without moving the layer.
|
||||
Resizing keeps the chosen corner and its offsets fixed; moving changes offsets.
|
||||
- [ ] Preserve precision internally. Validate finite numbers, positive sizes and
|
||||
device limits; report unsupported values without silently clamping them.
|
||||
|
|
@ -102,35 +129,36 @@ Gate: viewport scale and UI state cannot affect geometry or conversion results.
|
|||
|
||||
- [ ] Add screen resolution controls, one/two-layer setup, persistent layer IDs
|
||||
and names, and a right-hand layer list with a selected-layer inspector.
|
||||
- [ ] Add source format choices (including 4:3, 16:9 and 16:10) with explicit
|
||||
- [x] Add source format choices (including 4:3, 16:9 and 16:10) with explicit
|
||||
native pixel dimensions; an aspect ratio alone is not a pixel resolution.
|
||||
- [ ] Add output format choices and clearly labeled viewport resolution presets
|
||||
- [x] Add output format choices and clearly labeled viewport resolution presets
|
||||
(HD 1280 × 720, Full HD 1920 × 1080, UHD 4K 3840 × 2160), plus manual width
|
||||
and height. Derive the output ratio from custom dimensions, never silently
|
||||
stretch them to match a preset. Other formats can be added after validation.
|
||||
- [ ] Changing output dimensions preserves existing layer pixel bounds, flags
|
||||
- [x] Changing output dimensions preserves existing layer pixel bounds, flags
|
||||
out-of-screen layers and rechecks reference-image mapping. Validate positive
|
||||
integer dimensions independently of verified device output support; custom
|
||||
planning geometry must not imply that Eikos accepts every output mode.
|
||||
- [ ] Support click selection, Shift-click multi-selection, clear selection and
|
||||
- [x] Support click selection, Shift-click multi-selection, clear selection and
|
||||
list selection for overlapped or off-screen rectangles. Define deterministic
|
||||
overlap hit testing; list order represents preview stacking, not device routing.
|
||||
- [ ] Add dragging, exact width/height fields, four-corner selection and inward
|
||||
- [x] Add dragging, exact width/height fields, four-corner selection and inward
|
||||
offsets. Prefer numeric sizing first; add resize handles only with anchor
|
||||
behavior consistent with the geometry contract.
|
||||
- [ ] Show WebRCS horizontal/vertical center values beside corner inputs; make
|
||||
output values read-only initially. Offer per-value copy and labeled plain text
|
||||
for a whole layer. Do not imply plain text is a WebRCS-native clipboard format.
|
||||
- [ ] Add arrow nudges of 1 screen pixel and Shift-arrow nudges of 10; focused
|
||||
- [x] Add arrow nudges of 1 screen pixel and Shift-arrow nudges of 10; focused
|
||||
text fields must receive these keys instead of moving the selection.
|
||||
- [ ] Implement Space-drag/middle-button pan, pointer-centered zoom, Fit screen,
|
||||
- [x] Implement Space-drag/middle-button pan, pointer-centered zoom, Fit screen,
|
||||
Fit selection, explicit zoom percentage and a clearly defined 1:1 pixel view.
|
||||
- [ ] Keep handles/hit areas legible at every zoom; distinguish UI logical points,
|
||||
- [x] Keep handles/hit areas legible at every zoom; distinguish UI logical points,
|
||||
screen pixels and physical display pixels on HiDPI screens.
|
||||
- [ ] Add visible optional snapping to pixel edges, screen edges and other layer
|
||||
edges. Exact numeric entry bypasses proximity snapping. Show the active guide
|
||||
- [x] Add visible optional snapping to pixel edges, screen edges and other layer
|
||||
edges during movement. Resize/crop handles retain their own behavior.
|
||||
Exact numeric entry bypasses proximity snapping. Show the active guide
|
||||
and allow a temporary snap override; toggling snapping must not move anything.
|
||||
- [ ] Add undo/redo for geometry changes, one undo step per drag or committed
|
||||
- [x] Add undo/redo for geometry changes, one undo step per drag or committed
|
||||
field edit, and Escape to cancel an in-progress drag or uncommitted edit.
|
||||
|
||||
Gate: place a layer 120 px from the right and 180 px from the top, change zoom,
|
||||
|
|
@ -140,7 +168,7 @@ and reference settings; multi-selection shows mixed values explicitly.
|
|||
|
||||
### 5. Add accurate reference-picture placement
|
||||
|
||||
- [ ] Load PNG/JPEG through a file picker or drag/drop; report decoding failures
|
||||
- [x] Load PNG/JPEG through a file picker or drag/drop; report decoding failures
|
||||
while preserving the current image. Keep source files unchanged.
|
||||
- [ ] Use a matching-resolution image at screen origin with 1 image pixel per
|
||||
screen pixel. For mismatched dimensions, display the mismatch and require an
|
||||
|
|
@ -159,11 +187,11 @@ layer; changing image opacity, visibility, zoom or filtering changes no geometry
|
|||
|
||||
### 6. Add extensible clipboard position import
|
||||
|
||||
- [ ] Start with an explicit, documented plain-text geometry format and a
|
||||
- [x] Start with an explicit, documented plain-text geometry format and a
|
||||
paste-preview panel. For example: `x=1160; y=180; width=640; height=360; origin=top-left; unit=px`.
|
||||
- [ ] Preview parsed values, origin, units, target layer and before/after bounds.
|
||||
- [x] Preview parsed values, origin, units, target layer and before/after bounds.
|
||||
Allow position-only import; importing size must be an explicit choice.
|
||||
- [ ] Treat Ctrl/Cmd-V in a focused text input as normal text paste. Elsewhere,
|
||||
- [x] Treat Ctrl/Cmd-V in a focused text input as normal text paste. Elsewhere,
|
||||
open geometry preview; do not mutate the document merely by reading clipboard.
|
||||
- [ ] Define adapters by source format/version. Collect actual clipboard samples
|
||||
from each requested software before claiming support. The first adapter now
|
||||
|
|
@ -171,7 +199,7 @@ layer; changing image opacity, visibility, zoom or filtering changes no geometry
|
|||
application from an unlabeled number tuple.
|
||||
- [ ] Make points, inches, percentages, source canvas origins, decimal conventions
|
||||
and scale explicit. Ambiguity produces an explanation, not a guessed placement.
|
||||
- [ ] Validate the complete proposed edit before applying it atomically, with one
|
||||
- [x] Validate the complete proposed edit before applying it atomically, with one
|
||||
undo step. Unknown formats, missing fields and invalid values preserve state.
|
||||
- [ ] Test real fixtures for every added adapter and clipboard failure behavior
|
||||
on supported desktop platforms, including Wayland where applicable.
|
||||
|
|
@ -214,24 +242,24 @@ regardless of selection order except when explicitly choosing a reference layer.
|
|||
- [ ] Integrate the actual crate into workspace CI, coverage and manual packaging;
|
||||
run the repository Rust gates, whole-application coverage and relevant packaging
|
||||
tests. Document unavailable device or desktop checks.
|
||||
- [ ] Commit each completed task; no automatic release publishing.
|
||||
- [x] Commit each completed task; no automatic release publishing.
|
||||
|
||||
Session-file save/load can follow if needed; it is not required to demonstrate
|
||||
precise positioning. Networking is deferred to the separate stretch goal below.
|
||||
Project JSON save/load and SVG geometry export are implemented and documented in
|
||||
`docs/interfaces/`. Networking remains separate from file export.
|
||||
|
||||
### 9. After the first draft: input and layer resolutions
|
||||
|
||||
- [ ] Implement the separate input-crop and advanced-crop stages defined in the
|
||||
- [x] Implement the separate input-crop and advanced-crop stages defined in the
|
||||
[resolution specification](midra-layout-resolutions.md), with no device calls.
|
||||
- [ ] Keep Source format selected when Input resolution is Custom. Support exact
|
||||
- [x] Keep Source format selected when Input resolution is Custom. Support exact
|
||||
input dimensions and crop placement, defaulting to equal opposite-side crops.
|
||||
- [ ] Expose Layer resolution as the final visible width/height, with optional
|
||||
- [x] Expose Layer resolution as the final visible width/height, with optional
|
||||
aspect lock. Add Content zoom and Offset X/Y controls and an explicit content
|
||||
framing mode; moving the layer and moving its content must be distinct actions.
|
||||
- [ ] Keep the final box fixed during content framing; store four crop edges and
|
||||
- [x] Keep the final box fixed during content framing; store four crop edges and
|
||||
final size, derive zoom/offset, and compose input/layer crops without applying
|
||||
either stage twice. Preserve source-level sharing when two layers use one input.
|
||||
- [ ] Test the documented numerical examples, inverse transforms, offset limits,
|
||||
- [x] Test the documented numerical examples, inverse transforms, offset limits,
|
||||
extreme ratios, fractional crops, resizing, shared inputs and undo behavior.
|
||||
- [ ] Verify the device adapter's crop units, Centered mode, layer container size
|
||||
and center position with the actual firmware. Show rounding error; block values
|
||||
|
|
@ -471,7 +499,7 @@ with the user-supplied percent-encoded rectangle retained as a regression fixtur
|
|||
Reference-picture implementation update: PNG/JPEG/BMP import and file drop are
|
||||
available, with fill-screen or proportion-preserving fit, opacity and visibility.
|
||||
Resolution scaling produces a warning; aspect distortion a severe warning. Both
|
||||
remain non-blocking. Image offsets and persistent sessions remain future work.
|
||||
remain non-blocking. Image offsets remain future work; project save/load is implemented.
|
||||
|
||||
Corner-resizing implementation update: selected layers have interactive corner
|
||||
handles with a fixed opposite anchor, ratio locking enabled by default, an explicit
|
||||
|
|
|
|||
|
|
@ -204,13 +204,13 @@ Output resolution defaults to **1920 × 1080 (16:9)** and can be changed.
|
|||
The output dialog identifies standard aspect ratios from the current resolution;
|
||||
nonstandard ratios display as Custom.
|
||||
The initial backdrop is illustrative; importing a reference picture replaces it.
|
||||
Live video, verified hardware container/crop conversion and persistent session
|
||||
files are future work. Sessions currently live only in memory.
|
||||
Live video and verified hardware container/crop conversion remain future work.
|
||||
Project JSON save/load and SVG geometry export are implemented (see below).
|
||||
|
||||
[Layer management and export scope](midra-layout-plan.md#11-later-stretch-goal-layer-management-and-export-scope)
|
||||
are also later stretch goals: **Add layer**, Midra layer
|
||||
mapping in **Options**, and export of a **specific layer** or **visible layers
|
||||
only**. Optional folders would organize local layers. Visibility and organization
|
||||
mapping in **Options**, and device-targeted export of a **specific layer** or
|
||||
**visible layers only**. SVG already supports all or visible layers. Optional folders would organize local layers. Visibility and organization
|
||||
will not send commands or change the live device.
|
||||
|
||||
Applying layer format through the WebRCS REST API is a
|
||||
|
|
@ -482,3 +482,29 @@ documents the file and compatibility rules.
|
|||
right-click menu (including multiple selections). These controls share the
|
||||
Options setting and save changes automatically. They do not apply or discard
|
||||
pending size/position edits. Crop zoom remains proportional.
|
||||
|
||||
## Preferences window
|
||||
|
||||
Open **Menu → Preferences…**, **Options → Preferences…**, the toolbar cog's
|
||||
**Preferences…** entry, or **Ctrl/Cmd+,**. The window groups the available controls:
|
||||
|
||||
- **Appearance:** themes, recent choices, icon captions and source-coordinate preview.
|
||||
- **Editing:** aspect-ratio lock, movement snapping and a keyboard/mouse reference.
|
||||
- **Reference images:** import and access to the current project's image settings.
|
||||
- **Files & settings:** the settings-file path, copy-path action and restore defaults.
|
||||
- **Midra integration:** current offline status and compatibility limitations.
|
||||
|
||||
Changes apply and save immediately, sharing state with quick menus and inspector
|
||||
shortcuts. Close simply dismisses the window. Restore defaults resets preferences
|
||||
without altering geometry or pending position/size edits. Device controls are not
|
||||
presented as implemented until their mapping and transport are available.
|
||||
|
||||
### Movement snapping
|
||||
|
||||
Enable **Preferences → Editing → Snap while moving layers** and choose pixel,
|
||||
screen-edge and/or other-visible-layer-edge targets. Nearby edges show a guide;
|
||||
the proximity radius stays six logical pixels at any zoom. A selection moves as
|
||||
a rigid group. Hidden layers are ignored; visible locked layers can be targets.
|
||||
Hold **Alt** to bypass snapping. Turning snapping on/off alone never moves layers.
|
||||
Exact numeric entry and nudges bypass proximity snapping; resize and crop handles
|
||||
retain their existing behavior. One drag remains one undo step, with Escape to cancel.
|
||||
|
|
|
|||
Loading…
Reference in New Issue