Dock area: a document panel's body is shown edge to edge, without the panel inset

This commit is contained in:
aiongg
2026-11-16 16:14:25 +00:00
parent 49258624fc
commit b32bb77e61
3 changed files with 21 additions and 9 deletions
+2 -1
View File
@@ -30,7 +30,8 @@ pub trait DockPanels<P> {
/// Shows `panel`'s body in `ui`: the group's body, inset from its edges by the panel padding. The group is the
/// body's panel and its tab the body's title, so the body shows no framework `Panel` or padding of its own; content
/// taller than the group scrolls in the body's own scrolling container.
/// taller than the group scrolls in the body's own scrolling container. A document panel's body
/// (`PanelSpec::window_kind` `Document`) gets the group's body edge to edge.
fn body(&mut self, panel: &P, ui: &mut Ui, cx: &mut BodyCx<'_>);
/// Takes the group holding `panels`, whose tab `active` is selected, in place of its tab strip and body: at
+17 -6
View File
@@ -25,6 +25,7 @@ use craft_behavior::dock::{
Action, Column, DockEdge, DockError, Group, Layout, Location, Node, PanelPlace, Permissions, SplitSize, Workspace, node_at,
};
use craft_behavior::{CancelReason, DockSide, EditEvent, EditEvents, Flow, GestureId, GesturePhase, Mixed, Proposal};
use craft_host::target::WindowKind;
use egui::{Context, Id, Pos2, Rect, Response, Ui, UiBuilder, Vec2, ViewportId};
use std::cell::{Cell, RefCell};
use std::collections::HashMap;
@@ -639,8 +640,18 @@ fn float_space<P: Clone + PartialEq>(bounds: Rect, sizes: &DockSizes, config: &D
/// Shows a docked panel's body as its group holds it: filling the group's body, inset from its edges by the panel
/// padding. The group is the body's panel and its tab the body's title, so a docked body pads and frames nothing itself.
fn inset(ui: &mut Ui, mut body: impl FnMut(&mut Ui, &mut BodyCx<'_>)) {
let _ = Stack::new().fill().pad(Pad::Regular).show(ui, |ui, cx| body(ui, cx));
/// A document's body (`WindowKind::Document`) is no panel content and is shown edge to edge.
fn inset(ui: &mut Ui, cx: &mut BodyCx<'_>, document: bool, mut body: impl FnMut(&mut Ui, &mut BodyCx<'_>)) {
if document {
body(ui, cx);
} else {
let _ = Stack::new().fill().pad(Pad::Regular).show(ui, |ui, cx| body(ui, cx));
}
}
/// Whether `spec` is a document's: its body is shown without the panel inset.
fn document(spec: &PanelSpec) -> bool {
matches!(spec.window_kind, WindowKind::Document)
}
impl<P: Clone + Eq + Hash + Debug + Send + Sync + 'static> Pass<'_, P> {
@@ -814,19 +825,19 @@ impl<P: Clone + Eq + Hash + Debug + Send + Sync + 'static> Pass<'_, P> {
let rect = match at {
GroupAt::Measure(width) => {
let measured =
make(active, look.minimized).measure_in(ui, Proposal::Width(width), |ui, _| inset(ui, |ui, body| panels.borrow_mut().body(shown, ui, body)));
make(active, look.minimized).measure_in(ui, Proposal::Width(width), |ui, cx| inset(ui, cx, document(&scene.spec(shown)), |ui, body| panels.borrow_mut().body(shown, ui, body)));
return Some(measured.y);
}
GroupAt::Show(rect) => rect,
};
let output = make(active, look.minimized).show_at(ui, rect, |ui, _| inset(ui, |ui, body| panels.borrow_mut().body(shown, ui, body))).output;
let output = make(active, look.minimized).show_at(ui, rect, |ui, cx| inset(ui, cx, document(&scene.spec(shown)), |ui, body| panels.borrow_mut().body(shown, ui, body))).output;
// The size `panel` floats at out of this group: the group's width, and the height the group measures at with
// `panel` shown in a floating window's room, so content that fills the body takes that room.
let fitted = |ui: &Ui, panel: &P| {
let at = members.iter().position(|member| member == panel).unwrap_or(active);
let room = Vec2::new(rect.width(), scene.space.content_room());
let measured = make(at, false).id(output.response.id).measure_in(ui, Proposal::Size(room), |ui, _| {
inset(ui, |ui, body| panels.borrow_mut().body(&members[at], ui, body));
let measured = make(at, false).id(output.response.id).measure_in(ui, Proposal::Size(room), |ui, cx| {
inset(ui, cx, document(&scene.spec(&members[at])), |ui, body| panels.borrow_mut().body(&members[at], ui, body));
});
Vec2::new(rect.width(), measured.y)
};
+2 -2
View File
@@ -54,7 +54,7 @@ The host implements `DockPanels<P>`:
| --- | --- |
| `spec` | The panel's `PanelSpec`, read every pass: label, icon, `SizeLimits`, `DockHeights`, float size, `allow_native`, `window_kind`, `canvas`. |
| `permissions` | The panel's `Permissions` (default `ALL`). |
| `body` | Shows the panel's body, filling the group's body inset by the panel padding (`Pad::Regular`). The group is the body's panel, so the body adds no `Panel` or padding of its own. |
| `body` | Shows the panel's body, filling the group's body inset by the panel padding (`Pad::Regular`). The group is the body's panel, so the body adds no `Panel` or padding of its own. A document panel's body (`WindowKind::Document`) is shown edge to edge. |
| `group_view` | Takes a whole group in place of its tab strip and body, in a `Ui` held to the group's rect; a canvas group draws its document here. Default `None`. |
| `group_header` | The host's controls in a group header, before the tab strip. |
| `panel_rows` | The host's rows of a panel's menu, before the dock's own. |
@@ -116,7 +116,7 @@ The theme's docking sizes (`DockSizes`) set the drop bands and zones. `DockWords
A floating window is a `Floating` in the layout: its `rect` in logical points in the app's viewport, and `native` and `monitor` while it is an OS window. `FloatingGroup` shows it. With `DockConfig::native_windows` (on by default), every floating window opens in its own OS window (`docking::native`) where the window host opens OS windows and reports where they are (`WindowHost::positions_reported`; not on Wayland); a window never shown native yet opens over its place in the main window. Elsewhere, and for a panel with `allow_native` off, the window stays inside the main window. The OS close of a native window is its Close action: the window closes when every panel in it may close. Dragging a native window by its title row moves the whole window and docks it where it is released over a group of the main window, as a floating window inside the main window does: the window host runs that move (`runtime::windows::keeps_app_drag`). On macOS the row's press hands the move to the OS, the app follows the system pointer and button (`Caps::OS_MOVES_TRACKED`), and a press that ends within the click distance is a click, which docks nothing; elsewhere the app moves the window, and Escape puts it back. The app sends an OS window its place only when the app changes it (an undo, a reloaded layout); the OS's own moves and resizes are recorded and never sent back. `window_kind` says whether an OS window is a document or a tool window. A tool window's title row is its only title bar, whatever frame the main window has (`craft_window::policy::tool_frame`).
A panel or group floated out of the dock (a drag, the Float command, a tab torn out of the window) opens at the width it had docked and at the height its group measures at in a floating window's room (`Proposal::Size`), at most `size.float.height`: the docked body fills the group, so it opens at that height. A column opens at its docked size, at most that height. The area measures once, where the float starts: for a drag in the pass it starts, which adds the size to the drag's payload (`runtime::drag::amend`). A panel's own `PanelSpec` float size wins, and a window that already floats keeps its size.
A panel or group floated out of the dock (a drag, the Float command, a tab torn out of the window) opens at the width it had docked and at the height its group measures at in a floating window's room (`Proposal::Size`), at most `size.float.height`: a panel's body fills the group, so it opens at that height; a document's body opens at that height when its content fills it, else at its own. A column opens at its docked size, at most that height. The area measures once, where the float starts: for a drag in the pass it starts, which adds the size to the drag's payload (`runtime::drag::amend`). A panel's own `PanelSpec` float size wins, and a window that already floats keeps its size.
## SplitArea on its own