Make example backdrop title editable and save it with projects

This commit is contained in:
Dandaedre 2026-11-14 12:30:22 +01:00
parent 35f6ac6165
commit e8dfdb03ef
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
11 changed files with 259 additions and 17 deletions

View File

@ -76,6 +76,7 @@ pub struct Editor {
reference_pending:
Option<std::sync::mpsc::Receiver<Result<super::reference::Reference, String>>>,
outline_layers: bool,
backdrop_title: String,
reference_open: bool,
reference_error: String,
}
@ -285,6 +286,7 @@ impl Default for Editor {
reference: None,
reference_pending: None,
outline_layers: false,
backdrop_title: midra_layout::project::DEFAULT_BACKDROP_TITLE.into(),
reference_open: false,
reference_error: String::new(),
};
@ -2566,7 +2568,7 @@ impl Editor {
output,
);
} else if output == [1920, 1080] {
screen_artwork(&screen);
screen_artwork(&screen, &self.backdrop_title);
} else {
let rect = Rect::from_min_size(origin, Vec2::new(sw, sh) * scale);
screen.painter.rect_filled(rect, 0.0, palette.canvas);
@ -2588,6 +2590,9 @@ impl Editor {
);
}
}
if self.reference.is_none() && output != [1920, 1080] {
screen_title(&screen, &self.backdrop_title, output);
}
if self.edit_content
&& let Some(i) = self.layout.selected()
{
@ -3638,6 +3643,33 @@ mod tests {
);
frame(app, ctx, vec![mouse(pos, false)]);
}
#[test]
fn example_title_renders_custom_and_blank_text_at_different_output_sizes() {
for output in [[1920, 1080], [1280, 720]] {
let ctx = egui::Context::default();
let mut app = Editor::default();
app.layout.set_output(output).unwrap();
let contains = |frame: &egui::FullOutput, text: &str| {
frame
.shapes
.iter()
.any(|s| matches!(&s.shape, egui::Shape::Text(t) if t.galley.text() == text))
};
assert!(contains(
&frame(&mut app, &ctx, vec![]),
"Example Conference Name"
));
let before = app.layout.layers().clone();
app.backdrop_title = "My conference".into();
let custom = frame(&mut app, &ctx, vec![]);
assert!(contains(&custom, "My conference"));
assert!(!contains(&custom, "Example Conference Name"));
app.backdrop_title.clear();
assert!(!contains(&frame(&mut app, &ctx, vec![]), "My conference"));
assert_eq!(app.layout.layers(), &before);
}
}
#[test]
fn navigation_icons_are_exclusive_and_keep_grid_pivot_choices() {
let ctx = egui::Context::default();

View File

@ -119,13 +119,12 @@ impl Ink {
}
}
fn screen_artwork(ink: &Ink) {
fn screen_artwork(ink: &Ink, title: &str) {
let palette = theme::palette(ink.painter.ctx());
ink.text(0.0, -24.0, "SCREEN 1", 12.0, palette.muted);
ink.text(790.0, -24.0, "1920 × 1080 px", 13.0, palette.muted);
ink.rect(0.0, 0.0, 960.0, 540.0, palette.canvas);
ink.rect(0.0, 0.0, 960.0, 36.0, palette.banner);
ink.text(24.0, 10.0, "ANNUAL FORUM / MAIN STAGE", 13.0, palette.muted);
screen_title(ink, title, [1920, 1080]);
for x in (0..=1920).step_by(240) {
ink.line(
[x as f32 / 2.0, 36.0],
@ -145,3 +144,19 @@ fn screen_artwork(ink: &Ink) {
palette.muted,
);
}
fn screen_title(ink: &Ink, title: &str, output: [u32; 2]) {
let palette = theme::palette(ink.painter.ctx());
let width = output[0] as f32 / 2.0;
let height = (output[1] as f32 / 2.0).min(36.0);
let rect = Rect::from_min_max(ink.point(0.0, 0.0), ink.point(width, height));
let banner = Ink {
painter: ink
.painter
.with_clip_rect(ink.painter.clip_rect().intersect(rect)),
origin: ink.origin,
scale: ink.scale,
};
banner.rect(0.0, 0.0, width, height, palette.banner);
banner.text(24.0, 10.0, title, 13.0, palette.muted);
}

View File

@ -101,6 +101,26 @@ impl Editor {
}
});
}
pub(super) fn backdrop_options(&mut self, ui: &mut egui::Ui) {
ui.label("Example backdrop title (saved in project)");
if ui
.add(
egui::TextEdit::singleline(&mut self.backdrop_title)
.char_limit(128)
.desired_width(260.0),
)
.changed()
{
self.backdrop_title.retain(|c| !c.is_control());
}
ui.small("Updates immediately. Leave blank to hide the title.");
if ui.button("Reset example title").clicked() {
self.backdrop_title = midra_layout::project::DEFAULT_BACKDROP_TITLE.into();
}
if self.reference.is_some() {
ui.weak("The reference image replaces this example backdrop.");
}
}
pub(super) fn viewport_options_menu(&mut self, ui: &mut egui::Ui) {
if ui.button("Open all settings…").clicked() {
self.preferences_open = true;
@ -108,6 +128,7 @@ impl Editor {
}
ui.separator();
self.snapping_menu(ui);
ui.menu_button("Example backdrop", |ui| self.backdrop_options(ui));
let before = self.application_settings(ui.ctx());
let current = theme::Theme::current(ui.ctx());
ui.menu_button(format!("Theme: {}", current.name()), |ui| {

View File

@ -75,6 +75,8 @@ impl Editor {
}
Section::Reference => {
ui.heading("Reference images");
self.backdrop_options(ui);
ui.separator();
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); }

View File

@ -11,6 +11,7 @@ use std::{
};
pub const MAX_PROJECT_BYTES: u64 = 96 * 1024 * 1024;
pub const DEFAULT_BACKDROP_TITLE: &str = "Example Conference Name";
pub const FORMAT: &str = "beffroi.midra-layout";
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
@ -88,6 +89,7 @@ impl Reference {
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct EditorSettings {
pub backdrop_title: String,
pub selected_layer_ids: Vec<usize>,
pub position_point: PositionPoint,
pub keep_aspect_ratio: bool,
@ -113,7 +115,7 @@ impl Project {
pub fn from_layout(layout: &Layout) -> Self {
Self {
format: FORMAT.into(),
version: 6,
version: 7,
next_layer_id: layout.next_id,
output_resolution: layout.formats.output.into(),
inputs: (0..layout.formats.sources.len())
@ -142,6 +144,7 @@ impl Project {
.collect(),
reference: None,
editor: EditorSettings {
backdrop_title: DEFAULT_BACKDROP_TITLE.into(),
selected_layer_ids: layout
.selected_indices()
.into_iter()
@ -159,12 +162,17 @@ 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 != 6 {
if self.format != FORMAT || self.version != 7 {
return Err(
"Unsupported project format/version; expected beffroi.midra-layout version 6."
"Unsupported project format/version; expected beffroi.midra-layout version 7."
.into(),
);
}
if self.editor.backdrop_title.chars().count() > 128
|| self.editor.backdrop_title.chars().any(char::is_control)
{
return Err("Backdrop title must be a single line of at most 128 characters.".into());
}
let output = [self.output_resolution.width, self.output_resolution.height];
formats::validate_resolution(output)?;
let mut layout = Layout::default();
@ -282,8 +290,8 @@ 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());
if !(1..=7).contains(&header.version) {
return Err("Unsupported project version; expected versions 1–7.".into());
}
let mut migrated: serde_json::Value = if header.version == 1 || header.version == 2 {
let mut value: serde_json::Value =
@ -377,6 +385,16 @@ impl Project {
editor.insert("position_point".into(), corner);
migrated["version"] = 6.into();
}
if (1..=6).contains(&header.version) {
let editor = migrated["editor"]
.as_object_mut()
.ok_or("Missing editor settings")?;
if editor.contains_key("backdrop_title") {
return Err("Unexpected backdrop title in old project".into());
}
editor.insert("backdrop_title".into(), DEFAULT_BACKDROP_TITLE.into());
migrated["version"] = 7.into();
}
let p: Self =
serde_json::from_value(migrated).map_err(|e| format!("Invalid project JSON: {e}"))?;
p.layout()?;

View File

@ -13,6 +13,7 @@ impl Editor {
fn project(&self) -> Project {
let mut p = Project::from_layout(&self.layout);
p.editor.position_point = self.corner;
p.editor.backdrop_title = self.backdrop_title.clone();
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];
@ -69,6 +70,7 @@ impl Editor {
layout,
reference,
corner: e.position_point,
backdrop_title: e.backdrop_title,
keep_aspect_ratio: e.keep_aspect_ratio,
zoom: e.viewport_zoom,
pan: Vec2::from(e.viewport_pan),
@ -343,6 +345,7 @@ mod tests {
app.zoom = 2.5;
app.pan = Vec2::new(-20.5, 40.0);
app.corner = PositionPoint::Center;
app.backdrop_title = "Conference 2027 · Main stage".into();
app.keep_aspect_ratio = false;
app.show_pattern = true;
app.show_toolbar_icon_names = true;

View File

@ -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, 6);
assert_eq!(p.version, 7);
assert!(p.layers.iter().all(|l| l.midra_link.is_none()));
}
let mut value = serde_json::to_value(&project).unwrap();
@ -302,7 +302,7 @@ fn position_point_schema_migrates_corners_and_rejects_mislabeled_files() {
.unwrap();
old["editor"]["position_corner"] = name.into();
let loaded = Project::from_json(&old.to_string()).unwrap();
assert_eq!(loaded.version, 6);
assert_eq!(loaded.version, 7);
assert_eq!(loaded.editor.position_point, expected);
old["editor"]["position_corner"] = "center".into();
assert!(Project::from_json(&old.to_string()).is_err());
@ -311,7 +311,7 @@ fn position_point_schema_migrates_corners_and_rejects_mislabeled_files() {
assert!(Project::from_json(&old.to_string()).is_err());
}
let value: serde_json::Value = serde_json::from_str(&current.to_json().unwrap()).unwrap();
for version in [0, 7] {
for version in [0, 8] {
let mut invalid = value.clone();
invalid["version"] = version.into();
assert!(
@ -329,3 +329,44 @@ fn position_point_schema_migrates_corners_and_rejects_mislabeled_files() {
invalid["editor"]["position_corner"] = "top_left".into();
assert!(Project::from_json(&invalid.to_string()).is_err());
}
#[test]
fn backdrop_title_roundtrips_and_older_projects_gain_the_default() {
use midra_layout::project::DEFAULT_BACKDROP_TITLE;
let current = Project::from_json(include_str!(
"../../../docs/interfaces/midra-layout-v7.example.json"
))
.unwrap();
assert_eq!(current, Project::from_layout(&Layout::default()));
for text in ["", "Conférence · Main stage", &"é".repeat(128)] {
let mut project = current.clone();
project.editor.backdrop_title = text.into();
assert_eq!(
Project::from_json(&project.to_json().unwrap()).unwrap(),
project
);
assert_eq!(
project.to_svg(false).unwrap(),
current.to_svg(false).unwrap()
);
}
let old = include_str!("../../../docs/interfaces/midra-layout-v6.example.json");
let migrated = Project::from_json(old).unwrap();
assert_eq!(migrated.version, 7);
assert_eq!(migrated.editor.backdrop_title, DEFAULT_BACKDROP_TITLE);
let mut invalid: serde_json::Value = serde_json::from_str(old).unwrap();
invalid["editor"]["backdrop_title"] = "Unexpected".into();
assert!(Project::from_json(&invalid.to_string()).is_err());
let value: serde_json::Value = serde_json::from_str(&current.to_json().unwrap()).unwrap();
for title in ["a".repeat(129), "line\nbreak".into(), "tab\there".into()] {
let mut invalid = value.clone();
invalid["editor"]["backdrop_title"] = title.into();
assert!(Project::from_json(&invalid.to_string()).is_err());
}
let mut missing = value;
missing["editor"]
.as_object_mut()
.unwrap()
.remove("backdrop_title");
assert!(Project::from_json(&missing.to_string()).is_err());
}

View File

@ -0,0 +1,100 @@
{
"format": "beffroi.midra-layout",
"version": 7,
"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": {
"backdrop_title": "Example Conference Name",
"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
}

View File

@ -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 6
## Project JSON, version 7
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. 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.
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. Version 7 adds `editor.backdrop_title`; versions 1–6 gain `"Example Conference Name"` and cannot supply this field under the old schema. Saving always writes version 7; older applications reject it.
Incompatible files are never partially applied.
[Complete example](midra-layout-v6.example.json) is a valid default project,
[Complete example](midra-layout-v7.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 `6` |
| `version` | Integer `7` |
| `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,6 +93,7 @@ Editor object:
| Field | Representation / meaning |
| --- | --- |
| `selected_layer_ids` | Array of unique IDs of visible, unlocked layers; may be empty |
| `backdrop_title` | Required string, 0–128 Unicode characters, no control characters. Example backdrop title; empty hides the text. Preserved exactly, including spaces; omitted from SVG/device output. |
| `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 |
@ -177,7 +178,7 @@ and `viewBox="0 0 W H"` equal to the output screen. The root carries
## Compatibility changes
Project version 6 and SVG version 1 are strict contracts. A breaking project field/meaning change must bump
Project version 7 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

View File

@ -218,6 +218,13 @@ The document currently has two local rectangles and two source identities.
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 example backdrop is titled **Example Conference Name** by default. Edit it
under **Options → Example backdrop** or **Settings → Reference images**. Changes
appear immediately and save with the project; leave it blank to hide the text,
or use **Reset example title**. Up to 128 single-line characters are allowed.
The title is clipped to the banner and appears only without an imported reference
image, at any output resolution. It is not exported to SVG or sent to Midra.
The initial backdrop is illustrative; importing a reference picture replaces it.
Live video and verified hardware container/crop conversion remain future work.
Project JSON save/load and SVG geometry export are implemented (see below).

View File

@ -4,6 +4,8 @@
## Unreleased
- Default backdrop title is “Example Conference Name”; edit/reset it in Options → Example backdrop or Settings → Reference images. Project v7 saves the title and migrates v1–6.
- Add persistent Move/Pan/Zoom icons (V/H/Z). Zoom supports click, Alt-click out and horizontal drag; Space/middle-drag pans from any tool. Escape cancels camera drags; grid/pivot choices stay independent.
- Layer lists now show the topmost layer first; drag/drop and arrows match. Selection no longer raises layers temporarily. Saved project/SVG stacking stays compatible.