Skip to content

FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust

Graphics: only selected layers have a box, and a hidden layer has none

justjohn12345b6281f968f8f
diff --git a/crates/ui-egui/src/panels/graphics.rs b/crates/ui-egui/src/panels/graphics.rs
index f405bba75..3e044c1e2 100644
--- a/crates/ui-egui/src/panels/graphics.rs
+++ b/crates/ui-egui/src/panels/graphics.rs
@@ -85,7 +85,8 @@ pub fn selected_graphic(app: &FilmcraftApp) -> Option<(ClipId, TrackItem)> {
app.session.state.selection.iter().copied().find(|c| is_graphic_clip(app, *c)).and_then(|c| q.find_item(c).map(|(_, it)| (c, it.clone())))
}
-/// Layers of the graphic clips visible at the playhead, front-most first.
+/// Layers of the graphic clips visible at the playhead, front-most first. A layer whose
+/// visibility is off is not in the picture, so it has no box and cannot be clicked either.
pub fn visible_layers(app: &FilmcraftApp, pic: Rect, frame: (u32, u32)) -> Vec<LayerView> {
let Some(seq) = app.session.active_sequence() else { return Vec::new() };
let t = app.session.playhead();
@@ -106,7 +107,7 @@ pub fn visible_layers(app: &FilmcraftApp, pic: Rect, frame: (u32, u32)) -> Vec<L
let base = screen.then_apply(&filmcraft_render::motion_matrix(seq, it, size, mt));
let idx = layer_indices(&it.effects);
for (li, &ei) in idx.iter().enumerate().rev() {
- if let Some(spec) = eval_layer(&it.effects[ei], mt, size) {
+ if let Some(spec) = eval_layer(&it.effects[ei], mt, size).filter(|s| s.enabled) {
let local = layer_local_bounds(&spec);
out.push(LayerView { clip: it.id, layer: li, to_screen: base.then_apply(&layer_matrix(&spec)), canvas_to_screen: base, spec, local });
}
@@ -405,15 +406,11 @@ pub fn monitor_overlay(app: &mut FilmcraftApp, ui: &mut egui::Ui, pic: Rect, fra
let q = v.quad();
let selected = sel_layers.contains(&v.layer);
let is_edit = editing.as_ref().is_some_and(|e| e.clip == v.clip.0 && e.layer == v.layer);
- // the box of the text being typed into is red, as in Premiere
- let col = if is_edit {
- t.danger
- } else if selected {
- accent
- } else {
- Color32::from_white_alpha(70)
- };
- painter.add(egui::Shape::closed_line(q.to_vec(), Stroke::new(1.0, col)));
+ // only the selected layers have a box; that of the text being typed into is red, as in Premiere
+ if !(selected || is_edit) {
+ continue;
+ }
+ painter.add(egui::Shape::closed_line(q.to_vec(), Stroke::new(1.0, if is_edit { t.danger } else { accent })));
if selected && !is_edit {
let paragraph = text_of(&v.spec).filter(|tp| is_paragraph(tp));
let label = if paragraph.is_some() { "resize handle" } else { "scale handle" };
diff --git a/crates/ui-egui/tests/graphics_handles_ui.rs b/crates/ui-egui/tests/graphics_handles_ui.rs
index 957bda097..538798521 100644
--- a/crates/ui-egui/tests/graphics_handles_ui.rs
+++ b/crates/ui-egui/tests/graphics_handles_ui.rs
@@ -395,3 +395,35 @@ fn shape_edge_handles_stretch_one_axis() {
assert!(near(bl, bl2), "bottom edge stays put: {bl:?} -> {bl2:?}");
assert!((top2.1 - top.1 + 30.0).abs() < 2.0, "top follows the pointer: {top:?} -> {top2:?}");
}
+
+#[test]
+fn a_hidden_layer_has_no_box_and_cannot_be_clicked() {
+ let mut d = Driver::new();
+ let pre = d.shape();
+ let clip: u64 = pre.split('.').nth(2).unwrap().parse().unwrap();
+ let layer = format!("program.layer.{clip}.0");
+ let ids = |d: &mut Driver| -> Vec<String> {
+ let v = d.ok("ui.elements", json!({"prefix": layer}));
+ v.as_array().unwrap().iter().map(|e| e["id"].as_str().unwrap().to_string()).collect()
+ };
+ assert_eq!(ids(&mut d).len(), 10, "the layer, its eight handles and its anchor: {:?}", ids(&mut d));
+ let r = d.rect(&layer);
+ let inside = (r[0] + r[2] / 4.0, r[1] + r[3] / 2.0);
+
+ // visibility off: still selected in the panel, but nothing of it is on the monitor
+ d.exec("graphics.set", json!({"clip": clip, "props": {"enabled": false}}));
+ d.frames(4);
+ assert_eq!(ids(&mut d), Vec::<String>::new());
+ d.exec("graphics.selectLayer", json!({"clip": clip, "layers": []}));
+ d.ok("ui.click", json!({"x": inside.0, "y": inside.1}));
+ d.frames(4);
+
+ // visibility on: the click where it was selected nothing, so it has no handles; now it can be clicked
+ d.exec("graphics.set", json!({"clip": clip, "layer": 0, "props": {"enabled": true}}));
+ d.frames(4);
+ assert_eq!(ids(&mut d), vec![layer.clone()], "not selected: no handles");
+ // (elsewhere on it, so that the two clicks are not a double click)
+ d.ok("ui.click", json!({"x": r[0] + r[2] * 0.75, "y": inside.1}));
+ d.frames(4);
+ assert_eq!(ids(&mut d).len(), 10);
+}
diff --git a/docs/graphics.md b/docs/graphics.md
index e5ebefe84..6d935e82c 100644
--- a/docs/graphics.md
+++ b/docs/graphics.md
@@ -116,7 +116,7 @@ duration (a track is added if needed).
| Tool | On the Program monitor |
|---|---|
| Type (T) | Click empty picture: new point-text layer with a caret. Drag on empty picture: new paragraph-text layer with that box. Click a text layer: caret there. The box of the text being typed into is red. Type; ←/→ (⌥ word, ⌘ line), ↑/↓, Home/End, Shift to select, ⌘A, ⌘C/⌘X/⌘V, Return = new line, Backspace/Delete, Esc = stop editing. Drag inside the edited text to select. |
-| Selection (V) | Click a layer to select it (box with handles and anchor point); drag to move; drag the anchor point to move it alone; drag a handle to scale point text about its anchor, resize a paragraph-text box, or stretch a shape away from its opposite side (see *Point text and paragraph text*); double-click a text layer to edit it. |
+| Selection (V) | Click a layer to select it (box with handles and anchor point; only selected layers have a box, and a layer whose visibility is off has none and cannot be clicked); drag to move; drag the anchor point to move it alone; drag a handle to scale point text about its anchor, resize a paragraph-text box, or stretch a shape away from its opposite side (see *Point text and paragraph text*); double-click a text layer to edit it. |
| Rectangle / Ellipse | Drag to draw a shape layer. |
| Pen (P) | Click to place points; click the first point (or Return) to close the path; Esc cancels. |