FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
UI.9: floating panels stay out of the macOS title-bar strip
aionggf23dfeb1ee69
diff --git a/crates/ui-egui/src/dock_ui.rs b/crates/ui-egui/src/dock_ui.rsindex dea65515f..cde26ec48 100644--- a/crates/ui-egui/src/dock_ui.rs+++ b/crates/ui-egui/src/dock_ui.rs@@ -128,11 +128,21 @@ impl FilmcraftApp {self.show_panel(*panel);return Ok(());}- let space = craft_ui::docking::float_space(ctx, area_id()).unwrap_or_else(|| FloatSpace::new(ctx.content_rect()));+ let space = craft_ui::docking::float_space(ctx, area_id()).unwrap_or_else(|| FloatSpace::new(self.float_bounds(ctx)));let actions = command.to_actions(&Workspace::new(self.ui.dock.clone()), false, &space).map_err(|error| error.to_string())?;self.apply_dock_all(actions)}+ /// Where floating windows may go. With `integrated_titlebar` the header sits in the macOS+ /// title-bar strip, where a press on a floating window would move the whole app window.+ pub(crate) fn float_bounds(&self, ctx: &egui::Context) -> Rect {+ let mut bounds = ctx.content_rect();+ if self.integrated_titlebar {+ bounds.min.y += crate::header::HEIGHT;+ }+ bounds+ }+pub fn apply_dock(&mut self, action: Action<PanelKind>) -> Result<(), String> {self.apply_dock_all(vec![action])}@@ -210,7 +220,7 @@ impl FilmcraftApp {active: self.session.state.active_sequence.map(|id| id.0),};let style = dock_style(ui, &t);- let mut area = DockArea::new(area_id()).maximized(self.ui.keys.maximized.filter(|panel| self.ui.dock.is_docked(*panel)));+ let mut area = DockArea::new(area_id()).float_bounds(self.float_bounds(&ctx)).maximized(self.ui.keys.maximized.filter(|panel| self.ui.dock.is_docked(*panel)));if let Some(panel) = self.pending_panel_raise.take() {area = area.raise_panel(panel);}diff --git a/crates/ui-egui/src/header.rs b/crates/ui-egui/src/header.rsindex 5b8f23c85..9f08e2c8d 100644--- a/crates/ui-egui/src/header.rs+++ b/crates/ui-egui/src/header.rs@@ -10,6 +10,9 @@ use crate::icons::{self, Icon};use crate::state::Mode;use crate::theme::Tokens;+/// Height of the header bar. With `integrated_titlebar` it sits in the macOS title-bar strip.+pub const HEIGHT: f32 = 38.0;+pub fn show(app: &mut FilmcraftApp, ui: &mut egui::Ui, rect: Rect) {let t = app.tokens;let p = ui.painter().clone();diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rsindex c093d0965..7d95740d1 100644--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@ -1841,7 +1841,7 @@ impl FilmcraftApp {let t = self.tokens;let full = ui.max_rect();ui.painter().rect_filled(full, 0.0, t.app_bg);- let header_h = if self.ui.show_header { 38.0 } else { 0.0 };+ let header_h = if self.ui.show_header { header::HEIGHT } else { 0.0 };let header = egui::Rect::from_min_size(full.min, egui::vec2(full.width(), header_h));if self.ui.show_header {header::show(self, ui, header);diff --git a/crates/ui-egui/tests/shared_docking_ui.rs b/crates/ui-egui/tests/shared_docking_ui.rsindex 2995c64e9..5f6904e5d 100644--- a/crates/ui-egui/tests/shared_docking_ui.rs+++ b/crates/ui-egui/tests/shared_docking_ui.rs@@ -818,3 +818,21 @@ fn close_panel_group_keeps_the_timeline_and_closes_the_sequence() {assert!(state.ui.dock.is_visible(PanelKind::Timeline), "the Timeline closed");assert!(!state.ui.dock.contains(&PanelKind::Info), "Info stays open");}++/// With the header in the macOS title-bar strip, a floating window saved at the top of the+/// viewport is drawn below the strip, where a press on it cannot move the app window.+#[test]+fn a_floating_panel_stays_out_of_the_integrated_titlebar() {+ let mut app = FilmcraftApp::new(Session::default());+ app.ui.dock = layout();+ app.integrated_titlebar = true;+ let ctx = egui::Context::default();+ menus::invoke(&mut app, &ctx, "window.floatPanel", json!({"panel": "Info", "rect": [45, 65, 420, 320]})).unwrap();+ app.ui.dock.floating.iter_mut().find(|window| window.contains(&PanelKind::Info)).unwrap().rect[1] = 0.0;+ let mut h = Harness::builder().with_size(vec2(1200.0, 760.0)).build_eframe(move |_| app);+ for _ in 0..3 {+ step(&mut h);+ }+ let drawn = h.ctx.memory(|memory| memory.area_rect(window_layer(&h, PanelKind::Info).id)).expect("Info is drawn floating");+ assert!(drawn.min.y >= filmcraft_ui_egui::header::HEIGHT, "drawn at {drawn:?}");+}