FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
UI: UiState::show_header and show_status_bar, on by default
rossaai1e9f37864b57
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rsindex 461aa36ea..736b9ba35 100644--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@ -1235,10 +1235,12 @@ impl FilmcraftApp {let t = self.tokens;let full = ui.max_rect();ui.painter().rect_filled(full, 0.0, t.app_bg);- let header_h = 38.0;+ let header_h = if self.ui.show_header { 38.0 } else { 0.0 };let header = egui::Rect::from_min_size(full.min, egui::vec2(full.width(), header_h));- header::show(self, ui, header);- let status_h = 20.0;+ if self.ui.show_header {+ header::show(self, ui, header);+ }+ let status_h = if self.ui.show_status_bar { 20.0 } else { 0.0 };let body = egui::Rect::from_min_max(egui::pos2(full.min.x + 1.0, header.max.y + 1.0), egui::pos2(full.max.x - 1.0, full.max.y - status_h - 2.0));match self.ui.mode {state::Mode::Edit => self.dock_area(ui, body),@@ -1246,6 +1248,11 @@ impl FilmcraftApp {state::Mode::Export => panels::export_mode::show(self, ui, body),}panels::dialogs::show(self, &ctx);+ if !self.ui.show_status_bar {+ // no bar to draw the job in, but a finished preview render still plays+ self.watch_jobs(ui.ctx());+ return;+ }// Status / hint barlet sb = egui::Rect::from_min_max(egui::pos2(full.min.x, full.max.y - status_h), full.max);ui.painter().rect_filled(sb, 0.0, egui::Color32::from_rgb(0x1c, 0x1c, 0x1c));@@ -1268,9 +1275,9 @@ impl FilmcraftApp {self.job_status(ui, sb, &t);}- /// Right side of the status bar: the running job (export / render previews) with a progress- /// bar and a cancel button; plays the rendered range when a preview render completes.- fn job_status(&mut self, ui: &mut egui::Ui, sb: egui::Rect, t: &Tokens) {+ /// The running job (export / render previews), if any; plays the rendered range when a preview+ /// render completes. Runs every frame, with or without the status bar.+ fn watch_jobs(&mut self, ctx: &egui::Context) -> Option<filmcraft_engine::Job> {use std::sync::atomic::Ordering;let running = self.session.jobs.iter().rev().find(|j| !j.progress.finished.load(Ordering::Relaxed)).cloned();// Play after rendering previews.@@ -1285,12 +1292,20 @@ impl FilmcraftApp {self.play(1.0);}}- let Some(job) = running else { return };+ let job = running?;if job.label.starts_with("Rendering ") && !job.label.contains("audio") && self.watched_render.is_none_or(|w| w.0 != job.id) {let from = self.session.active_sequence().and_then(|q| q.mark_in).unwrap_or(Tick::ZERO);self.watched_render = Some((job.id, from));}- ui.ctx().request_repaint_after(std::time::Duration::from_millis(150));+ ctx.request_repaint_after(std::time::Duration::from_millis(150));+ Some(job)+ }++ /// Right side of the status bar: the running job (export / render previews) with a progress+ /// bar and a cancel button.+ fn job_status(&mut self, ui: &mut egui::Ui, sb: egui::Rect, t: &Tokens) {+ use std::sync::atomic::Ordering;+ let Some(job) = self.watch_jobs(ui.ctx()) else { return };let f = job.progress.fraction().clamp(0.0, 1.0);let left = job.progress.eta().map(panels::left_text).unwrap_or_default();let cancel = egui::Rect::from_center_size(egui::pos2(sb.max.x - 14.0, sb.center().y), egui::vec2(14.0, 14.0));diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rsindex 0bdfcda85..cf5ead127 100644--- a/crates/ui-egui/src/state.rs+++ b/crates/ui-egui/src/state.rs@@ -384,6 +384,12 @@ pub struct UiState {/// Collapsed effect sections in Effect Controls ("clip:index").pub collapsed_fx: Vec<String>,pub show_menu_bar: bool,+ /// The header bar (Home, Import, Edit, Export, workspaces). An app that embeds FilmCraft can hide it.+ #[serde(default = "shown")]+ pub show_header: bool,+ /// The status bar (hints, messages, job progress). An app that embeds FilmCraft can hide it.+ #[serde(default = "shown")]+ pub show_status_bar: bool,pub dark: bool,/// Lumetri scopes visible in the Program monitor area.pub show_scopes: bool,@@ -776,6 +782,10 @@ pub struct GfxEdit {pub anchor: usize,}+fn shown() -> bool {+ true+}+fn captions_tab() -> String {"Captions".into()}@@ -803,6 +813,8 @@ impl Default for UiState {lumetri_grid_folder: None,collapsed_fx: vec![],show_menu_bar: true,+ show_header: true,+ show_status_bar: true,dark: true,show_scopes: false,status: String::new(),diff --git a/crates/ui-egui/tests/chrome_ui.rs b/crates/ui-egui/tests/chrome_ui.rsnew file mode 100644index 000000000..c5efaea0d--- /dev/null+++ b/crates/ui-egui/tests/chrome_ui.rs@@ -0,0 +1,68 @@+//! Headless UI tests of the window chrome flags: `UiState::show_header` and+//! `UiState::show_status_bar` default to on, and an app that embeds FilmCraft can turn them off+//! to give the panels the whole window.++use egui_kittest::Harness;+use filmcraft_engine::Session;+use filmcraft_ui_egui::FilmcraftApp;+use filmcraft_ui_egui::state::UiState;+use serde_json::json;++const W: f32 = 1600.0;+const H: f32 = 980.0;++fn harness(show_header: bool, show_status_bar: bool) -> Harness<'static, FilmcraftApp> {+ let mut s = Session::default();+ s.execute("file.openDemoProject", json!({})).unwrap();+ let mut app = FilmcraftApp::new(s);+ app.ui.show_header = show_header;+ app.ui.show_status_bar = show_status_bar;+ let mut harness = Harness::builder().with_size(egui::vec2(W, H)).with_max_steps(10_000).build_eframe(move |_cc| app);+ for _ in 0..4 {+ harness.step();+ }+ harness+}++/// Top and bottom edge of every registered element outside the header.+fn body_extent(h: &Harness<'static, FilmcraftApp>) -> (f32, f32) {+ let els = h.state().auto.query("");+ let body: Vec<_> = els.iter().filter(|e| !e.id.starts_with("header.")).collect();+ assert!(!body.is_empty(), "no panel elements registered");+ let top = body.iter().map(|e| e.rect[1]).fold(f32::INFINITY, f32::min);+ let bottom = body.iter().map(|e| e.rect[1] + e.rect[3]).fold(f32::NEG_INFINITY, f32::max);+ (top, bottom)+}++#[test]+fn header_and_status_bar_are_shown_by_default() {+ assert!(UiState::default().show_header);+ assert!(UiState::default().show_status_bar);+ let h = harness(true, true);+ assert!(!h.state().auto.query("header.").is_empty());+ let (top, bottom) = body_extent(&h);+ assert!(top >= 38.0, "panels start under the header: {top}");+ assert!(bottom <= H - 20.0, "panels end above the status bar: {bottom}");+ assert!(h.state().ui_error.is_none(), "{:?}", h.state().ui_error);+}++#[test]+fn hidden_header_and_status_bar_give_the_panels_the_window() {+ let h = harness(false, false);+ assert!(h.state().auto.query("header.").is_empty(), "header drawn while hidden");+ let (top, bottom) = body_extent(&h);+ assert!(top < 38.0, "panels start at the top of the window: {top}");+ assert!(bottom > H - 20.0, "panels reach the bottom of the window: {bottom}");+ assert!(h.state().ui_error.is_none(), "{:?}", h.state().ui_error);+}++#[test]+fn saved_ui_state_without_the_flags_shows_the_chrome() {+ let mut v = serde_json::to_value(UiState::default()).unwrap();+ let obj = v.as_object_mut().unwrap();+ assert!(obj.remove("show_header").is_some());+ assert!(obj.remove("show_status_bar").is_some());+ let ui: UiState = serde_json::from_value(v).unwrap();+ assert!(ui.show_header);+ assert!(ui.show_status_bar);+}