diff --git a/crates/ui-patterns/src/patterns/dock/panes.rs b/crates/ui-patterns/src/patterns/dock/panes.rs
index 0cb160961..28a51f2d2 100644
--- a/crates/ui-patterns/src/patterns/dock/panes.rs
+++ b/crates/ui-patterns/src/patterns/dock/panes.rs
@@ -25,7 +25,7 @@ use crate::style::{ComponentStyle, StyleCx, SurfaceKind};
use craft_behavior::dock::{ZoneSize, zones};
use craft_behavior::{DockSide, GesturePhase, Metrics, Sense};
use egui::{Id, Pos2, Rect, Response, Ui, Vec2};
-use std::cell::RefCell;
+use std::cell::{Cell, RefCell};
use std::fmt::Debug;
use std::hash::Hash;
@@ -105,7 +105,9 @@ pub enum PaneRequest
{
Close(P),
/// The user moved the pane to a new place.
Place(P, PanePlace),
- /// The user moved or resized the floating frame to this rect. It arrives every pass a gesture changes the rect.
+ /// The user moved or resized the floating frame to this rect. It arrives every pass a gesture changes the rect,
+ /// and after the `Place` of a Float with the rect the pane floats in (its kept float rect, else where the area
+ /// places it).
FloatRect(P, Rect),
/// The user minimized the floating pane (`true`) or restored it (`false`).
Minimize(P, bool),
@@ -329,8 +331,32 @@ fn outermost
(panes: &[Shown
], policy: SidePolicy, edge: PaneEdge, dragged:
}
}
-/// The requests of a pane command acting on `pane`.
-fn command_requests(panes: &[Shown
], policy: SidePolicy, pane: PanelKey, command: PaneCommands) -> Vec> {
+/// Where floating panes are placed: the shell's float bounds and the cascade step of a pane with no float rect.
+#[derive(Clone, Copy, Debug)]
+struct FloatPlace {
+ bounds: Rect,
+ inset: f32,
+}
+
+/// The rect `pane` floats in: its state's float rect, else its float size at the bounds' start, one cascade step on
+/// for each floating pane before it. The area draws a floating pane there, and a Float reports it.
+fn float_rect_of
(panes: &[Shown
], pane: PanelKey, float: FloatPlace) -> Rect {
+ let Some(at) = panes.iter().position(|s| s.key == pane) else { return Rect::from_min_size(float.bounds.min, Vec2::ZERO) };
+ let shown = &panes[at];
+ shown.state.float_rect.unwrap_or_else(|| {
+ let before = panes[..at].iter().filter(|s| s.state.place == PanePlace::Floating).count();
+ Rect::from_min_size(float.bounds.min + Vec2::splat(before as f32 * float.inset), shown.spec.float_size)
+ })
+}
+
+/// The requests of a pane command acting on `pane`. `float` places a pane the command floats.
+fn command_requests(
+ panes: &[Shown
], policy: SidePolicy, pane: Pane
PaneCommands::MoveToEnd if shown.spec.movable => dock(PaneEdge::End),
PaneCommands::MoveToTop if shown.spec.movable => dock(PaneEdge::Top),
PaneCommands::MoveToBottom if shown.spec.movable => dock(PaneEdge::Bottom),
+ // The rect it will float in goes with the place, so an app that keeps the float rect has it from the Float on,
+ // not only after a move or resize.
PaneCommands::Float if shown.spec.movable && shown.state.place != PanePlace::Floating => {
- vec![PaneRequest::Place(shown.pane.clone(), PanePlace::Floating)]
+ let mut requests = vec![PaneRequest::Place(shown.pane.clone(), PanePlace::Floating)];
+ if let Some(float) = float {
+ requests.push(PaneRequest::FloatRect(shown.pane.clone(), float_rect_of(panes, pane, float)));
+ }
+ requests
}
PaneCommands::Close if shown.spec.closable => vec![PaneRequest::Close(shown.pane.clone())],
_ => Vec::new(),
@@ -640,6 +672,8 @@ struct Pass<'a, P> {
content: RefCell<&'a mut dyn PaneContent