FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
#786: right-click Label menus show the label colours
vangel7650560a8364d5
diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rsindex 1cca0b691..6c0910b2b 100644--- a/crates/ui-egui/src/menus.rs+++ b/crates/ui-egui/src/menus.rs@@ -847,8 +847,38 @@ fn menu_level(/// Only Edit ▸ Label choices get a swatch. Other commands keep their usual menu layout.fn label_menu_swatch(id: &str, labels: &filmcraft_engine::settings::LabelPrefs) -> Option<egui::Color32> {let label = id.strip_prefix("edit.label.").and_then(filmcraft_project::Label::from_name)?;- let [r, g, b] = labels.rgb(label);- Some(egui::Color32::from_rgb(r, g, b))+ Some(label_color(labels, label))+}++/// The user's colour for label `l` (Preferences ▸ Labels), else the built-in one.+pub fn label_color(labels: &filmcraft_engine::settings::LabelPrefs, l: filmcraft_project::Label) -> egui::Color32 {+ let [r, g, b] = labels.rgb(l);+ egui::Color32::from_rgb(r, g, b)+}++/// A label choice in a right-click Label menu (Project panel items, Timeline clips; #786), drawn+/// as Edit ▸ Label draws it: the user's name for the label with a swatch of its colour in the+/// left gutter. Registered for automation as `<prefix>.<Label>` (the label's built-in name).+pub fn label_choice(+ ui: &mut egui::Ui,+ auto: &mut crate::automation::Registry,+ labels: &filmcraft_engine::settings::LabelPrefs,+ l: filmcraft_project::Label,+ prefix: &str,+) -> egui::Response {+ let name = labels.name(l);+ let text = crate::i18n::t(&name);+ let r = ui.button(format!(" {text}"));+ auto.add(&format!("{prefix}.{}", l.name()), r.rect, text);+ paint_swatch(ui, r.rect, label_color(labels, l));+ r+}++/// A label swatch in the left gutter of the menu row `row`.+fn paint_swatch(ui: &egui::Ui, row: egui::Rect, color: egui::Color32) {+ let rect = egui::Rect::from_center_size(row.left_center() + egui::vec2(10.0, 0.0), egui::vec2(12.0, 12.0));+ ui.painter().rect_filled(rect, 2.0, color);+ ui.painter().rect_stroke(rect, 2.0, egui::Stroke::new(1.0, ui.visuals().widgets.inactive.bg_stroke.color), egui::StrokeKind::Inside);}fn menu_entry(ui: &mut egui::Ui, it: &MenuItem, auto: &mut crate::automation::Registry, labels: &filmcraft_engine::settings::LabelPrefs) -> bool {@@ -862,9 +892,7 @@ fn menu_entry(ui: &mut egui::Ui, it: &MenuItem, auto: &mut crate::automation::Relet r = ui.add_enabled(it.enabled, b);auto.add(&format!("menu.{}", it.id), r.rect, &it.label);if let Some(color) = swatch {- let rect = egui::Rect::from_center_size(r.rect.left_center() + egui::vec2(10.0, 0.0), egui::vec2(12.0, 12.0));- ui.painter().rect_filled(rect, 2.0, color);- ui.painter().rect_stroke(rect, 2.0, egui::Stroke::new(1.0, ui.visuals().widgets.inactive.bg_stroke.color), egui::StrokeKind::Inside);+ paint_swatch(ui, r.rect, color);}if it.checked == Some(true) {let c = r.rect.left_center() + egui::vec2(10.0, 0.0);diff --git a/crates/ui-egui/src/panels/project_views.rs b/crates/ui-egui/src/panels/project_views.rsindex e48d98dd4..f29bb59b8 100644--- a/crates/ui-egui/src/panels/project_views.rs+++ b/crates/ui-egui/src/panels/project_views.rs@@ -253,15 +253,18 @@ fn item_menu(app: &mut FilmcraftApp, ui: &mut egui::Ui, id: ItemId, kind: &ItemKui.close();}}- ui.menu_button(tl!("Label"), |ui| {+ let r = ui.menu_button(tl!("Label"), |ui| {+ // the user's label names and colours, as in Edit ▸ Label (#786)+ let labels = app.session.prefs.labels.clone();for l in filmcraft_project::Label::ALL {- if ui.button(crate::i18n::t(l.name())).clicked() {+ if crate::menus::label_choice(ui, &mut app.auto, &labels, l, "project.itemMenu.label").clicked() {actions.push(("project.select".into(), json!({"items": [id.0]})));actions.push(("edit.label".into(), json!({"label": l.name()})));ui.close();}}});+ app.auto.add("project.itemMenu.label", r.response.rect, tl!("Label"));if matches!(kind, ItemKind::Media(m) if matches!(m.media, filmcraft_project::MediaRef::File { .. })) {ui.separator();for (label, cmd) in [(tl!("Link Media…"), "media.linkMedia"), (tl!("Make Offline…"), "media.makeOffline")] {diff --git a/crates/ui-egui/src/panels/timeline.rs b/crates/ui-egui/src/panels/timeline.rsindex 70cde2b69..8440aa58a 100644--- a/crates/ui-egui/src/panels/timeline.rs+++ b/crates/ui-egui/src/panels/timeline.rs@@ -2469,14 +2469,17 @@ fn interact(app: &mut FilmcraftApp, ui: &mut egui::Ui, seq: &Sequence, layout: &}for &(label, cmd) in *group {if cmd == "edit.label" {- ui.menu_button(crate::i18n::t(label), |ui| {+ let r = ui.menu_button(crate::i18n::t(label), |ui| {+ // the user's label names and colours, as in Edit ▸ Label (#786)+ let labels = app.session.prefs.labels.clone();for l in filmcraft_project::Label::ALL {- if ui.button(crate::i18n::t(l.name())).clicked() {+ if crate::menus::label_choice(ui, &mut app.auto, &labels, l, "timeline.clipMenu.edit.label").clicked() {let _ = app.session.execute("edit.label", json!({"label": l.name()}));ui.close();}}});+ app.auto.add("timeline.clipMenu.edit.label", r.response.rect, crate::i18n::t(label));continue;}if cmd == "clip.multicam" {diff --git a/crates/ui-egui/tests/clip_dialogs_ui.rs b/crates/ui-egui/tests/clip_dialogs_ui.rsindex b60493718..4589d7b37 100644--- a/crates/ui-egui/tests/clip_dialogs_ui.rs+++ b/crates/ui-egui/tests/clip_dialogs_ui.rs@@ -289,6 +289,24 @@ fn speed_duration_from_the_clip_menu_opens_the_dialog() {assert_eq!(got.time_interpolation, filmcraft_project::TimeInterpolation::FrameBlending);}+/// #786: the clip's right-click Label menu lists the labels by the user's names (with their+/// colours, as Edit ▸ Label does) and each choice labels the clip.+#[test]+fn the_clip_menu_label_choices_use_the_user_names() {+ let mut d = Driver::new();+ let key = filmcraft_engine::settings::label_id(Label::Iris);+ d.app().session.prefs.labels.colors.get_mut(&key).unwrap().name = "Interviews".into();+ let c = d.v1(0);+ d.exec("timeline.select", json!({"clips": [c.id.0]}));+ d.ok("ui.click", json!({"id": format!("timeline.clip.{}", c.id.0), "button": "right"}));+ d.frames(3);+ d.click("timeline.clipMenu.edit.label");+ let choice = d.ok("ui.elements", json!({"prefix": "timeline.clipMenu.edit.label.Iris"}));+ assert_eq!(choice[0]["label"], json!("Interviews"), "{choice}");+ d.click("timeline.clipMenu.edit.label.Iris");+ assert_eq!(d.v1(0).label, Label::Iris);+}+#[test]fn quitting_with_unsaved_changes_asks_to_save() {let mut d = Driver::new();