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
@@ -153,6 +153,29 @@ fn saved_workspace_is_listed_in_the_workspace_menu() {
|
||||
assert_eq!(h.state().ui.dock, saved, "its layout came back");
|
||||
}
|
||||
|
||||
/// Edit ▸ Label shows each label's colour before its name (#290), and choosing one labels the
|
||||
/// selected layer.
|
||||
#[test]
|
||||
fn edit_label_menu_shows_the_label_colours() {
|
||||
let mut h = harness();
|
||||
click(&mut h, "menu.Edit");
|
||||
let label = h.query_by_label(" Label ⏵").expect("Edit ▸ Label").rect();
|
||||
hover(&mut h, label.center());
|
||||
// (Not Dark Green; the entry's label starts with its check-mark column.)
|
||||
let green = h.query_by_label(" Green").expect("the Label submenu is open").rect();
|
||||
let col = h.state().tokens.label(effectcraft_engine::color::Label::Green);
|
||||
let swatch = |s: &egui::Shape| matches!(s, egui::Shape::Rect(r) if r.fill == col && r.rect.width() < 16.0 && green.contains(r.rect.center()));
|
||||
let shapes: Vec<egui::Shape> = h.output().shapes.iter().map(|c| c.shape.clone()).collect();
|
||||
assert!(shapes.iter().any(|s| swatch(s) || matches!(s, egui::Shape::Vec(v) if v.iter().any(swatch))), "no Green swatch");
|
||||
// Into the submenu, then down to Green.
|
||||
hover(&mut h, pos2(green.center().x, label.center().y));
|
||||
for k in 1..=10 {
|
||||
hover(&mut h, pos2(green.center().x, label.center().y + (green.center().y - label.center().y) * k as f32 / 10.0));
|
||||
}
|
||||
click_at(&mut h, green.center());
|
||||
assert_eq!(h.state().session.active_comp().unwrap().layers[0].label, effectcraft_engine::color::Label::Green);
|
||||
}
|
||||
|
||||
/// Learn opens the Home screen's tutorials; clicking another workspace tab closes them again,
|
||||
/// however quickly the tabs are clicked (they stayed over every workspace, #272).
|
||||
#[test]
|
||||
|
||||
@@ -5,7 +5,7 @@ use effectcraft_engine::Session;
|
||||
use effectcraft_engine::color::Label;
|
||||
use effectcraft_engine::project::{ItemId, ItemKind};
|
||||
use effectcraft_ui_egui::EffectcraftApp;
|
||||
use egui::{Event, Modifiers, Pos2, pos2};
|
||||
use egui::{Color32, Event, Modifiers, Pos2, Rect, pos2};
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::Queryable;
|
||||
use serde_json::json;
|
||||
@@ -80,6 +80,18 @@ fn folder_twirl_opens_and_closes_the_folder_on_one_click() {
|
||||
assert!(h.state().ui.project_open_folders.contains(&folder.0), "a double-click on the row opens the folder");
|
||||
}
|
||||
|
||||
/// A swatch (a small rect filled with `col`) painted this frame in the left half of `row`.
|
||||
fn swatch_in(h: &Harness<'_, EffectcraftApp>, row: Rect, col: Color32) -> bool {
|
||||
fn walk(s: &egui::Shape, row: Rect, col: Color32) -> bool {
|
||||
match s {
|
||||
egui::Shape::Rect(r) => r.fill == col && r.rect.width() < 16.0 && row.contains(r.rect.center()) && r.rect.center().x < row.center().x,
|
||||
egui::Shape::Vec(v) => v.iter().any(|s| walk(s, row, col)),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
h.output().shapes.iter().any(|c| walk(&c.shape, row, col))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn label_swatch_opens_the_label_menu() {
|
||||
let (mut h, _, _, solid) = harness();
|
||||
@@ -89,6 +101,8 @@ fn label_swatch_opens_the_label_menu() {
|
||||
click(&mut h, &format!("project.item.{}.label", solid.0));
|
||||
assert!(h.state().session.state.project_selection.is_empty(), "the swatch does not select the row");
|
||||
let entry = h.query_by_label(&green).expect("the label menu is open").rect();
|
||||
// Each entry shows its colour before its name (#290).
|
||||
assert!(swatch_in(&h, entry, h.state().tokens.label(Label::Green)), "no {green} swatch");
|
||||
let undo = h.state().session.history.undo.len();
|
||||
click_at(&mut h, entry.center());
|
||||
assert_eq!(h.state().session.project.item(solid).unwrap().label, Label::Green);
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
//! Timeline layer switches with real pointer input (egui_kittest): pressing a switch and
|
||||
//! dragging over other layers gives them all the state the first one got, in one undo step, as
|
||||
//! in After Effects (#227); stopwatches the same way (#284). Also the layer bar past its source
|
||||
//! (#290).
|
||||
//! in After Effects (#227); stopwatches the same way (#284). Also the label swatch's menu and the
|
||||
//! layer bar past its source (#290).
|
||||
|
||||
use effectcraft_engine::Session;
|
||||
use effectcraft_engine::color::Label;
|
||||
use effectcraft_engine::project::LayerId;
|
||||
use effectcraft_ui_egui::EffectcraftApp;
|
||||
use egui::{Event, Modifiers, Pos2, Rect, pos2, vec2};
|
||||
use egui::{Color32, Event, Modifiers, Pos2, Rect, pos2, vec2};
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::Queryable;
|
||||
use serde_json::json;
|
||||
|
||||
/// Comp "Main" with solids A (top) to D (bottom); returns their ids top to bottom.
|
||||
@@ -146,6 +148,38 @@ fn dragging_over_stopwatches_sets_them_all() {
|
||||
assert_eq!(animated(&h), [true; 5], "each drag was one step");
|
||||
}
|
||||
|
||||
/// A swatch (a small rect filled with `col`) painted this frame in the left half of `row`.
|
||||
fn swatch_in(h: &Harness<'_, EffectcraftApp>, row: Rect, col: Color32) -> bool {
|
||||
fn walk(s: &egui::Shape, row: Rect, col: Color32) -> bool {
|
||||
match s {
|
||||
egui::Shape::Rect(r) => r.fill == col && r.rect.width() < 16.0 && row.contains(r.rect.center()) && r.rect.center().x < row.center().x,
|
||||
egui::Shape::Vec(v) => v.iter().any(|s| walk(s, row, col)),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
h.output().shapes.iter().any(|c| walk(&c.shape, row, col))
|
||||
}
|
||||
|
||||
/// Clicking a layer's label swatch opens the label menu, which shows each label's colour before
|
||||
/// its name, so a label is picked by its colour (#290).
|
||||
#[test]
|
||||
fn the_label_swatch_menu_shows_the_label_colours() {
|
||||
let (mut h, ids) = harness();
|
||||
let green = h.state().session.prefs.label_name(Label::Green);
|
||||
let at = rect(&h, &format!("timeline.layer.{}.label", ids[1])).center();
|
||||
drag(&mut h, at, at, 1);
|
||||
let entry = h.query_by_label(&green).expect("the label menu is open").rect();
|
||||
for l in [Label::Green, Label::SeaFoam, Label::Purple] {
|
||||
let e = h.query_by_label(&h.state().session.prefs.label_name(l)).unwrap().rect();
|
||||
assert!(swatch_in(&h, e, h.state().tokens.label(l)), "no {l:?} swatch");
|
||||
}
|
||||
let undo = h.state().session.history.undo.len();
|
||||
drag(&mut h, entry.center(), entry.center(), 1);
|
||||
assert_eq!(h.state().session.active_comp().unwrap().layer(LayerId(ids[1])).unwrap().label, Label::Green);
|
||||
assert_eq!(h.state().session.history.undo.len(), undo + 1);
|
||||
assert!(h.query_by_label(&green).is_none(), "the menu closed after the choice");
|
||||
}
|
||||
|
||||
/// A layer extended past its source's end (its last frame held) has that part of its bar
|
||||
/// striped, so the source's own span shows (#290); with time remapping it isn't.
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user