FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
UI.9: grips move Tools and the Audio Meters
aiongg26d0df20effa
diff --git a/crates/ui-egui/src/dock_ui.rs b/crates/ui-egui/src/dock_ui.rsindex 8f002c8c8..948386982 100644--- a/crates/ui-egui/src/dock_ui.rs+++ b/crates/ui-egui/src/dock_ui.rs@@ -22,6 +22,8 @@ fn bodies_id() -> egui::Id {area_id().with("bodies")}+/// Height of the move grip above a panel without a tab strip.+const GRIP_H: f32 = 8.0;/// Width of the ≡ panel menu button at the end of each tab strip.const MENU_W: f32 = 26.0;@@ -342,7 +344,21 @@ struct FilmContent<'a> {impl DockContent<PanelKind> for FilmContent<'_> {fn body(&mut self, ui: &mut egui::Ui, panel: &PanelKind) {let t = self.tokens;- let rect = ui.max_rect();+ let frame = ui.max_rect();+ let mut rect = frame;+ // Tools and the audio meters have no tab strip: a slim grip on top moves them.+ if panel.compact() {+ let grip = Rect::from_min_size(rect.min, vec2(rect.width(), GRIP_H.min(rect.height())));+ let response = ui.interact(grip, egui::Id::new(("panel-grip", panel.id())), Sense::drag()).on_hover_cursor(egui::CursorIcon::Grab);+ self.app.auto.add_response(&format!("panel.drag.{}", panel.id()), &response, "Move panel");+ for dx in [-4.0, 0.0, 4.0] {+ ui.painter().circle_filled(grip.center() + vec2(dx, 0.0), 1.0, if response.hovered() { t.tab_text_active } else { t.text_faint });+ }+ if response.drag_started() {+ craft_ui::docking::begin_drag(ui.ctx(), area_id(), *panel, frame);+ }+ rect.min.y = grip.max.y;+ }self.bodies.push((*panel, rect, ui.layer_id()));self.app.auto.add(&format!("panel.{}", panel.id()), rect, panel.title());let mut child = ui.new_child(egui::UiBuilder::new().max_rect(rect).id_salt(("panel", panel.id())));@@ -350,7 +366,7 @@ impl DockContent<PanelKind> for FilmContent<'_> {panels::show(self.app, &mut child, *panel, rect);// Painted after the body so child backgrounds cannot hide the focus outline (#1075).if self.app.ui.focused == *panel {- ui.painter().rect_stroke(rect, 0.0, Stroke::new(1.0, t.focus), StrokeKind::Inside);+ ui.painter().rect_stroke(frame, 0.0, Stroke::new(1.0, t.focus), StrokeKind::Inside);}}diff --git a/crates/ui-egui/tests/shared_docking_ui.rs b/crates/ui-egui/tests/shared_docking_ui.rsindex a8e2e43cd..6c182e88a 100644--- a/crates/ui-egui/tests/shared_docking_ui.rs+++ b/crates/ui-egui/tests/shared_docking_ui.rs@@ -704,3 +704,16 @@ fn the_last_docked_group_cannot_float_away() {menus::invoke(&mut app, &ctx, "window.panel.float", json!({"panel": "Info"})).unwrap();assert!(app.ui.dock.docked(PanelKind::Project) && !app.ui.dock.docked(PanelKind::Info));}++/// Tools and the audio meters have no tab strip; the grip above each one moves it.+#[test]+fn tools_and_meters_move_by_their_grips() {+ let mut h = demo_harness();+ for panel in [PanelKind::Tools, PanelKind::AudioMeters] {+ assert!(h.state().auto.find(&format!("panel.drag.{}", panel.id())).is_some(), "{panel:?} has no grip");+ }+ let from = rect(&h, "panel.drag.Tools").center();+ let to = rect(&h, "panel.Program").center();+ drag(&mut h, from, to, Modifiers::NONE);+ assert!(same_group(&h.state().ui.dock, PanelKind::Tools, PanelKind::Program), "{:?}", h.state().ui.dock);+}