Add center reference for Midra layer positioning
This commit is contained in:
parent
fa738f0ec4
commit
8a2e08397c
|
|
@ -46,7 +46,7 @@ impl FormatDraft {
|
|||
self.baseline.4 = self.framing;
|
||||
Ok(())
|
||||
}
|
||||
fn apply(&mut self, layout: &mut Layout, corner: Corner) -> Result<(), String> {
|
||||
fn apply(&mut self, layout: &mut Layout, corner: PositionPoint) -> Result<(), String> {
|
||||
let input = self.source.input()?;
|
||||
if input
|
||||
.iter()
|
||||
|
|
|
|||
|
|
@ -15,7 +15,9 @@ mod project_ui;
|
|||
mod viewport_guides;
|
||||
use format_ui::{FormatDraft, OutputDraft, PropertyTab};
|
||||
use midra_layout::import::{DetectedShape, ImportDocument, parse_svg, parse_values};
|
||||
use midra_layout::{AlignTarget, Alignment, Corner, Geometry, Layout, ResizeHandle, ResizeMode};
|
||||
use midra_layout::{
|
||||
AlignTarget, Alignment, Corner, Geometry, Layout, PositionPoint, ResizeHandle, ResizeMode,
|
||||
};
|
||||
|
||||
pub struct Editor {
|
||||
device: device_ui::DeviceUi,
|
||||
|
|
@ -28,7 +30,7 @@ pub struct Editor {
|
|||
preferences_section: preferences_ui::Section,
|
||||
layout: Layout,
|
||||
files: project_ui::FileUi,
|
||||
corner: Corner,
|
||||
corner: PositionPoint,
|
||||
fields: [String; 4],
|
||||
field_rects: [Rect; 4],
|
||||
fields_closing: bool,
|
||||
|
|
@ -228,7 +230,7 @@ impl Default for Editor {
|
|||
preferences_section: preferences_ui::Section::default(),
|
||||
layout: Layout::default(),
|
||||
files: project_ui::FileUi::default(),
|
||||
corner: Corner::TopRight,
|
||||
corner: PositionPoint::TopRight,
|
||||
fields: Default::default(),
|
||||
field_rects: [Rect::NOTHING; 4],
|
||||
fields_closing: false,
|
||||
|
|
@ -1108,19 +1110,14 @@ impl Editor {
|
|||
).size(12.0).color(palette.muted)).wrap().halign(egui::Align::Min),
|
||||
);
|
||||
let ink = Ink::new(ui, r.translate(Vec2::new(0.0, 108.0)));
|
||||
ink.text(
|
||||
0.0,
|
||||
267.0,
|
||||
"POSITION FROM SCREEN CORNER",
|
||||
11.0,
|
||||
palette.muted,
|
||||
);
|
||||
ink.text(0.0, 267.0, "MEASURE POSITION FROM", 11.0, palette.muted);
|
||||
ink.card(0.0, 292.0, 94.0, 58.0, palette.field, palette.line);
|
||||
for (x, y, c) in [
|
||||
(8.0, 300.0, Corner::TopLeft),
|
||||
(84.0, 300.0, Corner::TopRight),
|
||||
(8.0, 342.0, Corner::BottomLeft),
|
||||
(84.0, 342.0, Corner::BottomRight),
|
||||
(8.0, 300.0, PositionPoint::TopLeft),
|
||||
(84.0, 300.0, PositionPoint::TopRight),
|
||||
(8.0, 342.0, PositionPoint::BottomLeft),
|
||||
(84.0, 342.0, PositionPoint::BottomRight),
|
||||
(46.0, 321.0, PositionPoint::Center),
|
||||
] {
|
||||
ink.rect(
|
||||
x - 3.0,
|
||||
|
|
@ -1144,13 +1141,24 @@ impl Editor {
|
|||
}
|
||||
}
|
||||
let (name, horizontal, vertical) = match self.corner {
|
||||
Corner::TopLeft => ("Top left", "From left", "From top"),
|
||||
Corner::TopRight => ("Top right", "From right", "From top"),
|
||||
Corner::BottomLeft => ("Bottom left", "From left", "From bottom"),
|
||||
Corner::BottomRight => ("Bottom right", "From right", "From bottom"),
|
||||
PositionPoint::Center => ("Center", "Center X offset", "Center Y offset"),
|
||||
PositionPoint::TopLeft => ("Top left", "From left", "From top"),
|
||||
PositionPoint::TopRight => ("Top right", "From right", "From top"),
|
||||
PositionPoint::BottomLeft => ("Bottom left", "From left", "From bottom"),
|
||||
PositionPoint::BottomRight => ("Bottom right", "From right", "From bottom"),
|
||||
};
|
||||
ink.text(112.0, 299.0, name, 18.0, palette.text);
|
||||
ink.text(112.0, 326.0, "Offsets inward · px", 12.0, palette.muted);
|
||||
ink.text(
|
||||
112.0,
|
||||
326.0,
|
||||
if self.corner == PositionPoint::Center {
|
||||
"+ right / + down · px"
|
||||
} else {
|
||||
"Offsets inward · px"
|
||||
},
|
||||
12.0,
|
||||
palette.muted,
|
||||
);
|
||||
let half = (w - 12.0) / 2.0;
|
||||
let mut enter = false;
|
||||
for (index, x, y, title) in [
|
||||
|
|
@ -2346,9 +2354,15 @@ impl Editor {
|
|||
let g = self.layout.layers()[i];
|
||||
if !g.outside_on(self.layout.formats().output) {
|
||||
let [dx, dy] = self.corner.offsets_on(g, self.layout.formats().output);
|
||||
let right = matches!(self.corner, Corner::TopRight | Corner::BottomRight);
|
||||
let bottom = matches!(self.corner, Corner::BottomLeft | Corner::BottomRight);
|
||||
let edge = origin
|
||||
let right = matches!(
|
||||
self.corner,
|
||||
PositionPoint::TopRight | PositionPoint::BottomRight
|
||||
);
|
||||
let bottom = matches!(
|
||||
self.corner,
|
||||
PositionPoint::BottomLeft | PositionPoint::BottomRight
|
||||
);
|
||||
let mut edge = origin
|
||||
+ Vec2::new(
|
||||
if right {
|
||||
(g.x + g.width) as f32
|
||||
|
|
@ -2361,9 +2375,14 @@ impl Editor {
|
|||
g.y as f32
|
||||
},
|
||||
) * scale;
|
||||
let boundary = origin
|
||||
let mut boundary = origin
|
||||
+ Vec2::new(if right { sw } else { 0.0 }, if bottom { sh } else { 0.0 })
|
||||
* scale;
|
||||
if self.corner == PositionPoint::Center {
|
||||
let center = g.center();
|
||||
edge = origin + Vec2::new(center[0] as f32, center[1] as f32) * scale;
|
||||
boundary = origin + Vec2::new(sw / 2.0, sh / 2.0) * scale;
|
||||
}
|
||||
let guide = &screen.painter;
|
||||
let stroke = Stroke::new(1.0_f32, palette.amber);
|
||||
guide.line_segment([edge, Pos2::new(boundary.x, edge.y)], stroke);
|
||||
|
|
@ -3028,6 +3047,41 @@ mod tests {
|
|||
);
|
||||
frame(app, ctx, vec![mouse(pos, false)]);
|
||||
}
|
||||
#[test]
|
||||
fn center_marker_switches_reference_without_moving_and_resizes_about_center() {
|
||||
let ctx = egui::Context::default();
|
||||
let mut app = Editor::default();
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
frame(&mut app, &ctx, vec![]);
|
||||
let before = app.layout.layers().clone();
|
||||
let output = frame(&mut app, &ctx, vec![]);
|
||||
let pos = output
|
||||
.shapes
|
||||
.iter()
|
||||
.find_map(|shape| match &shape.shape {
|
||||
egui::Shape::Text(text) if text.galley.text() == "MEASURE POSITION FROM" => {
|
||||
Some(text.pos + Vec2::new(46.0, 54.0))
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.unwrap();
|
||||
frame(
|
||||
&mut app,
|
||||
&ctx,
|
||||
vec![egui::Event::PointerMoved(pos), mouse(pos, true)],
|
||||
);
|
||||
frame(&mut app, &ctx, vec![mouse(pos, false)]);
|
||||
assert_eq!(app.corner, PositionPoint::Center);
|
||||
assert_eq!(app.layout.layers(), &before);
|
||||
let i = app.layout.selected().unwrap();
|
||||
let center = before[i].center();
|
||||
app.keep_aspect_ratio = false;
|
||||
app.fields[2] = "400".into();
|
||||
app.apply_fields();
|
||||
assert_eq!(app.layout.layers()[i].width, 400.0);
|
||||
assert_eq!(app.layout.layers()[i].center(), center);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn leaving_numeric_fields_commits_before_selection_changes_and_invalid_edits_prompt() {
|
||||
let ctx = egui::Context::default();
|
||||
|
|
|
|||
|
|
@ -417,7 +417,7 @@ mod tests {
|
|||
})
|
||||
.unwrap()
|
||||
};
|
||||
assert!(y("POSITION FROM SCREEN CORNER") > y("Adjust layer crop") + 60.0);
|
||||
assert!(y("MEASURE POSITION FROM") > y("Adjust layer crop") + 60.0);
|
||||
}
|
||||
#[test]
|
||||
fn many_layer_inspector_and_manager_render_after_history_changes() {
|
||||
|
|
|
|||
|
|
@ -279,6 +279,60 @@ impl Corner {
|
|||
}
|
||||
}
|
||||
|
||||
/// Matching screen/layer point used for numeric positioning.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum PositionPoint {
|
||||
#[default]
|
||||
TopLeft,
|
||||
TopRight,
|
||||
BottomLeft,
|
||||
BottomRight,
|
||||
Center,
|
||||
}
|
||||
impl PositionPoint {
|
||||
fn corner(self) -> Option<Corner> {
|
||||
match self {
|
||||
Self::TopLeft => Some(Corner::TopLeft),
|
||||
Self::TopRight => Some(Corner::TopRight),
|
||||
Self::BottomLeft => Some(Corner::BottomLeft),
|
||||
Self::BottomRight => Some(Corner::BottomRight),
|
||||
Self::Center => None,
|
||||
}
|
||||
}
|
||||
pub fn offsets_on(self, g: Geometry, output: [u32; 2]) -> [f64; 2] {
|
||||
if let Some(corner) = self.corner() {
|
||||
corner.offsets_on(g, output)
|
||||
} else {
|
||||
let center = g.center();
|
||||
[
|
||||
center[0] - output[0] as f64 / 2.0,
|
||||
center[1] - output[1] as f64 / 2.0,
|
||||
]
|
||||
}
|
||||
}
|
||||
pub fn geometry_on(
|
||||
self,
|
||||
dx: f64,
|
||||
dy: f64,
|
||||
width: f64,
|
||||
height: f64,
|
||||
output: [u32; 2],
|
||||
) -> Result<Geometry, String> {
|
||||
if let Some(corner) = self.corner() {
|
||||
corner.geometry_on(dx, dy, width, height, output)
|
||||
} else {
|
||||
Geometry {
|
||||
x: output[0] as f64 / 2.0 + dx - width / 2.0,
|
||||
y: output[1] as f64 / 2.0 + dy - height / 2.0,
|
||||
width,
|
||||
height,
|
||||
}
|
||||
.validate()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Edge or center line to align, without resizing layers.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub enum Alignment {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
//! Versioned offline interchange. Contract: docs/interfaces/midra-layout.md.
|
||||
use crate::{
|
||||
Corner, Geometry, Layout,
|
||||
Corner, Geometry, Layout, PositionPoint,
|
||||
formats::{self, Aspect, Crop, Source},
|
||||
};
|
||||
use base64::{Engine, engine::general_purpose::STANDARD};
|
||||
|
|
@ -89,7 +89,7 @@ impl Reference {
|
|||
#[serde(deny_unknown_fields)]
|
||||
pub struct EditorSettings {
|
||||
pub selected_layer_ids: Vec<usize>,
|
||||
pub position_corner: Corner,
|
||||
pub position_point: PositionPoint,
|
||||
pub keep_aspect_ratio: bool,
|
||||
pub viewport_zoom: f32,
|
||||
pub viewport_pan: [f32; 2],
|
||||
|
|
@ -113,7 +113,7 @@ impl Project {
|
|||
pub fn from_layout(layout: &Layout) -> Self {
|
||||
Self {
|
||||
format: FORMAT.into(),
|
||||
version: 5,
|
||||
version: 6,
|
||||
next_layer_id: layout.next_id,
|
||||
output_resolution: layout.formats.output.into(),
|
||||
inputs: (0..layout.formats.sources.len())
|
||||
|
|
@ -147,7 +147,7 @@ impl Project {
|
|||
.into_iter()
|
||||
.map(|i| layout.info[i].id)
|
||||
.collect(),
|
||||
position_corner: Corner::TopLeft,
|
||||
position_point: PositionPoint::TopLeft,
|
||||
keep_aspect_ratio: true,
|
||||
viewport_zoom: 1.0,
|
||||
viewport_pan: [0.0; 2],
|
||||
|
|
@ -159,9 +159,9 @@ impl Project {
|
|||
}
|
||||
/// Build a fresh document only after validating the entire file. No history is restored.
|
||||
pub fn layout(&self) -> Result<Layout, String> {
|
||||
if self.format != FORMAT || self.version != 5 {
|
||||
if self.format != FORMAT || self.version != 6 {
|
||||
return Err(
|
||||
"Unsupported project format/version; expected beffroi.midra-layout version 5."
|
||||
"Unsupported project format/version; expected beffroi.midra-layout version 6."
|
||||
.into(),
|
||||
);
|
||||
}
|
||||
|
|
@ -282,6 +282,9 @@ impl Project {
|
|||
}
|
||||
let header: Header =
|
||||
serde_json::from_str(text).map_err(|e| format!("Invalid project JSON: {e}"))?;
|
||||
if !(1..=6).contains(&header.version) {
|
||||
return Err("Unsupported project version; expected versions 1–6.".into());
|
||||
}
|
||||
let mut migrated: serde_json::Value = if header.version == 1 || header.version == 2 {
|
||||
let mut value: serde_json::Value =
|
||||
serde_json::from_str(text).map_err(|e| format!("Invalid project JSON: {e}"))?;
|
||||
|
|
@ -359,6 +362,21 @@ impl Project {
|
|||
}
|
||||
migrated["version"] = 5.into();
|
||||
}
|
||||
if (1..=5).contains(&header.version) {
|
||||
let editor = migrated["editor"]
|
||||
.as_object_mut()
|
||||
.ok_or("Missing editor settings")?;
|
||||
if editor.contains_key("position_point") {
|
||||
return Err("Unexpected position point in old project".into());
|
||||
}
|
||||
let corner = editor
|
||||
.remove("position_corner")
|
||||
.ok_or("Missing position corner")?;
|
||||
serde_json::from_value::<Corner>(corner.clone())
|
||||
.map_err(|e| format!("Invalid position corner: {e}"))?;
|
||||
editor.insert("position_point".into(), corner);
|
||||
migrated["version"] = 6.into();
|
||||
}
|
||||
let p: Self =
|
||||
serde_json::from_value(migrated).map_err(|e| format!("Invalid project JSON: {e}"))?;
|
||||
p.layout()?;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ pub(super) struct FileUi {
|
|||
impl Editor {
|
||||
fn project(&self) -> Project {
|
||||
let mut p = Project::from_layout(&self.layout);
|
||||
p.editor.position_corner = self.corner;
|
||||
p.editor.position_point = self.corner;
|
||||
p.editor.keep_aspect_ratio = self.keep_aspect_ratio;
|
||||
p.editor.viewport_zoom = self.zoom;
|
||||
p.editor.viewport_pan = [self.pan.x, self.pan.y];
|
||||
|
|
@ -65,7 +65,7 @@ impl Editor {
|
|||
resize_mode: self.resize_mode,
|
||||
layout,
|
||||
reference,
|
||||
corner: e.position_corner,
|
||||
corner: e.position_point,
|
||||
keep_aspect_ratio: e.keep_aspect_ratio,
|
||||
zoom: e.viewport_zoom,
|
||||
pan: Vec2::from(e.viewport_pan),
|
||||
|
|
@ -333,7 +333,7 @@ mod tests {
|
|||
app.outline_layers = true;
|
||||
app.zoom = 2.5;
|
||||
app.pan = Vec2::new(-20.5, 40.0);
|
||||
app.corner = Corner::BottomRight;
|
||||
app.corner = PositionPoint::Center;
|
||||
app.keep_aspect_ratio = false;
|
||||
app.show_pattern = true;
|
||||
app.show_toolbar_icon_names = true;
|
||||
|
|
|
|||
|
|
@ -225,7 +225,7 @@ fn persistent_midra_links_roundtrip_migrate_and_undo() {
|
|||
include_str!("../../../docs/interfaces/midra-layout-v5.example.json"),
|
||||
] {
|
||||
let p = Project::from_json(text).unwrap();
|
||||
assert_eq!(p.version, 5);
|
||||
assert_eq!(p.version, 6);
|
||||
assert!(p.layers.iter().all(|l| l.midra_link.is_none()));
|
||||
}
|
||||
let mut value = serde_json::to_value(&project).unwrap();
|
||||
|
|
@ -238,3 +238,94 @@ fn persistent_midra_links_roundtrip_migrate_and_undo() {
|
|||
.remove("midra_link");
|
||||
assert!(Project::from_json(&value.to_string()).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn positioning_points_roundtrip_and_keep_their_reference_when_resized() {
|
||||
use midra_layout::PositionPoint;
|
||||
let output = [1921, 1081];
|
||||
let g = Geometry {
|
||||
x: 100.25,
|
||||
y: 200.5,
|
||||
width: 321.5,
|
||||
height: 181.25,
|
||||
};
|
||||
for point in [
|
||||
PositionPoint::TopLeft,
|
||||
PositionPoint::TopRight,
|
||||
PositionPoint::BottomLeft,
|
||||
PositionPoint::BottomRight,
|
||||
PositionPoint::Center,
|
||||
] {
|
||||
let [dx, dy] = point.offsets_on(g, output);
|
||||
assert_eq!(
|
||||
point
|
||||
.geometry_on(dx, dy, g.width, g.height, output)
|
||||
.unwrap(),
|
||||
g
|
||||
);
|
||||
let resized = point.geometry_on(dx, dy, 123.5, 99.25, output).unwrap();
|
||||
assert_eq!(point.offsets_on(resized, output), [dx, dy]);
|
||||
if point == PositionPoint::Center {
|
||||
assert!(dx < 0.0 && dy < 0.0);
|
||||
assert_eq!(resized.center(), g.center());
|
||||
}
|
||||
let mut project = Project::from_layout(&Layout::default());
|
||||
project.editor.position_point = point;
|
||||
assert_eq!(
|
||||
Project::from_json(&project.to_json().unwrap()).unwrap(),
|
||||
project
|
||||
);
|
||||
}
|
||||
let centered = PositionPoint::Center
|
||||
.geometry_on(0.0, 0.0, 320.0, 180.0, output)
|
||||
.unwrap();
|
||||
assert_eq!(centered.center(), [960.5, 540.5]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn position_point_schema_migrates_corners_and_rejects_mislabeled_files() {
|
||||
use midra_layout::PositionPoint;
|
||||
let current = Project::from_json(include_str!(
|
||||
"../../../docs/interfaces/midra-layout-v6.example.json"
|
||||
))
|
||||
.unwrap();
|
||||
assert_eq!(current, Project::from_layout(&Layout::default()));
|
||||
for (name, expected) in [
|
||||
("top_left", PositionPoint::TopLeft),
|
||||
("top_right", PositionPoint::TopRight),
|
||||
("bottom_left", PositionPoint::BottomLeft),
|
||||
("bottom_right", PositionPoint::BottomRight),
|
||||
] {
|
||||
let mut old: serde_json::Value = serde_json::from_str(include_str!(
|
||||
"../../../docs/interfaces/midra-layout-v5.example.json"
|
||||
))
|
||||
.unwrap();
|
||||
old["editor"]["position_corner"] = name.into();
|
||||
let loaded = Project::from_json(&old.to_string()).unwrap();
|
||||
assert_eq!(loaded.version, 6);
|
||||
assert_eq!(loaded.editor.position_point, expected);
|
||||
old["editor"]["position_corner"] = "center".into();
|
||||
assert!(Project::from_json(&old.to_string()).is_err());
|
||||
old["editor"]["position_corner"] = name.into();
|
||||
old["editor"]["position_point"] = name.into();
|
||||
assert!(Project::from_json(&old.to_string()).is_err());
|
||||
}
|
||||
let value: serde_json::Value = serde_json::from_str(¤t.to_json().unwrap()).unwrap();
|
||||
for version in [0, 7] {
|
||||
let mut invalid = value.clone();
|
||||
invalid["version"] = version.into();
|
||||
assert!(
|
||||
Project::from_json(&invalid.to_string())
|
||||
.unwrap_err()
|
||||
.contains("Unsupported")
|
||||
);
|
||||
}
|
||||
let mut invalid = value.clone();
|
||||
invalid["editor"]
|
||||
.as_object_mut()
|
||||
.unwrap()
|
||||
.remove("position_point");
|
||||
assert!(Project::from_json(&invalid.to_string()).is_err());
|
||||
invalid["editor"]["position_corner"] = "top_left".into();
|
||||
assert!(Project::from_json(&invalid.to_string()).is_err());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,99 @@
|
|||
{
|
||||
"format": "beffroi.midra-layout",
|
||||
"version": 6,
|
||||
"output_resolution": {
|
||||
"width": 1920,
|
||||
"height": 1080
|
||||
},
|
||||
"inputs": [
|
||||
{
|
||||
"id": 1,
|
||||
"source_format": "sixteen_nine",
|
||||
"native_resolution": {
|
||||
"width": 1920,
|
||||
"height": 1080
|
||||
},
|
||||
"input_crop": {
|
||||
"left": 0.0,
|
||||
"right": 0.0,
|
||||
"top": 0.0,
|
||||
"bottom": 0.0
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"source_format": "sixteen_nine",
|
||||
"native_resolution": {
|
||||
"width": 1920,
|
||||
"height": 1080
|
||||
},
|
||||
"input_crop": {
|
||||
"left": 0.0,
|
||||
"right": 0.0,
|
||||
"top": 0.0,
|
||||
"bottom": 0.0
|
||||
}
|
||||
}
|
||||
],
|
||||
"layers": [
|
||||
{
|
||||
"id": 1,
|
||||
"source_id": 1,
|
||||
"bounds": {
|
||||
"x": 120.0,
|
||||
"y": 180.0,
|
||||
"width": 640.0,
|
||||
"height": 360.0
|
||||
},
|
||||
"advanced_crop": {
|
||||
"left": 0.0,
|
||||
"right": 0.0,
|
||||
"top": 0.0,
|
||||
"bottom": 0.0
|
||||
},
|
||||
"visible": true,
|
||||
"locked": false,
|
||||
"name": "Presenter",
|
||||
"folder": "",
|
||||
"midra_link": null
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"source_id": 2,
|
||||
"bounds": {
|
||||
"x": 1160.0,
|
||||
"y": 180.0,
|
||||
"width": 640.0,
|
||||
"height": 360.0
|
||||
},
|
||||
"advanced_crop": {
|
||||
"left": 0.0,
|
||||
"right": 0.0,
|
||||
"top": 0.0,
|
||||
"bottom": 0.0
|
||||
},
|
||||
"visible": true,
|
||||
"locked": false,
|
||||
"name": "Slides",
|
||||
"folder": "",
|
||||
"midra_link": null
|
||||
}
|
||||
],
|
||||
"reference": null,
|
||||
"editor": {
|
||||
"selected_layer_ids": [
|
||||
2
|
||||
],
|
||||
"position_point": "top_left",
|
||||
"keep_aspect_ratio": true,
|
||||
"viewport_zoom": 1.0,
|
||||
"viewport_pan": [
|
||||
0.0,
|
||||
0.0
|
||||
],
|
||||
"show_source_pattern": false,
|
||||
"show_toolbar_icon_names": false,
|
||||
"outline_layers": false
|
||||
},
|
||||
"next_layer_id": 3
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@ These are offline editor formats, not Analog Way REST payloads. Implementation:
|
|||
[`project.rs`](../../crates/midra-layout/tests/project.rs). Update this contract,
|
||||
examples and tests in the same change as any save/export schema change.
|
||||
|
||||
## Project JSON, version 5
|
||||
## Project JSON, version 6
|
||||
|
||||
Suggested filename: `layout.midra.json`. Encoding: UTF-8, pretty-printed JSON,
|
||||
with a trailing newline. A project preserves applied document values at their
|
||||
|
|
@ -18,16 +18,16 @@ and `next_layer_id: 3`; other values are preserved.
|
|||
The [version 1 example](midra-layout-v1.example.json) remains a migration fixture.
|
||||
Version 4 adds `editor.outline_layers: false`, and reference `native_size: false`
|
||||
and `offset: [0, 0]` when migrating versions 1–3. Old fitting behavior is preserved.
|
||||
Version 5 adds required `midra_link` to every layer. Versions 1–4 migrate with null links; links cannot be supplied under an older version. Saving always writes version 5. Older applications reject version 5 files.
|
||||
Version 5 adds required `midra_link` to every layer. Versions 1–4 migrate with null links; links cannot be supplied under an older version. Version 6 renames `editor.position_corner` to `editor.position_point` and adds `center`. Versions 1–5 retain their original corner; center and the new field are rejected in those older schemas. Saving always writes version 6; older applications reject it.
|
||||
Incompatible files are never partially applied.
|
||||
|
||||
[Complete example](midra-layout-v5.example.json) is a valid default project,
|
||||
[Complete example](midra-layout-v6.example.json) is a valid default project,
|
||||
without a reference image. It is loaded by the regression tests.
|
||||
|
||||
| Root field | Representation / meaning |
|
||||
| --- | --- |
|
||||
| `format` | Exactly `"beffroi.midra-layout"` |
|
||||
| `version` | Integer `5` |
|
||||
| `version` | Integer `6` |
|
||||
| `next_layer_id` | Positive integer strictly greater than every layer ID; not rewound by undo |
|
||||
| `output_resolution` | `{ "width": integer, "height": integer }`, screen pixels |
|
||||
| `inputs` | 1–1024 input objects, consecutive IDs starting at 1 |
|
||||
|
|
@ -93,7 +93,7 @@ Editor object:
|
|||
| Field | Representation / meaning |
|
||||
| --- | --- |
|
||||
| `selected_layer_ids` | Array of unique IDs of visible, unlocked layers; may be empty |
|
||||
| `position_corner` | `"top_left"`, `"top_right"`, `"bottom_left"`, `"bottom_right"` |
|
||||
| `position_point` | `"top_left"`, `"top_right"`, `"bottom_left"`, `"bottom_right"`, `"center"` |
|
||||
| `keep_aspect_ratio` | Boolean for layer resizing |
|
||||
| `viewport_zoom` | Positive fit-relative scale, 0.0001–256 |
|
||||
| `viewport_pan` | `[x, y]`, viewport pan in screen-coordinate pixels; finite, absolute value at most 1e9 |
|
||||
|
|
@ -101,6 +101,8 @@ Editor object:
|
|||
| `show_toolbar_icon_names` | Boolean: show names beneath toolbar icons; false by default |
|
||||
| `outline_layers` | Boolean: transparent layer fill for reference alignment; selection/handles remain visible |
|
||||
|
||||
Position offsets use matching layer/screen points. Corners measure inward from their screen edges. Center measures layer center minus screen center in pixels (positive right/down); resizing preserves those offsets. Changing the reference alone never moves a layer. Stored bounds remain top-left coordinates.
|
||||
|
||||
Resolution dimensions must be whole pixels from 1 to 16384. Layer x/y must be finite and within ±1,000,000 pixels; layer widths/heights
|
||||
and retained input dimensions must be positive, finite, and at most 1,000,000
|
||||
pixels. Crop edges must be finite and nonnegative, with a positive retained
|
||||
|
|
@ -131,7 +133,7 @@ layer); rectangles retain stable IDs and document stacking order. Names/folders
|
|||
are not added to the geometry SVG format.
|
||||
|
||||
Reordering changes only the order of the existing `layers` array, not IDs or
|
||||
per-layer values. Project v5 and SVG v1 remain unchanged. Moving layer 1 below
|
||||
per-layer values. Reordering uses the existing array order; SVG remains v1. Moving layer 1 below
|
||||
layer 2 saves IDs in `[2, 1]` order and emits `layer-2` before `layer-1` in SVG.
|
||||
Loading preserves that order; selected-layer exports still follow document order,
|
||||
not selection order. Source slots, `next_layer_id`, names, folders, crop geometry,
|
||||
|
|
@ -175,7 +177,7 @@ and `viewBox="0 0 W H"` equal to the output screen. The root carries
|
|||
|
||||
## Compatibility changes
|
||||
|
||||
Project version 5 and SVG version 1 are strict contracts. A breaking project field/meaning change must bump
|
||||
Project version 6 and SVG version 1 are strict contracts. A breaking project field/meaning change must bump
|
||||
`version` and either implement a tested migration or clearly reject older/newer
|
||||
files. Changing rectangle/marker semantics requires a corresponding documented
|
||||
SVG interface revision and importer tests. Update this document and its example
|
||||
|
|
|
|||
|
|
@ -124,10 +124,10 @@ clipboard testing against a running draw.io instance remains to be done.
|
|||
deltas and preserves fractional starting positions, sizes and relative spacing.
|
||||
Drag a corner handle to resize that layer, or use the single-layer numeric fields.
|
||||
- Arrow keys move the selection by **1 px**; Shift-arrow moves it by **10 px**.
|
||||
- Choose one of the four corner markers. Switching corner changes the displayed
|
||||
- Under **Measure position from**, choose a corner or the center marker. Center offsets measure layer center from screen center (positive right/down); zero centers the layer. Switching reference changes the displayed
|
||||
offsets without moving the layer. Position and size edits apply when you leave
|
||||
a field or press Enter; **Apply position / size** is also available. Resizing preserves that
|
||||
corner's offsets. Invalid values leave the document unchanged.
|
||||
reference point's offsets. Invalid values leave the document unchanged.
|
||||
- **Escape** cancels a drag or restores uncommitted numeric fields. In the paste
|
||||
dialog it asks whether to Apply or Discard detected values. Group drags cancel atomically.
|
||||
- The history toolbar icons (**Undo/Redo**) or Ctrl/Cmd-Z, Ctrl/Cmd-Shift-Z (also Ctrl/Cmd-Y) reverse
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
## Unreleased
|
||||
|
||||
- Add center to “Measure position from”; numeric resizing preserves center offsets. Project v6 saves the reference and migrates v1–5 corners.
|
||||
|
||||
- Rename Preferences to Settings; menu actions now read “Open all settings…”.
|
||||
|
||||
- Shift-drag moves/resizes on a 10 px grid; Ctrl+Shift uses 100 px, Alt bypasses. Replaces resize snap inversion; Shift-click and empty-canvas additive selection remain.
|
||||
|
|
|
|||
Loading…
Reference in New Issue