Labels: label menus show each label's colour (#290)
The label menus listed the labels' names only, so a label couldn't be picked by its colour. Every place a label is chosen now shows its colour swatch before its name, as After Effects does: the Timeline's label swatch (which now opens its menu on a click too, not only a right-click), the Project panel's label swatch and a new Label submenu in its item menu, Edit > Label, keyframe Label menus and the marker dialog. One shared widget (widgets::label_entry / label_popup) draws them; keyframe labels now show the names set in Settings > Labels. Tests: label_swatch_opens_the_label_menu (ui_project_rows), the_label_swatch_menu_shows_the_label_colours (ui_timeline_switches), edit_label_menu_shows_the_label_colours (ui_panels). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
3174652ce4
commit
2f3a507f8e
@@ -190,12 +190,10 @@ pub fn dialog(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) {
|
||||
let labels = effectcraft_engine::color::Label::ALL;
|
||||
let cur = labels.get(d.label).copied().unwrap_or_default();
|
||||
let r = egui::ComboBox::from_id_salt("dialog.marker.label").selected_text(app.session.prefs.label_name(cur)).show_ui(ui, |ui| {
|
||||
for (i, l) in labels.iter().enumerate() {
|
||||
ui.horizontal(|ui| {
|
||||
let (r, _) = ui.allocate_exact_size(vec2(10.0, 10.0), Sense::hover());
|
||||
ui.painter().rect_filled(r, 2.0, app.tokens.label(*l));
|
||||
ui.selectable_value(&mut d.label, i, app.session.prefs.label_name(*l));
|
||||
});
|
||||
for (i, l) in labels.into_iter().enumerate() {
|
||||
if crate::widgets::label_entry(ui, l, &app.session.prefs.label_name(l), d.label == i, &app.tokens).clicked() {
|
||||
d.label = i;
|
||||
}
|
||||
}
|
||||
});
|
||||
app.auto.add("dialog.marker.label", r.response.rect, "Label");
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use effectcraft_engine::color::Label;
|
||||
use effectcraft_engine::project::{Item, ItemId, ItemKind};
|
||||
use egui::{Align2, Color32, Rect, Sense, Stroke, pos2, vec2};
|
||||
use serde_json::json;
|
||||
@@ -485,14 +486,11 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
let sresp = ui.interact(sw.expand(3.0).intersect(list), egui::Id::new(("plabel", id.0)), Sense::click());
|
||||
app.auto.add(&format!("project.item.{}.label", id.0), sw, it.label.name());
|
||||
let pop = egui::Id::new(("plabel-pop", id.0));
|
||||
if sresp.clicked() {
|
||||
if sresp.clicked() || sresp.secondary_clicked() {
|
||||
widgets::open_popup(ui, pop);
|
||||
}
|
||||
let names: Vec<String> = effectcraft_engine::color::Label::ALL.iter().map(|l| app.session.prefs.label_name(*l)).collect();
|
||||
let cur = effectcraft_engine::color::Label::ALL.iter().position(|l| *l == it.label);
|
||||
if let Some(li) = widgets::popup_menu(ui, pop, sw.left_bottom(), &names, cur) {
|
||||
let items: Vec<u64> = if selected { app.session.state.project_selection.iter().map(|i| i.0).collect() } else { vec![id.0] };
|
||||
actions.push(("project.setLabel".into(), json!({"items": items, "label": li})));
|
||||
if let Some(l) = widgets::label_popup(ui, pop, sw.left_bottom(), it.label, |l| app.session.prefs.label_name(l), &t) {
|
||||
actions.push(("project.setLabel".into(), json!({"items": targets(app, *id, selected), "label": label_index(l)})));
|
||||
}
|
||||
// Optional columns.
|
||||
for (key, _, cx, w) in cols.iter().skip(2) {
|
||||
@@ -576,8 +574,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
}
|
||||
resp.context_menu(|ui| {
|
||||
if ui.button("Delete").clicked() {
|
||||
let items: Vec<u64> = if selected { app.session.state.project_selection.iter().map(|i| i.0).collect() } else { vec![id.0] };
|
||||
actions.push(("project.delete".into(), json!({"items": items})));
|
||||
actions.push(("project.delete".into(), json!({"items": targets(app, *id, selected)})));
|
||||
ui.close();
|
||||
}
|
||||
if matches!(it.kind, ItemKind::Comp(_)) && ui.button("Open Composition").clicked() {
|
||||
@@ -604,6 +601,15 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
}
|
||||
ui.close();
|
||||
}
|
||||
ui.separator();
|
||||
ui.menu_button("Label", |ui| {
|
||||
for l in Label::ALL {
|
||||
if widgets::label_entry(ui, l, &app.session.prefs.label_name(l), l == it.label, &t).clicked() {
|
||||
actions.push(("project.setLabel".into(), json!({"items": targets(app, *id, selected), "label": label_index(l)})));
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
// The scroll bars, over the rows (which would take their presses otherwise).
|
||||
@@ -775,6 +781,16 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Items a row's menu acts on: the selection when the row is selected, else the row's item.
|
||||
fn targets(app: &EffectcraftApp, id: ItemId, selected: bool) -> Vec<u64> {
|
||||
if selected { app.session.state.project_selection.iter().map(|i| i.0).collect() } else { vec![id.0] }
|
||||
}
|
||||
|
||||
/// `project.setLabel`'s index of a label.
|
||||
fn label_index(l: Label) -> usize {
|
||||
Label::ALL.iter().position(|x| *x == l).unwrap_or(0)
|
||||
}
|
||||
|
||||
/// The column header's context menu: show or hide the optional columns.
|
||||
fn column_menu(app: &mut EffectcraftApp, resp: &egui::Response) {
|
||||
resp.context_menu(|ui| {
|
||||
|
||||
@@ -1599,15 +1599,14 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
lp.rect_filled(lr, 2.0, t.label(layer.label));
|
||||
let lresp = ui.interact(lr, egui::Id::new(("label", layer.id.0)), Sense::click());
|
||||
app.auto.add(&format!("timeline.layer.{}.label", layer.id.0), lr, layer.label.name());
|
||||
lresp.context_menu(|ui| {
|
||||
for lab in effectcraft_engine::color::Label::ALL {
|
||||
let name = if lab == effectcraft_engine::color::Label::None { lab.name().to_string() } else { app.session.prefs.label_name(lab) };
|
||||
if ui.button(name).clicked() {
|
||||
actions.push(("edit.label".into(), json!({"layers": [layer.id.0], "label": lab.name()})));
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
});
|
||||
// Click (or right-click) the swatch for the label menu (After Effects).
|
||||
let pop = egui::Id::new(("label-pop", layer.id.0));
|
||||
if lresp.clicked() || lresp.secondary_clicked() {
|
||||
widgets::open_popup(ui, pop);
|
||||
}
|
||||
if let Some(lab) = widgets::label_popup(ui, pop, lr.left_bottom(), layer.label, |l| app.session.prefs.label_name(l), &t) {
|
||||
actions.push(("edit.label".into(), json!({"layers": [layer.id.0], "label": lab.name()})));
|
||||
}
|
||||
}
|
||||
if vis.num {
|
||||
lp.text(pos2(cw.num + 13.0, cy), Align2::CENTER_CENTER, format!("{}", idx_of(layer.id)), Tokens::ui(11.5), t.text_dim);
|
||||
@@ -2384,8 +2383,8 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
if lbl == "Select All Keyframes" {
|
||||
// Keyframe colour labels.
|
||||
ui.menu_button("Label", |ui| {
|
||||
for (i, l) in effectcraft_engine::color::Label::ALL.iter().enumerate() {
|
||||
if ui.add(egui::Button::new(l.name()).selected(k.label as usize == i)).clicked() {
|
||||
for (i, l) in effectcraft_engine::color::Label::ALL.into_iter().enumerate() {
|
||||
if widgets::label_entry(ui, l, &app.session.prefs.label_name(l), k.label as usize == i, &t).clicked() {
|
||||
if !ks {
|
||||
actions.push((
|
||||
"keys.select".into(),
|
||||
|
||||
Reference in New Issue
Block a user